vue引进echarts
时间: 2023-09-05 08:09:51 浏览: 35
要在Vue项目中使用Echarts,需要先安装Echarts。可以通过以下命令行进行安装:
```
npm install echarts --save
```
安装完成后,在Vue组件中引入Echarts:
```javascript
import echarts from 'echarts'
```
然后在 mounted 钩子函数里初始化图表:
```javascript
mounted() {
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('myChart'));
// 绘制图表
myChart.setOption({
title: { text: 'ECharts 入门示例' },
tooltip: {},
xAxis: {
data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
});
}
```
最后,在模板中添加一个 `div` 作为图表容器:
```html
<template>
<div id="myChart" style="width: 600px;height:400px;"></div>
</template>
```
这样就可以在Vue项目中使用Echarts啦!