給echarts圖表線條、數據點和區(qū)域設置顏色示例代碼

let myChart = echarts.init(document.getElementById("chartmainCop"));
// 獲取當前干部的各項評分
const allIndicators = Object.keys(this.dialogEacherTable[0])
.filter(key => key !== "CadreID" && key !== "xm")
.map(key => ({
name: key,
max: 100
}));
const colors = ["#D1351B", "#7DA5F0", "#90C66C"]; //邊框色
const areaColors = [
"rgba(241,176,166,0.5)",
"rgba(229,243,253,0.5)",
"rgba(234,245,226,0.5)"
]; //覆蓋色
const seriesData = this.dialogEacherTable.map((item, index) => {
const color = colors[index % colors.length];
const areaColor = areaColors[index % areaColors.length];
return {
value: Object.keys(item)
.filter(key => key !== "CadreID" && key !== "xm")
.map(key => item[key]),
name: item.xm,
lineStyle: {
color: color
},
itemStyle: {
color: color
},
areaStyle: {
color: areaColor
}
};
});
const option = {
tooltip: { },
legend: {
data: seriesData.map(item => item.name),
bottom: 10
},
radar: {
name: {
textStyle: {
color: "#000",
borderRadius: 1,
padding: [1, 1]
}
},
indicator: allIndicators,
radius: "60%",
fontSize: 14
},
series: [
{
name: "各項能力",
type: "radar",
data: seriesData
}
]
};
myChart.setOption(option);配置項解析:
tooltip:原本有自定義格式化函數,但被注釋掉了,用于顯示鼠標懸停時的提示信息。legend:定義了圖例的位置和數據,數據來源于seriesData的干部名字。radar:配置雷達圖的指標、半徑比例和字體大小。series:定義了數據系列,包括系列的名字、類型(雷達圖)和數據來源。
這里主要使用到了3個邊框色和三個覆蓋色,因為我的業(yè)務里面最多只需要三種顏色就可以。并把顏色值賦值給lineStyle、itemStyle、areaStyle
lineStyle
lineStyle用于配置線條的樣式,它通常用在折線圖、雷達圖等圖表中。主要屬性包括:
color:線條的顏色。width:線條的寬度。type:線條的類型,如'solid'(實線)、'dashed'(虛線)或'dotted'(點線)。shadowBlur、shadowColor、shadowOffsetX、shadowOffsetY:陰影效果的配置。
例如:
lineStyle: {
color: '#ff0000',
width: 2,
type: 'dashed'
}itemStyle
itemStyle用于配置圖表中單個數據項的樣式,適用于多種圖表類型,如折線圖的數據點、柱狀圖的柱子、餅圖的扇區(qū)等。主要屬性包括:
color:數據項的顏色。borderColor:邊框顏色。borderWidth:邊框寬度。borderType:邊框類型。shadowBlur、shadowColor、shadowOffsetX、shadowOffsetY:陰影效果的配置。
itemStyle: {
color: '#00ff00',
borderColor: '#000000',
borderWidth: 1
}areaStyle
areaStyle用于配置圖表中區(qū)域填充的樣式,常用于折線圖的區(qū)域填充。主要屬性包括:
color:填充顏色,可以是純色,也可以是漸變色。opacity:透明度,取值范圍是0~1。
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{offset: 0, color: 'rgba(0,0,255,0.3)'},
{offset: 1, color: 'rgba(0,0,255,0)'}
])
}lineStyle、itemStyle和areaStyle分別被用來配置線條顏色、數據點顏色和區(qū)域填充顏色。這樣可以使得圖表的視覺效果更加豐富和美觀。
總結
到此這篇關于給echarts圖表線條、數據點和區(qū)域設置顏色的文章就介紹到這了,更多相關echarts圖表設置顏色內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
javascript 移動鼠標得到單元格所在table表中的rowIndex位置[兼容ie,firefox]
移動鼠標,得到單元格所在表中的位置,主要是學習使用js的e.srcElement.2009-12-12
JavaScript程序設計高級算法之動態(tài)規(guī)劃實例分析
這篇文章主要介紹了JavaScript程序設計高級算法之動態(tài)規(guī)劃,結合實例形式分析了javascript動態(tài)規(guī)劃算法的原理、實現技巧與相關使用注意事項,需要的朋友可以參考下2017-11-11

