import * as echarts from "echarts"; export const pie = { title: [ { text: "场内拥堵率", x: "center", top: "52%", textStyle: { color: "#FFFFFF", fontSize: 21, fontFamily: 'MFLiHei', }, }, { text: `30%`, x: "center", top: "28%", textStyle: { fontSize: "40", color: "#FFFFFF", fontFamily: "DINAlternate-Bold, DINAlternate", foontWeight: "600", }, }, ], backgroundColor: "rgba(0,0,0,0)", polar: { radius: ["63%", "75%"], center: ["50%", "50%"], }, angleAxis: { max: 100, show: false, }, radiusAxis: { type: "category", show: true, axisLabel: { show: false, }, axisLine: { show: false, }, axisTick: { show: false, }, }, series: [ { name: "", type: "bar", roundCap: true, barWidth: 50, showBackground: true, backgroundStyle: { color: "rgba(66, 66, 66, 0)", }, data: [30], coordinateSystem: "polar", itemStyle: { normal: { color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [ { offset: 0, color: "#fcc451", }, { offset: 1, color: "#66ffff", }, ]), }, }, }, ], } export const pie2 = { title: [ { text: "场内异常率", x: "center", top: "52%", textStyle: { color: "#FFFFFF", fontSize: 21, fontFamily: 'MFLiHei', }, }, { text: `30%`, x: "center", top: "25%", textStyle: { fontSize: "40", color: "#FFFFFF", fontFamily: "DINAlternate-Bold, DINAlternate", foontWeight: "600", }, }, ], backgroundColor: "rgba(0,0,0,0)", polar: { radius: ["63%", "75%"], center: ["50%", "50%"], }, angleAxis: { max: 100, show: false, }, radiusAxis: { type: "category", show: true, axisLabel: { show: false, }, axisLine: { show: false, }, axisTick: { show: false, }, }, series: [ { name: "", type: "bar", roundCap: true, barWidth: 50, showBackground: true, backgroundStyle: { color: "rgba(66, 66, 66, 0)", }, data: [30], coordinateSystem: "polar", itemStyle: { normal: { color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [ { offset: 0, color: "#fcc451", }, { offset: 1, color: "#3e94fa", }, ]), }, }, }, ], } let colors = ['#3A92FE', '#01FFFF', '#47FD7F'] let xData = ['0-15km', '15-30km', '30km以上'] let yData = [5, 32, 18] // 传入数据生成 option let optionsData = []; for (let i = 0; i < xData.length; i++) { optionsData.push( { name: xData[i], value: yData[i], itemStyle: { color: colors[i], } } ); } function getSymbolData(datas) { let arr = [] for (var i = 0; i < datas.length; i++) { arr.push({ value: datas[i], symbolPosition: 'end', }) } return arr } export const barData = { backgroundColor: 'rgba(0,0,0,0)', grid: { top: 14, left: 0, right: 0, bottom: 7, containLabel: true, }, legend: { show: false }, xAxis: { data: ['当前一个小时\n平均到场时间', '预计下个小时\n平均到场时间',], axisLine: { lineStyle: { color: 'rgba(255, 255, 255, 0.2)', width: 1 }, }, axisTick: { show: true, lineStyle: { color: 'rgba(255, 255, 255, 0.5)' } }, axisLabel: { show: true, fontSize: 10, textStyle: { color: "rgba(255, 255, 255, 0.5)" //X轴文字颜色 } }, }, yAxis: [ { type: "value", splitLine: { show: true, lineStyle: { color: 'rgba(255, 255, 255, 0.2)', type: 'dashed', width: 1 }, }, axisTick: { show: false }, axisLine: { show: false }, axisLabel: { show: true, fontSize: 16, textStyle: { color: "rgba(255, 255, 255, 0.5)" //X轴文字颜色 } }, }, ], series: [ { // 背景系列 type: 'bar', barGap: '-100%', // 使背景系列与主系列重叠 data: [1, 1, 1, 1, 1, 1, 1], // 所有值为1,表示100% itemStyle: { color: 'rgba(255, 255, 255, 0.1)', borderWidth: 0, borderColor: '#ccc' }, barWidth: '100%', // 背景宽度 animation: false }, { name: "", type: "bar", barWidth: 15, itemStyle: { normal: { color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{ offset: 0, color: "#0372FF", }, { offset: 1, color: "#75ECFF", }, ]), } }, showBackground: true, data: [31, 28,], label: { show: false, }, z: 0, }, { type: 'pictorialBar', symbol: 'react', symbolSize: [15, 3], symbolOffset: [0, -2], z: 12, itemStyle: { color: '#FFFFFF', shadowColor: 'rgba(252, 194, 50, 1)', shadowBlur: 20, }, data: getSymbolData([31, 28]), }, ] } export function initBing(optionsData) { let total = 0 optionsData.map(r=>total+=r.value) const series = getPie3D(optionsData, 0.8); series.push({ name: 'pie2d', type: 'pie', label: { opacity: 1, fontSize: 12, lineHeight: 20, textStyle: { fontSize: 12, }, }, title:{ text:'x213' }, labelLine: { length: 60, length2: 60, }, startAngle: -50, //起始角度,支持范围[0, 360]。 clockwise: false, //饼图的扇区是否是顺时针排布。上述这两项配置主要是为了对齐3d的样式 radius: ['0', '0'], center: ['20%', '20%'], data: optionsData, itemStyle: { opacity: 0, }, }); // 准备待返回的配置项,把准备好的 legendData、series 传入。 return { legend: { tooltip: { show: true, }, data: xData, bottom: '5%', itemGap: 10, itemWidth: 7, itemHeight: 7, textStyle: { color: '#fff', fontSize: 12, }, }, animation: true, tooltip: { formatter: params => { if (params.seriesName !== 'mouseoutSeries' && params.seriesName !== 'pie2d') { return `${params.seriesName}
${option.series[params.seriesIndex].pieData.value}`; } }, textStyle: { fontSize: 12 }, }, title: { text: `${total}辆`, x: 'center', top: '20', textStyle: { color: '#fff', fontSize: 24, }, }, backgroundColor: 'rgba(0,0,0,0)', color:['#3A93FF','#01FFFF','#47FD7F'], labelLine: { show: false, lineStyle: { color: 'transparent', }, }, label: { show: false, color: 'transparent', position: 'outside', formatter: '{b} \n{c} {d}%', }, xAxis3D: { min: -1, max: 1, }, yAxis3D: { min: -1, max: 1, }, zAxis3D: { min: -1, max: 1, }, grid3D: { show: false, boxHeight: 0.05, top: '5%', bottom: '15%', viewControl: { autoRotate: true, // 自动旋转 zoomSensitivity: 0 }, }, series: series, }; } function getParametricEquation(startRatio, endRatio, isSelected, isHovered, k, height) { // 计算 let midRatio = (startRatio + endRatio) / 2; let startRadian = startRatio * Math.PI * 2; let endRadian = endRatio * Math.PI * 2; let midRadian = midRatio * Math.PI * 2; // 如果只有一个扇形,则不实现选中效果。 if (startRatio === 0 && endRatio === 1) { isSelected = false; } // 通过扇形内径/外径的值,换算出辅助参数 k(默认值 1/3) k = typeof k !== 'undefined' ? k : 1 / 3; // 计算选中效果分别在 x 轴、y 轴方向上的位移(未选中,则位移均为 0) let offsetX = isSelected ? Math.cos(midRadian) * 0.1 : 0; let offsetY = isSelected ? Math.sin(midRadian) * 0.1 : 0; // 计算高亮效果的放大比例(未高亮,则比例为 1) let hoverRate = isHovered ? 1.05 : 1; // 返回曲面参数方程 return { u: { min: -Math.PI, max: Math.PI * 3, step: Math.PI / 32 }, v: { min: 0, max: Math.PI * 2, step: Math.PI / 20 }, x: function (u, v) { if (u < startRadian) { return offsetX + Math.cos(startRadian) * (1 + Math.cos(v) * k) * hoverRate; } if (u > endRadian) { return offsetX + Math.cos(endRadian) * (1 + Math.cos(v) * k) * hoverRate; } return offsetX + Math.cos(u) * (1 + Math.cos(v) * k) * hoverRate; }, y: function (u, v) { if (u < startRadian) { return offsetY + Math.sin(startRadian) * (1 + Math.cos(v) * k) * hoverRate; } if (u > endRadian) { return offsetY + Math.sin(endRadian) * (1 + Math.cos(v) * k) * hoverRate; } return offsetY + Math.sin(u) * (1 + Math.cos(v) * k) * hoverRate; }, z: function (u, v) { if (u < - Math.PI * 0.5) { return Math.sin(u); } if (u > Math.PI * 2.5) { return Math.sin(u); } return Math.sin(v) > 0 ? 2 * height : -1; } }; } // 生成模拟 3D 饼图的配置项 function getPie3D(pieData, internalDiameterRatio) { let series = []; let sumValue = 0; let startValue = 0; let endValue = 0; let legendData = []; let k = typeof internalDiameterRatio !== 'undefined' ? (1 - internalDiameterRatio) / (1 + internalDiameterRatio) : 1 / 3; // 为每一个饼图数据,生成一个 series-surface 配置 for (let i = 0; i < pieData.length; i++) { sumValue += pieData[i].value; let seriesItem = { name: typeof pieData[i].name === 'undefined' ? `series${i}` : pieData[i].name, type: 'surface', parametric: true, wireframe: { show: false }, pieData: pieData[i], pieStatus: { selected: false, hovered: false, k: k } }; if (typeof pieData[i].itemStyle != 'undefined') { let itemStyle = {}; typeof pieData[i].itemStyle.color != 'undefined' ? itemStyle.color = pieData[i].itemStyle.color : null; typeof pieData[i].itemStyle.opacity != 'undefined' ? itemStyle.opacity = pieData[i].itemStyle.opacity : null; seriesItem.itemStyle = itemStyle; } series.push(seriesItem); } // 使用上一次遍历时,计算出的数据和 sumValue,调用 getParametricEquation 函数, // 向每个 series-surface 传入不同的参数方程 series-surface.parametricEquation,也就是实现每一个扇形。 for (let i = 0; i < series.length; i++) { endValue = startValue + series[i].pieData.value; console.log(series[i]); series[i].pieData.startRatio = startValue / sumValue; series[i].pieData.endRatio = endValue / sumValue; series[i].parametricEquation = getParametricEquation(series[i].pieData.startRatio, series[i].pieData.endRatio, false, false, k, series[i].pieData.value); startValue = endValue; legendData.push(series[i].name); } // // 补充一个透明的圆环,用于支撑高亮功能的近似实现。 series.push({ name: 'mouseoutSeries', type: 'surface', parametric: true, wireframe: { show: false, }, itemStyle: { opacity: 0.1, color: '#f0f', }, parametricEquation: { u: { min: 0, max: Math.PI * 2, step: Math.PI / 20, }, v: { min: 0, max: Math.PI, step: Math.PI / 20, }, x: function (u, v) { return ((Math.sin(v) * Math.sin(u) + Math.sin(u)) / Math.PI) * 2.1; }, y: function (u, v) { return ((Math.sin(v) * Math.cos(u) + Math.cos(u)) / Math.PI) * 2.1; }, z: function (u, v) { return Math.cos(v) > 0 ? 0 : -5; }, }, }); series.push({ name: 'mouseoutSeries', type: 'surface', parametric: true, wireframe: { show: false, }, itemStyle: { opacity: 0.1, color: '#0ff', }, parametricEquation: { u: { min: 0, max: Math.PI * 2, step: Math.PI / 20, }, v: { min: 0, max: Math.PI, step: Math.PI / 20, }, x: function (u, v) { return ((Math.sin(v) * Math.sin(u) + Math.sin(u)) / Math.PI) * 2.1; }, y: function (u, v) { return ((Math.sin(v) * Math.cos(u) + Math.cos(u)) / Math.PI) * 2.1; }, z: function (u, v) { return Math.cos(v) > 0 ? -15 : -20; }, }, }); return series; } // 进行线的截断 export function initLine(yAxisData, data1, data2, data3) { // let yAxisData = ['07/01', '07/02', '07/03', '07/04', '07/05', '07/06', '07/07',] // let data = [100, 90, 200, 250, 240, 500, 120, 390,] return { tooltip: { trigger: 'axis', axisPointer: { type: 'shadow', crossStyle: { color: '#999' } } }, legend: { orient: "vertical", top: "10%", right: "0%", itemWidth: 6, itemHeight: 6, itemGap: 5, itemStyle: { borderRadius: 20, // 设置圆角大 }, icon: "rect", textStyle: { fontSize: 10, color: "#ffffff", padding: [0, 0, 0, 0], }, show: false }, backgroundColor: 'rgba(0,0,0,0)', grid: { top: "25%", right: "5%", bottom: "15%" }, xAxis: { type: 'category', boundaryGap: true, axisTick: { show: false }, axisLine: { lineStyle: { color: '#94A7BD'//轴线和单位颜色 } }, data: yAxisData }, yAxis: { type: 'value', name: '单位:吨', axisLine: { lineStyle: { color: '#94A7BD'//轴线和单位颜色 } }, splitLine: { show: false, lineStyle: { show: false, color: '#182D46', type: [2, 3], dashOffset: 2 } } }, series: [{ name: '钢铁', type: 'line', // symbolSize: 10, symbol: 'none', areaStyle: { color: { type: 'linear', x: 0, y: 0, x2: 0, y2: 1, colorStops: [{ offset: 0, color: 'rgba(58, 147, 255, 1)' // 0% 处的颜色 }, { offset: 1, color: 'rgba(58, 147, 255, 0)' // 100% 处的颜色 }], global: false // 缺省为 false }, }, lineStyle: { color: 'rgba(58, 147, 255, 1)', width: 2, type: 'solid' }, // 最高点标点 data: data1.map(item => { const maxValue = Math.max(...data1.filter(item => item != '-')) const minVlaue = Math.min(...data1.filter(item => item != '-')) if (item === maxValue || item === minVlaue) { return { value: item, symbol: 'circle', symbolSize: 6, itemStyle: { color: 'rgba(58, 147, 255, 1)', shadowColor: 'rgba(58, 147, 255,0.6)', shadowBlur: 10 } } } return item }) }, { name: '沙石', type: 'line', // symbolSize: 10, symbol: 'none', areaStyle: { color: { type: 'linear', x: 0, y: 0, x2: 0, y2: 1, colorStops: [{ offset: 0, color: 'rgba(67, 230, 150, 1)' // 0% 处的颜色 }, { offset: 1, color: 'rgba(67, 230, 150, 0)' // 100% 处的颜色 }], global: false // 缺省为 false }, }, lineStyle: { color: 'rgba(67, 230, 150, 1)', width: 2, type: 'solid' }, // 最高点标点 data: data2.map(item => { const maxValue = Math.max(...data2.filter(item => item != '-')) const minVlaue = Math.min(...data2.filter(item => item != '-')) if (item === maxValue || item === minVlaue) { return { value: item, symbol: 'circle', symbolSize: 6, itemStyle: { color: 'rgba(67, 230, 150, 1)', shadowColor: 'rgba(67, 230, 150, 0.6)', shadowBlur: 10 } } } return item != '-' ? item : '-' }) }, // { // name: '煤炭', // type: 'line', // // symbolSize: 10, // symbol: 'none', // areaStyle: { // color: { // type: 'linear', x: 0, y: 0, x2: 0, y2: 1, // colorStops: [{ // offset: 0, color: 'rgba(68,233,150.6)' // 0% 处的颜色 // }, { // offset: 1, color: 'rgba(68,233,150,0)' // 100% 处的颜色 // }], // global: false // 缺省为 false // }, // }, // lineStyle: { // color: 'rgba(68,233,150,1)', // width: 2, // type: 'solid' // }, // // 最高点标点 // data: data3.map(item => { // const maxValue = Math.max(...data3.filter(item => item != '-')) // const minVlaue = Math.min(...data3.filter(item => item != '-')) // if (item === maxValue || item === minVlaue) { // return { // value: item, // symbol: 'circle', // symbolSize: 6, // itemStyle: { color: 'rgba(68,233,150,1)', shadowColor: 'rgba(255,255,255,0.6)', shadowBlur: 10 } // } // } // return item != '-' ? item : '-' // }) // }, { name: '石灰石', type: 'line', // symbolSize: 10, symbol: 'none', areaStyle: { color: { type: 'linear', x: 0, y: 0, x2: 0, y2: 1, colorStops: [{ offset: 0, color: 'rgba(247, 85, 21, 1)' // 0% 处的颜色 }, { offset: 1, color: 'rgba(247, 85, 21, 0)' // 100% 处的颜色 }], global: false // 缺省为 false }, }, lineStyle: { color: 'rgba(247, 85, 21, 1)', width: 2, type: 'solid' }, // 最高点标点 data: data3.map(item => { const maxValue = Math.max(...data3.filter(item => item != '-')) const minVlaue = Math.min(...data3.filter(item => item != '-')) if (item === maxValue || item === minVlaue) { return { value: item, symbol: 'circle', symbolSize: 4, itemStyle: { color: '#rgba(247, 85, 21, 1)', shadowColor: 'rgba(247, 85, 21, 0.6)', shadowBlur: 10 } } } return item != '-' ? item : '-' }) }] }; }