欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 锐评 > Vue+Echarts做图表展示

Vue+Echarts做图表展示

2024/11/30 12:39:25 来源:https://blog.csdn.net/weixin_60457220/article/details/140486991  浏览:    关键词:Vue+Echarts做图表展示

1.Echarts安装

终端运行安装命令:

npm install echarts -s

在main.js做全局引用:

//引入echarts
import * as echarts from 'echarts'
//vue全局注入echarts
Vue.prototype.$echarts = echarts;

 2.页面使用Echarts画柱状图和饼图

效果:

代码展示:

        <!-- 统计信息展示 --><div style="display: flex; justify-content: space-around;margin-top: 36px;"><!-- 工作量统计 --><div class="echart-work" ref="echartWork"></div><!-- 库存统计 --><div class="echart-work" ref="echartRepertory"></div></div>mounted() {// 挂载完成dom后进行初始化this.showEcarts();},methods: {showEcarts() {//工作量统计const echartWork = this.$refs.echartWorkconst mycartEchartWork = this.$echarts.init(echartWork)//库存统计const echartRepertory = this.$refs.echartRepertoryconst mycartEchartRepertory = this.$echarts.init(echartRepertory)//绘制工作量统计图表const optionEchartWork = {title : {text: '工作量统计',subtext: '总计',left: '2%',top: '2%',},tooltip : {trigger: 'axis'},legend: {data:['']},toolbox: {show : true,feature : {mark : {show: true},dataView : {show: true, readOnly: false},magicType: {show: true, type: ['line', 'bar']},restore : {show: true},saveAsImage : {show: true}}},calculable : true,grid: [{top: 60,width: '90%',bottom: '10%',left: 10,containLabel: true},],xAxis : [{type : 'value',boundaryGap : [0, 0.01]}],yAxis : [{type : 'category',data : ['管理员','若依','Njcdv','曹日新','了不起的菜包','测试']}],series : [{name:'工作量',type:'bar',itemStyle: {color: 'rgb(30,144,255)'},data:[85, 0, 0, 143, 0, 20]},]};//绘制库存统计图表const optionEchartRepertory = {title : {text: '库存统计',subtext: '总计114',x:'center',top: '2%',},tooltip : {trigger: 'item',formatter: "{a} <br/>{b} : {c} ({d}%)"},legend: {orient : 'vertical',x : 'left',data:['打点下载','素材','专题','其他','文档','音频']},toolbox: {show : true,feature : {mark : {show: true},dataView : {show: true, readOnly: false},magicType : {show: true, type: ['pie', 'funnel',],option: {funnel: {x: '25%',width: '50%',funnelAlign: 'left',max: 1548}}},// restore : {show: true},saveAsImage : {show: true}}},// calculable : true,series : [{name:'库存统计',type:'pie',radius : '55%',center: ['50%', '60%'],itemStyle: {normal: {color: function (colors) {var colorList = ['#fc8251', '#5470c6', '#91cd77', '#ef6567', '#f9c956', '#75bedc'];return colorList[colors.dataIndex];}}},data:[{value:335, name:'打点下载'},{value:310, name:'素材'},{value:234, name:'专题'},{value:1548, name:'其他'},{value:135, name:'文档'},{value:548, name:'音频'},]}]};// 渲染图表mycartEchartWork.setOption(optionEchartWork)mycartEchartRepertory.setOption(optionEchartRepertory)}

版权声明:

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

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