0


给echarts图表线条、数据点和区域设置颜色

  1. let myChart = echarts.init(document.getElementById("chartmainCop"));
  2. // 获取当前干部的各项评分
  3. const allIndicators = Object.keys(this.dialogEacherTable[0])
  4. .filter(key => key !== "CadreID" && key !== "xm")
  5. .map(key => ({
  6. name: key,
  7. max: 100
  8. }));
  9. const colors = ["#D1351B", "#7DA5F0", "#90C66C"]; //边框色
  10. const areaColors = [
  11. "rgba(241,176,166,0.5)",
  12. "rgba(229,243,253,0.5)",
  13. "rgba(234,245,226,0.5)"
  14. ]; //覆盖色
  15. const seriesData = this.dialogEacherTable.map((item, index) => {
  16. const color = colors[index % colors.length];
  17. const areaColor = areaColors[index % areaColors.length];
  18. return {
  19. value: Object.keys(item)
  20. .filter(key => key !== "CadreID" && key !== "xm")
  21. .map(key => item[key]),
  22. name: item.xm,
  23. lineStyle: {
  24. color: color
  25. },
  26. itemStyle: {
  27. color: color
  28. },
  29. areaStyle: {
  30. color: areaColor
  31. }
  32. };
  33. });
  34. const option = {
  35. tooltip: { },
  36. legend: {
  37. data: seriesData.map(item => item.name),
  38. bottom: 10
  39. },
  40. radar: {
  41. name: {
  42. textStyle: {
  43. color: "#000",
  44. borderRadius: 1,
  45. padding: [1, 1]
  46. }
  47. },
  48. indicator: allIndicators,
  49. radius: "60%",
  50. fontSize: 14
  51. },
  52. series: [
  53. {
  54. name: "各项能力",
  55. type: "radar",
  56. data: seriesData
  57. }
  58. ]
  59. };
  60. myChart.setOption(option);

配置项解析:

  • tooltip:原本有自定义格式化函数,但被注释掉了,用于显示鼠标悬停时的提示信息。
  • legend:定义了图例的位置和数据,数据来源于seriesData的干部名字。
  • radar:配置雷达图的指标、半径比例和字体大小。
  • series:定义了数据系列,包括系列的名字、类型(雷达图)和数据来源。

这里主要使用到了3个边框色和三个覆盖色,因为我的业务里面最多只需要三种颜色就可以。并把颜色值赋值给lineStyle、itemStyle、areaStyle

lineStyle

  1. lineStyle

用于配置线条的样式,它通常用在折线图、雷达图等图表中。主要属性包括:

  • color:线条的颜色。
  • width:线条的宽度。
  • type:线条的类型,如'solid'(实线)、'dashed'(虚线)或'dotted'(点线)。
  • shadowBlurshadowColorshadowOffsetXshadowOffsetY:阴影效果的配置。

例如:

  1. lineStyle: {
  2. color: '#ff0000',
  3. width: 2,
  4. type: 'dashed'
  5. }
**
  1. itemStyle

**

  1. itemStyle

用于配置图表中单个数据项的样式,适用于多种图表类型,如折线图的数据点、柱状图的柱子、饼图的扇区等。主要属性包括:

  • color:数据项的颜色。
  • borderColor:边框颜色。
  • borderWidth:边框宽度。
  • borderType:边框类型。
  • shadowBlurshadowColorshadowOffsetXshadowOffsetY:阴影效果的配置。
  1. itemStyle: {
  2. color: '#00ff00',
  3. borderColor: '#000000',
  4. borderWidth: 1
  5. }

areaStyle

  1. areaStyle

用于配置图表中区域填充的样式,常用于折线图的区域填充。主要属性包括:

  • color:填充颜色,可以是纯色,也可以是渐变色。
  • opacity:透明度,取值范围是0~1。
  1. areaStyle: {
  2. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  3. {offset: 0, color: 'rgba(0,0,255,0.3)'},
  4. {offset: 1, color: 'rgba(0,0,255,0)'}
  5. ])
  6. }
  1. lineStyle

  1. itemStyle

  1. areaStyle

分别被用来配置线条颜色、数据点颜色和区域填充颜色。这样可以使得图表的视觉效果更加丰富和美观。


本文转载自: https://blog.csdn.net/qq_63322025/article/details/140865259
版权归原作者 阿 尭 所有, 如有侵权,请联系我们删除。

“给echarts图表线条、数据点和区域设置颜色”的评论:

还没有评论