// 统计图表统一清爽简洁风格(echarts 4 兼容) // 供 statistics/*.vue 复用,保证视觉一致 const toRgba = (hex, alpha) => { const n = parseInt(hex.slice(1), 16); const r = (n >> 16) & 255; const g = (n >> 8) & 255; const b = n & 255; return `rgba(${r}, ${g}, ${b}, ${alpha})`; }; export const COLORS = { blue: '#5B8FF9', green: '#5AD8A6', amber: '#F6BD16', coral: '#E8684A', sky: '#6DC8EC', purple: '#9270CA', orange: '#FF9D4D', teal: '#269A99' }; export const PALETTE = Object.values(COLORS); const tipBase = { backgroundColor: '#ffffff', borderColor: '#e8eaf0', borderWidth: 1, padding: [10, 14], textStyle: { color: '#333', fontSize: 13 }, extraCssText: 'box-shadow:0 6px 18px rgba(31,45,61,.1);border-radius:10px;' }; // 坐标轴类 tooltip(柱状/折线) export function axisTooltip() { return { trigger: 'axis', ...tipBase, axisPointer: { lineStyle: { color: '#c9d2e0' } } }; } // 图形类 tooltip(饼图) export function itemTooltip() { return { trigger: 'item', ...tipBase, formatter: '{b}:{c} ({d}%)' }; } export function grid() { return { left: 8, right: 16, top: 44, bottom: 8, containLabel: true }; } // 类目轴 export function xAxis(data) { return { type: 'category', data, axisLine: { show: false }, axisTick: { show: false }, axisLabel: { color: '#8a919f', fontSize: 12 } }; } // 数值轴 export function yAxis(name) { return { type: 'value', name, nameTextStyle: { color: '#b0b6c3', fontSize: 12 }, axisLabel: { color: '#8a919f', fontSize: 12 }, splitLine: { lineStyle: { type: 'dashed', color: '#f0f1f5' } } }; } export function legend(data) { return { data, icon: 'roundRect', itemWidth: 10, itemHeight: 10, itemGap: 18, textStyle: { color: '#8a919f', fontSize: 12 } }; } // 柱状系列 export function barSeries(name, data, color, opts = {}) { return { name, type: 'bar', data, barMaxWidth: opts.maxWidth || 20, itemStyle: { color, borderRadius: opts.radius || [4, 4, 0, 0] }, stack: opts.stack, yAxisIndex: opts.yAxisIndex }; } // 折线系列 export function lineSeries(name, data, color, opts = {}) { const s = { name, type: 'line', data, smooth: true, symbol: 'circle', symbolSize: opts.symbolSize || 6, lineStyle: { width: 3, color }, itemStyle: { color }, yAxisIndex: opts.yAxisIndex }; if (opts.area) { s.areaStyle = { color: { type: 'linear', x: 0, y: 0, x2: 0, y2: 1, colorStops: [ { offset: 0, color: toRgba(color, 0.24) }, { offset: 1, color: toRgba(color, 0) } ] } }; } return s; } // 环形图系列 export function donutSeries(name, data) { return { name, type: 'pie', radius: ['52%', '72%'], center: ['50%', '50%'], avoidLabelOverlap: false, itemStyle: { borderColor: '#fff', borderWidth: 2 }, label: { show: false }, labelLine: { show: false }, data, color: PALETTE }; }