|
一、简单介绍
Echart是百度研发团队开发的一款报表视图JS插件,功能十分强大,使用内容做简单记录;(EChart下载地址 http://echarts.baidu.com/download.html) Echart官方网站:https://www.echartsjs.com/index.html 二、下载 npm i echarts三、引用Echart import * as echarts from 'echarts'; Vue.prototype.$echarts = echarts四、在组件中使用 <template>
<div>
<div id="myChart" :style="{width: '100%', height: '500px',top: '50px'}"></div>
</div>
</template>
<script>
export default {
name: 'hello',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
},
mounted(){
//我们要在mounted生命周期函数中实例化echarts对象。因为我们要确保dom元素已经挂载到页面中
this.drawLine();
methods: {
drawLine(){
// 基于准备好的dom,初始化echarts实例
let myChart = this.$echarts.init(document.getElementById('myChart'))
// 绘制图表
myChart.setOption({
title: { text: '在Vue中使用echarts' },
tooltip: {},
xAxis: {
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
});
}
}
}
</script>效果如下: 图片:7821344-c3ab17257c07cb9b.png ![]() 这样一个简单的Echart图就完成了,是不是非常的简单呢 |
|
|
沙发#
发布于:2022-06-09 15:56
|
|
|
