ECharts,一个纯 Javascript 的图表库,可以流畅的运行在 PC 和移动设备上。echarts是开源的一个数据可视化的一个重要工具,运行流畅,并且是免费使用!
echarts支持vue吗?
echarts支持vue。可以通过在vue项目的main.js中全局引入echarts,然后将其绑定到vue原型上:
-
import echarts from 'echarts'
-
Vue.prototype.$echarts = echarts;
这样就可以在任何一个组件中使用echarts了,接下来我们在初始化项目中的helloWorld组件中使用echarts配置图标,具体如下:
<template> <div> <div style="width:500px;height:500px" ref="chart"></div> </div> </template> <script> export default{ data () { return {}; }, methods: { initCharts () { let myChart = this.$echarts.init(this.$refs.chart); console.log(this.$refs.chart) // 绘制图表 myChart.setOption({ title: { text: '在Vue中使用echarts' }, tooltip: {}, <mark style="color:transparent">来源gaodaimacom搞#代%码网</mark> xAxis: { data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"] }, yAxis: {}, series: [{ name: '销量', type: 'bar', data: [5, 20, 36, 10, 10, 20] }] }); } }, mounted () { this.initCharts(); } } </script>
这样下来,就可以在项目的任何地方使用echarts了。
更多vue.js相关知识,可访问 Vue.js答疑 栏目!!
以上就是echarts支持vue吗?的详细内容,更多请关注gaodaima搞代码网其它相关文章!