vue饼图统计_vue中使用echarts画饼状图

本文介绍如何在Vue项目中按需引入ECharts库,通过示例代码展示如何创建饼状图,包括数据初始化、图表配置以及效果展示。同时提及了如何改变折线图颜色和工具栏样式的技巧。
摘要由CSDN通过智能技术生成

新地址:

ECharts 正在 Apache 开源基金会孵化中,因此域名已不再使用,请访问  echarts.apache.org

ECharts is now under incubation at the Apache Software Foundation. So this domain name is no longer in use. Visit echarts.apache.org please

采用按需引入的方式

安装echarts包就不说了,上一篇有代码

今天来看看如何画饼状图

let echarts = require('echarts/lib/echarts')//引入饼状图组件

require('echarts/lib/chart/pie')//引入提示框和title组件

require('echarts/lib/component/tooltip')

require('echarts/lib/component/title')exportdefault{created(){

},

mounted(){this.initData();

},methods:{//初始化数据

initData() {//基于准备好的dom,初始化echarts实例

var myChart = echarts.init(document.getElementById('main1'));//绘制图表

myChart.setOption({

title : {

text:'某站点用户访问来源',//主标题

subtext:'纯属虚构',//副标题

x:'center',//x轴方向对齐方式},

tooltip : {

trigger:'item',

formatter:"{a}
{b} : {c} ({d}%)"},

legend: {

orient:'vertical',

bottom:'bottom',

data: ['直接访问','邮件营销','联盟广告','视频广告','搜索引擎']

},

series : [

{

name:'访问来源',

type:'pie',

radius :'55%',

center: ['50%', '60%'],

data:[

{value:335, name:'直接访问'},

{value:310, name:'邮件营销'},

{value:234, name:'联盟广告'},

{value:135, name:'视频广告'},

{value:1548, name:'搜索引擎'}

],

itemStyle: {

emphasis: {

shadowBlur:10,

shadowOffsetX:0,

shadowColor:'rgba(0, 0, 0, 0.5)'}

}

}

]

});

},

}

}

效果图

具体设置请参考 官网

改变折线图的颜色以及折点颜色:

series: [

{

name: 折线图名称,

type:'line',

data: [...],

smooth:true,

itemStyle : { normal : { lineStyle:{ color:'#324ED9'},color:'#324ED9'},},

},

{

name: 折线图名称,

type:'line',

data: [...],

smooth:true,

itemStyle : { normal : { lineStyle:{ color:'#2BB02D'},color:'#2BB02D'},},

}

]

改变工具栏样式:

//右上角工具栏

toolbox: {

emphasis:{

iconStyle:{

borderColor:"#486eff",//自定义鼠标悬浮工具栏图标的颜色}

},

feature: {

magicType: {

type: ['line', 'bar'],

icon:{

line:"path://xxx",//自定义折现图标

bar:"path://xxx",//自定义柱状图图标

}

},

saveAsImage: {

show:true,

name:'OverviewPic',//导出图片名称

icon:"path://xxx",//自定义保存图标icon

},

myTool1: {//自定义工具栏

show:true,

title: 自定义工具名称,

icon: "path://xxxxx",

onclick:function(){

//dosome...}

},

},

tooltip: {}

},

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值