这里写自定义目录标题
vue+ts+echarts绘制柱形图失败
问题描述是显示不出来任何信息,包括表头什么的
很多人说是版本问题,我换过了,并不是。
然后通过debug发现,我的option根本没有获取到,或许该换种方式写
(this as any).chartLine = (this as any). e c h a r t s . i n i t ( t h i s . echarts.init(this. echarts.init(this.refs.chartLineBox as HTMLDivElement);
// 使用刚指定的配置项和数据显示图表。
(this as any).chartLine.setOption({
title: {
text: 'Biu~简单柱状图示例'
},
tooltip: {},
legend: {
data:['销量']
},
xAxis: {
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}],
color: ['#66FF99']
});
下面是错误代码
// 指定图表的配置项和数据
option: {
title: {
text: 'Biu~简单柱状图示例'
},
tooltip: {},
legend: {
data:['销量']
},
xAxis: {
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}],
color: ['#66FF99']
} | undefined
mounted(){
console.log(this.$refs.chartLineBox);
debugger
(this as any).chartLine = (this as any).$echarts.init(this.$refs.chartLineBox as HTMLDivElement);
// 使用刚指定的配置项和数据显示图表。
(this as any).chartLine.setOption((this as any).option);
}
在获取的时候option显示是undefined,我确实是个傻子,:并不能赋值,那是指明属性类型的,要用=赋值才能成功