/** * 获取合适的字体大小 */ function fGetChartFontSize() { const dpr = window.devicePixelRatio; let fontSize = 12; if (dpr == 2) { fontSize = 17; } else if (dpr == 3) { fontSize = 24; } else if (dpr > 3) { fontSize = 24; } return fontSize; } // 折线图 function factorLineOption(_xAxis, _series, legends) { var fontSize = fGetChartFontSize(); return { animationEasing: 'elasticOut', animationDelayUpdate: function (idx) { return idx * 5; }, // toolbox: { // bottom: 0, // feature: { // dataZoom: {}, // magicType: { // type: ['line', 'bar'] // }, // restore: {} // } // }, tooltip: { textStyle: { fontSize: fontSize } }, legend: { type: 'scroll', data: legends, left: 0, textStyle: { fontSize: fontSize, color: 'white' } }, xAxis: { name: '时间', data: _xAxis, axisLabel: { textStyle: { fontSize: fontSize }, color: '#ffffff', textBorderColor: '#fff' }, axisTick: { lineStyle: { color: 'white' }, intervel: 0, inside: false }, nameTextStyle: { color: '#ffffff' }, axisLine: { lineStyle: { color: '#ffffff' } } }, yAxis: { name: '浓度(μg/m³)', axisLabel: { textStyle: { fontSize: fontSize } }, axisLine: { show: true, lineStyle: { color: 'white' } }, axisTick: { show: true, lineStyle: { color: 'white' } }, minInterval: 1 }, series: _series, dataZoom: [ { type: 'inside', start: 0, end: 100 } ] }; } // 仪表盘 function gaugeOption(name, value) { var fontSize = fGetChartFontSize(); var option = { title: { text: name, textStyle: { color: 'white', fontSize: fontSize }, left: 'center' }, textStyle: { color: '#ffffff', fontSize: 10 }, tooltip: { formatter: '{a}
{b} : {c}%' }, toolbox: { // feature: { // restore: {}, // saveAsImage: {} // } }, series: [ { name: name, type: 'gauge', detail: { color: 'white', formatter: '{value}', textStyle: { fontSize: fontSize } }, splitLine: { lineStyle: { color: 'white' } }, axisTick: { lineStyle: { color: 'white' } }, axisLabel: { color: 'white', fontSize: 10 }, axisLine: { lineStyle: { color: [ [0.2, '#2afd2a'], [0.8, '#f1e74d'], [1, '#c23531'] ] } }, itemStyle: { color: 'white' }, data: [ { value: value, name: '' } ], min: 0, max: 200 } ] }; return option; } export { factorLineOption, gaugeOption };