vuejs中使用echart图表
2024-10-15 16:46:03
首先安装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({
})
})
}
最新文章
- XML基础
- String类型的属性和方法
- sql条件为空查询全部,不为空按条件查询以及多条件筛选查询。
- C++ - 复制(copy) 和 虚复制(virtual copy) 的 区别
- Unity2D 之 Sprite点击事件
- 通过struts.xml搭建、为属性注入值_2015.01.04
- Javascript offsetLeft详情
- 将spfile存储在ASM中
- 【.net】创建属于自己的log组件——改进版
- DICOM医学图像处理:DIMSE消息发送与接收“大同小异”之DCMTK fo-dicom mDCM
- Linux初始root密码设置
- EXP/IMP的三种模式
- HTML编码的用户输入
- Kafka 高性能吞吐揭秘
- 一个经典的PHP验证码类分享
- 指针--摘自C++技术网 作者dx
- BZOJ2002(分块)
- Python和SQL Server 2017的强大功能
- idea免费破解
- AXI
热门文章
- PCL法线估计
- Qt入门——使用QT+VS2008开发windows应用程序
- 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
- C# 使用XPath解析网页
- Java如何获取正在运行的线程的Id?
- unity--------------------四元数的旋转与原理
- (原创)Python文件与文件系统系列(3)——os.path模块
- spring oxm入门(包含demo)
- Chrome Adobe Flash Player 因过期而 阻止
- C# IP地址与数字之间的互转