失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > echarts年龄饼图_echarts饼图

echarts年龄饼图_echarts饼图

时间:2022-02-01 10:25:52

相关推荐

echarts年龄饼图_echarts饼图

1、添加点击事件并跳转到不同的页面

// 路径配置

require.config({

paths: {

echarts: '/build/dist/'

}

});

// 使用

var option;(设置全局变量)

require(

[

'echarts',

'echarts/chart/pie'// 使用柱状图就加载pie模块,按需加载

],

function (ec) {

// 基于准备好的dom,初始化echarts图表

var myChart = ec.init(document.getElementById('chartsmain1'));

var ecConfig = require('echarts/config');

myChart.on(ecConfig.EVENT.CLICK, eConsole);

option = {

title : {

text: '最常用社交媒体占比',

x:'center'

},

legend: {

orient : 'vertical',

x : 'left',

y:'bottom',

data:['QQ','微博','微信']

},

series : [

{

name:'访问来源',

type:'pie',

radius : '55%',

clickable : true,

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

data:[

{

value:335,

name:'QQ',

itemStyle:{

normal:{

color:'rgb(255,192,0)'

}

}

},

{

value:310,

name:'微博',

itemStyle:{

normal:{

color:'rgb(1,175,80)'

}

}

},

{

value:234,

name:'微信',

itemStyle:{

normal:{

color:'rgb(122,48,158)'

}

}

}

]

}

]

};

// 为echarts对象加载数据

myChart.setOption(option);

});

function eConsole(option) {

//获得option的值做出判断,添加链接

if(option.name=="QQ"){

window.open("/")

}else if(option.name=="微博"){

window.open("/")

}else{

window.open("/")

}

}

注意:加红色的部分为饼图添加点击事件所需的代码

2、饼图颜色和折线图的线条颜色一一对应应当保持一致并不依赖默认颜色

饼图

data:[

{

value:335,

name:'QQ',

itemStyle:{

normal:{

color:'rgb(255,192,0)'

}

}

},

{

value:310,

name:'微博',

itemStyle:{

normal:{

color:'rgb(1,175,80)'

}

}

},

{

value:234,

name:'微信',

itemStyle:{

normal:{

color:'rgb(122,48,158)'

}

}

}

]

红色的部分是修改默认颜色为自定义颜色

折线

series : [

{

name:'QQ',

type:'line',

stack: '总量',

data:[120, 132, 101, 134, 90, 230, 210],

itemStyle:{

normal:{

color:'rgb(255,192,0)',

}

}

},

{

name:'微信',

type:'line',

stack: '总量',

data:[220, 182, 191, 234, 290, 330, 310],

itemStyle:{

normal:{

color:'rgb(122,48,158)',

}

}

},

{

name:'微博',

type:'line',

stack: '总量',

data:[150, 232, 201, 154, 190, 330, 410],

itemStyle:{

normal:{

color:'rgb(1,175,80)',

}

}

}

]

效果图

如果觉得《echarts年龄饼图_echarts饼图》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。