Echarts
Echarts官网https://echarts.apache.org/zh/index.html
1.安装依赖:echarts
2.导入echarts
import echarts from 'echarts'
我这样导入出错了,后来直接require
3.为ECharts准备一个具备大小(宽高)的Dom
<div id="main" style="width: 750px; height: 400px"></div>
4. 基于准备好的dom,初始化echarts实例
这里我也直接let
let myChart = echarts.init(document.getElementById('main')); // var myChart = echarts.init(document.getElementById('main'))
5.指定图表的配置项和数据
var option = {
title: {
text: 'ECharts 入门示例'
},
tooltip: {},
legend: {
data:['销量']
},
xAxis: {
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
init错误
vue写echarts 报错 Cannot read property ‘init‘ of undefined“
参考:https://blog.csdn.net/qq_35567179/article/details/110734722
直接 let echarts = require('echarts');导入echarts,终于解决了,呜呜呜~