Highcharts stock图 线型图 区分股票日盘,夜盘

​​​​先借助配色网站coolors,调整saturation, brightness和temperature,配出默认色加深色,颜色代码如下

export const HighchartColorsEnum = [
    '#7cb5ec',
    '#90ed7d',
    '#f7a35c',
    '#8085e9',
    '#f15c80',
    '#e4d354',
    '#2b908f',
    '#f45b5b',
    '#91e8e1'
  ]

  // brightness: -50, temperature 10, saturation 0
export const HighchartColorsDarkEnum = [
  '#245591',
  '#409020',
  '#A14708',
  '#2B258D',
  '#980D2B',
  '#877015',
  '#1B4343',
  '#9D0B0B',
  '#2D8F87'
]

效果如下

在Highcharts中,线条分色的配置项是series.line.zones
An array defining zones within a series. Zones can be applied to the X axis, Y axis or Z axis for bubbles, according to the zoneAxis option. The zone definitions have to be in ascending order regarding to the value.

如何配置可以查阅该示例,我们将zoneAxis设置成横轴坐标轴,然后将数据按照时间进行分区,分为以下三个区域

0:00-8:59 夜盘
9:00-19:00 日盘

19:00-23:59 夜盘

计算最小的最大的timestamp对应的年月日为startDate, endDate,days为开始和结束之间相隔的天数,我们再循环内,针对每一天进行时间的分区,算法如下

getZones(res, index) {
      const zones = []
      if (res.values && res.values.length) {
        const startTimeStamp = res.values[0][0]
        const startMoment = moment(startTimeStamp)
        const endTimeStamp = res.values[res.values.length -1][0]
        const startDate = {
          year: startMoment.year(),
          month: startMoment.month(),
          day: startMoment.date()
        }
        const days = Math.ceil((endTimeStamp - startTimeStamp) / (1000 * 3600 * 24))

        for (let i = 0; i < days + 1; i++) {
          zones.push(...[{
              value: Date.UTC(startDate.year, startDate.month, startDate.day + i, 0, 0),
              color: HighchartColorsEnum[index]
            }, {
              value: Date.UTC(startDate.year, startDate.month, startDate.day + i, 8, 59),
              color: HighchartColorsEnum[index]
            }, {
              value: Date.UTC(startDate.year, startDate.month, startDate.day + i, 19, 0),
              color: HighchartColorsDarkEnum[index]
            }, {
              value: Date.UTC(startDate.year, startDate.month, startDate.day + i, 23, 59),
              color: HighchartColorsEnum[index]
            }
          ])
        }
      }
      return zones
    }

在series.line配置

{
    zoneAxis: 'x',
    yAxis: index % 2,
    data: [],
    name: `${res.strategy}.${res.data_name}`,
    tooltip: { valueDecimals: 4 },
    type: 'line',
    data: res.values,
    zones: day_night ? this.getZones(res, index) : []
}

这里的res是接口返回的数据,示例如下

{
    "values": [
        [
            1702558813000,
            0.5
        ],
        [
            1702558824000,
            0.5
        ],
        [
            1702558836000,
            0.5
        ],
        [
            1702558848000,
            0.5
        ],
        [
            1702558860000,
            0.5
        ],
        [
            1702558872000,
            0.533059
        ],
        [
            1702558887000,
            0.535286
        ],
        [
            1702558900000,
            0.535286
        ],
        [
            1702558911000,
            0.533924
        ],
        [
            1702558924000,
            0.532048
        ],
        [
            1702558938000,
            0.533799
        ],
        [
            1702558950000,
            0.53583
        ],
        [
            1702558963000,
            0.53935
        ],
        [
            1702558974000,
            0.543211
        ],
        [
            1702558985000,
            0.543905
        ],
        [
            1702558998000,
            0.542447
        ],
        [
            1702559013000,
            0.538705
        ],
        [
            1702559025000,
            0.534785
        ],
        [
            1702559036000,
            0.535363
        ],
        [
            1702559063000,
            0.536544
        ],
        [
            1702559076000,
            0.537351
        ],
        [
            1702559089000,
            0.536926
        ],
        [
            1702559101000,
            0.538045
        ],
        [
            1702559112000,
            0.539609
        ],
        [
            1702559124000,
            0.54059
        ],
        [
            1702559137000,
            0.541295
        ],
        [
            1702559148000,
            0.540882
        ]
    ],
    "strategy": "***",
    "data_name": "***"
}

最后效果如下:

推荐下列配色网站:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值