You need to enable JavaScript to run this app. 如何实现Highcharts面积图fillColor随zone分区颜色动态变化
优惠活动
大模型
产品
解决方案
定价
更多

如何实现Highcharts面积图fillColor随zone分区颜色动态变化

实现方案

你只需要将fillColor配置从全局plotOptions.area中移除,改为在每个zone配置项中单独定义对应颜色的渐变即可,Highcharts的zones本身支持为每个分区独立配置填充色属性。

修改后的代码示例如下:

this.chartOptions = {
...
      plotOptions: {
        area: {
          pointStart: chartStart,
          // 移除全局统一的fillColor配置
        }
      },
      series: [
        {
          type: 'area',
          data: this.avgVoltageSeries,
          pointInterval: ticksTime,
          pointStart: chartStart,
          zones: [{
            value: this.fenceNodeConfiguration.criticalVoltage / 1000,
            color: 'red',
            // 单独配置当前分区的红色渐变填充
            fillColor: {
              linearGradient: {x1: 0, x2: 0, y1: 0, y2: 1},
              stops: [
                [0, 'red'],
                [1, 'white']
              ]
            }
          }, {
            value: this.fenceNodeConfiguration.warningVoltage / 1000,
            color: 'orange',
            // 单独配置当前分区的橙色渐变填充
            fillColor: {
              linearGradient: {x1: 0, x2: 0, y1: 0, y2: 1},
              stops: [
                [0, 'orange'],
                [1, 'white']
              ]
            }
          }, {
            color: '#009900',
            // 单独配置当前分区的绿色渐变填充
            fillColor: {
              linearGradient: {x1: 0, x2: 0, y1: 0, y2: 1},
              stops: [
                [0, '#009900'],
                [1, 'white']
              ]
            }
          }],
        }]
    };
改动说明
  • 删除了全局统一的填充色配置,避免所有分区共用同一种渐变
  • 为每个zone新增了独立的fillColor属性,渐变规则保持你原有的从上到下从对应刻度色过渡到白色的逻辑,不同分区的填充渐变会自动随所属区域的刻度色切换

内容的提问来源于stack exchange,提问作者Riccardo Fachin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.10 14:30:02