echarts中解决警告 There is a chart instance already initialized on the dom.

解决警告 There is a chart instance already initialized on the dom.

主要代码

	// 基于准备好的dom,初始化echarts实例
	this.myChart = echarts.init(document.getElementById(this.elId));
	watch: {
			xAxis: {
				handler(newValue, oldValue) {
					this.myChart.setOption({
						xAxis: {
							data: this.xAxis,
							type: "category",
							axisTick: { show: false },
							axisLabel: {
								fontSize: 12
							}
						}
					});
				},
				deep: true //深度监听
			},
		}

完整代码

	drawLine() {
			// 基于准备好的dom,初始化echarts实例
			this.myChart = echarts.init(document.getElementById(this.elId));
			// 绘制图表
			let series = this.series.map((value, key) => {
				return {
					name: this.legend[key],
					type: "line",
					barGap: 0,
					data: value,
					smooth: true,
					showSymbol: this.showsymbol,
					areaStyle: {
						color: this.color[key]
					}
				};
			});
			this.myChart.setOption({
				color: COLOR_INFO,
				tooltip: {
					trigger: "axis",
					axisPointer: {
						type: "shadow"
					},
					formatter: params => {
						let params0 = params[0],
							params1 = params[1];
						return `
                         <div style="border:0;color:#fff;text-align: left;width:100px">
                          <span style="padding-bottom='5px'">${params[0].axisValue}: <span style="color: ${COLOR_INFO[0]};">${params0.data}</span>/<span style="color: ${COLOR_INFO[1]};">${params1.data}</span></span>
                     </div>`;
					},
					backgroundColor: "rgba(12,69,147,0.80)",
					borderColor: "rgba(12,69,147,0.80)",
					borderWidth: 0
				},
				legend: {
					show: false,
					data: this.legend
				},
				xAxis: {
					data: this.xAxis,
					type: "category",
					axisTick: { show: false },
					axisLabel: {
						fontSize: 12
					}
				},
				yAxis: {
					type: "value",
					show: true,
					axisLine: {
						show: true // 是否显示坐标轴轴线。
					},
					axisTick: {
						show: true // 是否显示坐标刻度
					},
					splitNumber: 3,
					splitLine: {
						show: true,
						lineStyle: {
							type: "dashed",
							color: "#113d5e"
						}
					},
					axisLabel: {
						fontSize: 12
					}
				},
				series: series,
				grid: {
					left: this.left,
					x: 20,
					y: 10,
					x2: 18,
					y2: 20
				}
			});
		}
	watch: {
		xAxis: {
			handler(newValue, oldValue) {
				this.myChart.setOption({
					xAxis: {
						data: this.xAxis,
						type: "category",
						axisTick: { show: false },
						axisLabel: {
							fontSize: 12
						}
					}
				});
			},
			deep: true //深度监听
		},
		series: {
			handler(newValue, oldValue) {
				let series = this.series.map((value, key) => {
					return {
						name: this.legend[key],
						type: "line",
						barGap: 0,
						data: value,
						smooth: true,
						showSymbol: this.showsymbol,
						areaStyle: {
							color: this.color[key]
						}
					};
				});
				this.myChart.setOption({
					series: series
				});
			},
			deep: true //深度监听
		}
	}

链接: https://blog.csdn.net/qq_26477073/article/details/84568668.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值