首先安装echart

npm i echarts -S

加下来以使用这个图表为例

在vue组件中像这样使用:

<template>
<div :class="className" :id="id" :style="{height:height,width:width}" ref="myEchart">
</div>
</template>
<script>
import echarts from 'echarts'
export default {
props: {
className: {
type: String,
default: 'yourClassName'
},
id: {
type: String,
default: 'yourID'
},
width: {
type: String,
default: '500px'
},
height: {
type: String,
default: '500px'
}
},
data() {
return {
chart: null
}
},
mounted() {
this.initChart();
},
beforeDestroy() {
if (!this.chart) {
return
}
this.chart.dispose();
this.chart = null;
},
methods: {
initChart() {
this.chart = echarts.init(this.$refs.myEchart);
// 把配置和数据放这里
this.chart.setOption({
color: ['#3398DB'],
tooltip: {
trigger: 'axis',
axisPointer: { // 坐标轴指示器,坐标轴触发有效
type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: [{
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
axisTick: {
alignWithLabel: true
}
}],
yAxis: [{
type: 'value'
}],
series: [{
name: '直接访问',
type: 'bar',
barWidth: '60%',
data: [10, 52, 200, 334, 390, 330, 220]
}]
})
}
}
}
</script>

如果是异步获取的数据,比如用axios,那只需要把配置项放到then方法后面:

    initChart() {
this.chart = echarts.init(this.$refs.myEchart);
// 把配置和数据放这里
this.axios.get('/url').then((data) => {
this.chart.setOption({ })
})
}

最新文章

  1. XML基础
  2. String类型的属性和方法
  3. sql条件为空查询全部,不为空按条件查询以及多条件筛选查询。
  4. C++ - 复制(copy) 和 虚复制(virtual copy) 的 区别
  5. Unity2D 之 Sprite点击事件
  6. 通过struts.xml搭建、为属性注入值_2015.01.04
  7. Javascript offsetLeft详情
  8. 将spfile存储在ASM中
  9. 【.net】创建属于自己的log组件——改进版
  10. DICOM医学图像处理:DIMSE消息发送与接收“大同小异”之DCMTK fo-dicom mDCM
  11. Linux初始root密码设置
  12. EXP/IMP的三种模式
  13. HTML编码的用户输入
  14. Kafka 高性能吞吐揭秘
  15. 一个经典的PHP验证码类分享
  16. 指针--摘自C++技术网 作者dx
  17. BZOJ2002(分块)
  18. Python和SQL Server 2017的强大功能
  19. idea免费破解
  20. AXI

热门文章

  1. PCL法线估计
  2. Qt入门——使用QT+VS2008开发windows应用程序
  3. android studio 解析Excel数据格式导入poi-3.17.jar时的一系列报错及处理Failed resolution of: Ljavax/xml/stream/XMLEventFactory,duplicate entry: org/apache/xmlbeans/xml/stream/Location.class,GC overhead limit exceeded
  4. C# 使用XPath解析网页
  5. Java如何获取正在运行的线程的Id?
  6. unity--------------------四元数的旋转与原理
  7. (原创)Python文件与文件系统系列(3)——os.path模块
  8. spring oxm入门(包含demo)
  9. Chrome Adobe Flash Player 因过期而 阻止
  10. C# IP地址与数字之间的互转