<template>
<div class="echarts">
<IEcharts :option="bar" :loading="loading" @ready="onReady" @click="onClick"></IEcharts>
<button @click="doRandom">Random</button>
</div>
</template>
<script type="text/babel">
import IEcharts from 'vue-echarts-v3/src/full.js';
export default {
name: 'view',
components: {
IEcharts
},
props: {
},
data: () => ({
loading: true,
bar: {
title: {
text: 'ECharts Hello World'
},
tooltip: {},
xAxis: {
data: ['Shirt', 'Sweater', 'Chiffon Shirt', 'Pants', 'High Heels', 'Socks']
},
yAxis: {},
series: [{
name: 'Sales',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
}
}),
methods: {
doRandom() {
const that = this;
let data = [];
for (let i = 0, min = 5, max = 99; i < 6; i++) {
data.push(Math.floor(Math.random() * (max + 1 - min) + min));
}
that.loading = !that.loading;
that.bar.series[0].data = data;
},
onReady(instance) {
console.log(instance);
},
onClick(event, instance, echarts) {
console.log(arguments);
}
}
};
</script>
<style scoped>
.echarts {
width: 400px;
height: 400px;
}
</style>
vue.js使用vue-echarts给柱形图绑定点击事件
最新推荐文章于 2025-09-11 04:12:38 发布
本文介绍了一个使用Vue.js结合ECharts实现的动态柱状图案例。该案例通过随机数更新数据来展示图表的变化效果,并提供了按钮触发数据更新的功能。文章详细展示了如何配置图表样式和数据源,以及如何在Vue组件中集成ECharts。
2648

被折叠的 条评论
为什么被折叠?



