| | |
| | | }, |
| | | |
| | | generateChart(option) { |
| | | // 配置折线图和柱状图的样式 |
| | | // 样式只加在副本上,不能回写 this.series:series 是父页面的响应式数据, |
| | | // 回写会触发本组件 series 的 deep watcher 再次 renderChart,每次生成新对象永不收敛,页面死循环卡死 |
| | | if (option.series && option.series.length > 0) { |
| | | option.series.forEach((s, index) => { |
| | | option.series = option.series.map((s, index) => { |
| | | if (s.type === 'line') { |
| | | s.itemStyle = { |
| | | color: this.lineColors[index] || this.lineColors[0] |
| | | } |
| | | s.lineStyle = { |
| | | color: this.lineColors[index] || this.lineColors[0] |
| | | } |
| | | const color = this.lineColors[index] || this.lineColors[0] |
| | | return { ...s, itemStyle: { color }, lineStyle: { color } } |
| | | } else if (s.type === 'bar') { |
| | | s.itemStyle = { |
| | | color: this.barColors[index] || this.barColors[0] |
| | | } |
| | | const color = this.barColors[index] || this.barColors[0] |
| | | return { ...s, itemStyle: { color } } |
| | | } |
| | | return s |
| | | }) |
| | | } |
| | | this.chartInstance.clear() |