ECharts餅圖顏色設(shè)置的4種方式總結(jié)
ECharts 餅狀圖顏色設(shè)置教程
- 方法一:在
series
內(nèi)配置餅狀圖顏色 - 方法二:在
option
內(nèi)配置餅狀圖顏色 - 方法三:在
data
內(nèi)配置餅狀圖顏色 - 方法四:配置 ECharts 餅狀圖隨機(jī)顏色
Charts 餅狀圖中的每個扇形顏色其實(shí)都可以自定義或者隨機(jī)顯示顏色。本文講解 4 種配置修改 ECharts 餅圖顏色的方法。
方法一:在 series 內(nèi)配置餅狀圖顏色
series: [ itemStyle: { normal: { color: function (colors) { var colorList = [ '#fc8251', '#5470c6', '#9A60B4', '#ef6567', '#f9c956', '#3BA272' ]; return colorList[colors.dataIndex]; } }, } ]
EChart.js 在 series
中設(shè)置餅狀圖顏色的 Demo 源代碼:
this.chart.setOption({ legend: { orient: "vertical", left: "left", textStyle: { //圖例中文字的樣式 color: "#ffffff", fontSize: 12, }, }, series: [ { type: "pie", radius: "50%", data: this.optionData, emphasis: { itemStyle: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: "rgba(0, 0, 0, 0.5)", }, }, labelLine: { show: false, //隱藏指示線 }, label: { show: false, //隱藏標(biāo)示文字 }, itemStyle: { normal: { color: function (colors) { var colorList = [ '#fc8251', '#5470c6', '#9A60B4', '#ef6567', '#f9c956', '#3BA272' ]; return colorList[colors.dataIndex]; } }, } }, ], });
效果
方法二:在 option 內(nèi)配置餅狀圖顏色
this.chart.setOption({ legend: { orient: "vertical", left: "left", textStyle: { //圖例中文字的樣式 color: "#ffffff", fontSize: 12, }, }, color:['#fc8251','#5470c6','#9A60B4','#ef6567', '#f9c956','#3BA272']; series: [ { type: "pie", radius: "50%", data: this.optionData, emphasis: { itemStyle: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: "rgba(0, 0, 0, 0.5)", }, }, labelLine: { show: false, //隱藏指示線 }, label: { show: false, //隱藏標(biāo)示文字 }, }, ], });
方法三:在 data 內(nèi)配置餅狀圖顏色
**data: [ { value: 917, name: '搜索引擎',itemStyle: {color:'#fc8251'}}, { value: 873, name: '微信朋友圈',itemStyle: {color:'#5470c6'}}, { value: 678, name: 'Feeds 廣告',itemStyle: {color:'#91cd77'}}, { value: 583, name: '直接訪問',itemStyle: {color:'#ef6567'}}, { value: 432, name: '口碑介紹',itemStyle: {color:'#f9c956'}} ] **
EChart.js 在 data
中設(shè)置餅狀圖顏色的 Demo 源代碼:
option = { legend: { top: 'bottom' }, series: [ { name: '', type: 'pie', radius: [50, 250], center: ['50%', '50%'], roseType: 'area', itemStyle: { borderRadius: 8 }, data: [ { value: 917, name: '搜索引擎',itemStyle: {color:'#fc8251'}}, { value: 873, name: '微信朋友圈',itemStyle: {color:'#5470c6'}}, { value: 678, name: 'Feeds 廣告',itemStyle: {color:'#91cd77'}}, { value: 583, name: '直接訪問',itemStyle: {color:'#ef6567'}}, { value: 332, name: '電話銷售',itemStyle: {color:'#f9c956'} }, { value: 432, name: '口碑介紹',itemStyle: {color:'#75bedc'}} ] } ] };
方法四:配置 ECharts 餅狀圖隨機(jī)顏色
color: function () { return ( 'rgb(' + [ Math.round(Math.random() * 270), Math.round(Math.random() * 370), Math.round(Math.random() * 400) ].join(',') + ')' ); },
option = { legend: { top: 'bottom' }, series: [ { name: '', type: 'pie', radius: [50, 250], center: ['50%', '50%'], roseType: 'area', itemStyle: { color: function () { return ( 'rgb(' + [ Math.round(Math.random() * 270), Math.round(Math.random() * 370), Math.round(Math.random() * 400) ].join(',') + ')' ); }, borderRadius: 8 }, data: [ { value: 917, name: '搜索引擎'}, { value: 873, name: '微信朋友圈'}, { value: 678, name: 'Feeds 廣告'}, { value: 583, name: '直接訪問'}, { value: 332, name: '電話銷售'}, { value: 432, name: '口碑介紹'} ] } ] };
總結(jié)
到此這篇關(guān)于ECharts餅圖顏色設(shè)置的4種方式總結(jié)的文章就介紹到這了,更多相關(guān)ECharts餅圖顏色設(shè)置內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用sql.js實(shí)現(xiàn)前端SQLite數(shù)據(jù)庫操作
sql.js?是將?SQLite?數(shù)據(jù)庫編譯為?JavaScript?的庫,允許開發(fā)者在瀏覽器環(huán)境中直接操作?SQLite?數(shù)據(jù)庫,本文主要介紹了如何使用sql.js實(shí)現(xiàn)多張表的關(guān)聯(lián)操作,需要的可以了解下2024-12-12JavaScript設(shè)計(jì)模式之單例模式實(shí)例
這篇文章主要介紹了JavaScript設(shè)計(jì)模式之單例模式實(shí)例,本文用一個實(shí)際例子講解JavaScript中的單例模式,需要的朋友可以參考下2014-09-09js實(shí)現(xiàn)同一頁面可多次調(diào)用的圖片幻燈切換效果
這篇文章主要介紹了js實(shí)現(xiàn)同一頁面可多次調(diào)用的圖片幻燈切換效果,可實(shí)現(xiàn)在同一頁面中多次調(diào)用幻燈切換效果,非常具有實(shí)用價值,需要的朋友可以參考下2015-02-02javascript使用eval或者new Function進(jìn)行語法檢查
使用代碼來實(shí)現(xiàn)分析代碼的語法,這是一件極其痛苦的事情。簡單的解決辦法是:使用腳本引擎自己的語法檢查,比方說eval( ) 或者new Function( )。2010-10-10