echarts饼图设置颜色
时间: 2023-09-28 11:11:26 浏览: 114
在ECharts中,有多种方法可以设置饼图的颜色。一种方法是在series内配置饼图的颜色,可以使用itemStyle中的normal属性来设置颜色。可以通过定义一个颜色数组,然后通过索引来选择颜色。例如:
series: [
itemStyle: {
normal: {
color: function (colors) {
var colorList = [ '#fc8251', '#5470c6', '#9A60B4', '#ef6567', '#f9c956', '#3BA272' ];
return colorList[colors.dataIndex];
}
},
}
]
另一种方法是在option内配置饼图的颜色,可以通过color属性来设置颜色。例如:
option: {
color: [ '#fc8251', '#5470c6', '#9A60B4', '#ef6567', '#f9c956', '#3BA272' ],
}
还可以在data内配置饼图的颜色,通过在每个数据项中设置color属性来指定颜色。例如:
data: [
{ value: 335, name: '直接访问', color: '#fc8251' },
{ value: 310, name: '邮件营销', color: '#5470c6' },
{ value: 234, name: '联盟广告', color: '#9A60B4' },
{ value: 135, name: '视频广告', color: '#ef6567' },
{ value: 1548, name: '搜索引擎', color: '#f9c956' }
]
通过以上方法,可以根据需要自定义或者随机显示饼图的颜色。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [ECharts 饼图颜色设置教程 - 3 种方式设置饼图颜色](https://blog.csdn.net/xm1037782843/article/details/129914814)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [ECharts 饼状图颜色设置](https://blog.csdn.net/qq_38778882/article/details/130596533)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文