higcharts横坐标crosshair设置渐变色

如何设置highcharts的crosshair的渐变色

您可以使用函数 Axis.addPlotBand()创建一个绘图带,在mouseOver事件使用,在mouseOut移除使用,详细可以查看如下代码例子

await this.$nextTick()
      let self = this
      HighCharts.chart('line', {
        chart: {
          type: 'spline'
        },
        title: {
          text: ''
        },
        legend: {
          enabled: false
        },
        credits: {
          enabled: false
        },

        tooltip: {
        },
        xAxis: {
          //表示为时间,注意大小写
          type: 'datetime',
          //格式化时间,day,week....
          dateTimeLabelFormats: {
            day: '%Y-%m-%d'
          },

        },
        yAxis: {
          opposite: true,
          title: {
            text: ''
          }
        },
        plotOptions: {

          spline: {
            lineWidth: 2,
            color: '#00B8A4',
            states: {
              hover: {
                lineWidth: 3
              }
            },
            marker: {
              enabled: false
            },
            //设置crosshair渐变色
            point: {
              events: {
                mouseOver: function (e) {
                  var targetX = e.target.x,
                    from = targetX - 0.1,
                    to = targetX + 0.1;
                  this.series.chart.xAxis[0].addPlotBand({
                    id: 'plot-band-1',
                    from: from,
                    to: to,
                    zIndex: 2,
                    color: {
                      linearGradient: {
                        x1: 0,
                        x2: 0,
                        y1: 1,
                        y2: 0
                      },
                      stops: [
                        [0, 'rgba(0, 184, 164, 0)'],
                        [1, 'rgba(0, 184, 164, 1)']
                      ]
                    }
                  });
                },
                mouseOut: function (e) {
                  this.series.chart.xAxis[0].removePlotBand('plot-band-1');
                }
              }
            }
          },
          series: {
            point: {
              events: {
                mouseOver: function () {
                  console.log('鼠标移入》〉》〉', this, this.x);
                  self.curX = this.x
                  self.curY = this.y
                }
              }
            },
            events: {
              mouseOut: function () {
                if (this.chart.lbl) {
                  this.chart.lbl.hide();
                }
              }
            }
          }
        },
        series: [
          { data: [[1527832563000, 29.9], [1527918791000, 71.5], [1528005191000, 106.4], [1528091591000, 129.2], [1528177991000, 144.0], [1528264563000, 176.0], [1528350963000, 135.6], [1528437363000, 148.5], [1528523763000, 216.4], [1528610163000, 194.1], [1528696563000, 95.6], [1528782963000, 54.4]] }
        ]
      });

在这里插入图片描述

如果对你有帮助,欢迎打赏
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值