您的位置:首页 > 教育 > 培训 > Vue使用Echarts(入门级)

Vue使用Echarts(入门级)

2024/10/6 9:24:45 来源:https://blog.csdn.net/SDKL_YI/article/details/140296837  浏览:    关键词:Vue使用Echarts(入门级)

最终效果:
在这里插入图片描述

npm install echarts --save	// 先安装echarts
<template><!-- 创建一个dom区域用于挂载echarts图表 --><div id="chart" style="width: 600px;height:500px;"/>
</template>
<script>
import * as echarts from 'echarts' // 导入echartsexport default {name: 'DataGraph',data() {return {chart: null // 声明一个变量用于存放echarts实例}},mounted() {this.initChart() // echarts初始化创建函数},methods: {initChart() {// 使用echarts.init创建实例,参数为要挂载的dom对象this.chart = echarts.init(document.getElementById('chart'))// echarts相关参数const option = {title: {text: 'ECharts 入门示例'},tooltip: {},legend: {data: ['销量']},xAxis: {data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']},yAxis: {},series: [{name: '销量',type: 'bar',data: [5, 20, 36, 10, 10, 20]}]}// 对于实例设置上面所配置的参数this.chart.setOption(option)}}
}
</script>
<style scoped>
</style>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com