vue项目引入echarts柱状图
2024-08-30 14:13:59
一。components文件下引入 barCharts.vue文件
<template>
<div :class="className" :style="{height:height,width:width}" />
</template> <script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
//import resize from './mixins/resize' const animationDuration = 6000 export default {
//mixins: [resize],
props: {
className: {
type: String,
default: 'chart'
},
width: {
type: String,
default: '100%'
},
height: {
type: String,
default: '200px'
}
},
data() {
return {
chart: null
}
},
mounted() {
this.$nextTick(() => {
this.initChart()
})
},
beforeDestroy() {
if (!this.chart) {
return
}
this.chart.dispose()
this.chart = null
},
methods: {
initChart() {
this.chart = echarts.init(this.$el, 'macarons') this.chart.setOption({
tooltip: {
trigger: 'axis',
axisPointer: { // 坐标轴指示器,坐标轴触发有效
type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
}
},
grid: {
top: 30,
left: '2%',
right: '1%',
bottom: 10,
containLabel: true
},
dataset: {
source: [
['product', '2015','2016'],
['AC06H', 143.3,60],
['AC06L', 83.1,21.4],
['AC12N', 386.4 ,35.3],
['AC125', 72.4 ,10],
['AC13E', 192.4 ,72],
['AC13W', 572.4 ,10],
['AC18H', 142.4 ,47],
]
},
xAxis: { type: 'category' },
yAxis: {},
series: [{
type: 'bar',
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#09c9c5' },
{ offset: 1, color: '#003791' }
])
}
},{
type: 'bar',
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#5eff4d' },
{ offset: 1, color: '#245119' }
])
},
}]
})
}
}
}
</script>
二。需要的页面引入组件:
效果图如下:
最新文章
- CompletionService/ExecutorCompletionService/线程池/concurrent包
- jdk+myeclipse配置安装相关步骤
- LinqToSQL实例参见
- ANDROID L——Material Design详细解释(UI控制)
- Swift语言指南(七)--语言基础之布尔值和类型别名
- spring boot + vue + element-ui全栈开发入门——基于Electron桌面应用开发
- ios开发数据库版本迁移手动更新迭代和自动更新迭代艺术(二)
- 关于项目里server清楚缓存的代码
- 解决关于 ionic3 启动白屏 控制台错误提示:Uncaught SyntaxError Use of const in strict mode.
- [20180408]那些函数索引适合字段的查询.txt
- linux 查看cpu的使用百分比
- CF 954H Path Counting
- 【转】netstat 的10个基本用法
- sql server不要插入大数据,开销太大
- EXCEL 单元格引用问题
- PECL: configuration option ";php_ini"; is not set to php.ini location
- Howto run google-chrome as root
- linux使用rsync、inotify-tools实现多台服务器文件实时同步
- uber shader
- nyoj-1016-德莱联盟(向量叉乘判断线段相交)