| | |
| | | <template> |
| | | <div class="chart-item"> |
| | | <div id="ChartDom" style="width: 100%; height: 100%"></div> |
| | | <div :id="domId" style="width: 100%; height: 100%"></div> |
| | | </div> |
| | | </template> |
| | | |
| | |
| | | chartType: { |
| | | type: String, |
| | | default: "line", // bar |
| | | }, |
| | | domId: { |
| | | type: String, |
| | | default: "ChartDom", |
| | | }, |
| | | }) |
| | | |
| | |
| | | if (!props.chartData.xAxis) { |
| | | return |
| | | } |
| | | const chartDom = document.getElementById("ChartDom") |
| | | const chartDom = document.getElementById(props.domId) |
| | | if (echarts.getInstanceByDom(chartDom)) { |
| | | echarts.dispose(chartDom) |
| | | } |
| | | const myChart = echarts.init(chartDom) |
| | | // 处理多系列数据 |
| | | const series = props.chartData.series.map((item) => ({ |
| | | ...item, |
| | | name: item.name, |
| | | type: props.chartType, // 根据传入类型渲染 |
| | | data: item.data, |
| | | barWidth: "16", |
| | | barWidth: props.chartData.barWidth || "16", |
| | | itemStyle: { |
| | | borderRadius: [15, 15, 0, 0], |
| | | }, |
| | | smooth: true, // 启用平滑曲线 |
| | | })) |
| | | console.log("initChart", series) |
| | | let option = { |
| | | title: { |
| | | // text: props.chartData.title, |
| | | text: props.chartData.title || "", |
| | | left: "40", |
| | | textStyle: { |
| | | color: "#2979ff", |
| | | }, |
| | | }, |
| | | color: ["#2979ff", "#19be6b", "#ff9900", "#fa3534"], |
| | | color: ["#4dadf8", "#19be6b", "#ff9900", "#3d8a32", "#e8463a", "#ff4e3f"], |
| | | // color: ["#2979ff", "#19be6b", "#ff9900", "#fa3534"], |
| | | tooltip: { |
| | | trigger: "axis", |
| | | axisPointer: { |