在 ECharts 中设置折线图的颜色可以通过以下几种方式实现:

  1. 使用全局配置项 'color' 设置所有系列的颜色:

    option = {
      color: ['#ff0000', '#00ff00', '#0000ff'],  // 设置为红、绿、蓝三种颜色
      // ...
    };
    
  2. 在每个系列的配置项中单独设置颜色:

    option = {
      series: [
        {
          name: '系列1',
          type: 'line',
          data: [/* 数据数组 */],
          itemStyle: {
            color: '#ff0000'  // 设置为红色
          }
        },
        {
          name: '系列2',
          type: 'line',
          data: [/* 数据数组 */],
          itemStyle: {
            color: '#00ff00'  // 设置为绿色
          }
        },
        // ...
      ]
    };
    
  3. 使用渐变色来设置颜色:

    option = {
      series: [
        {
          name: '系列1',
          type: 'line',
          data: [/* 数据数组 */],
          itemStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {offset: 0, color: '#ff0000'},  // 起始颜色为红色
              {offset: 1, color: '#00ff00'}   // 结束颜色为绿色
            ])
          }
        },
        // ...
      ]
    };
    

以上是一些常用的设置折线图颜色的方法,你可以根据需要选择其中一种或多种方式来进行设置。

ECharts 折线图颜色设置方法详解

原文地址: https://www.cveoy.top/t/topic/qlsn 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录