formatting all the markers for the hovering series

2019-08-19 20:25发布

问题:

I want to change the appearange of all the markers (not only the one pointed) when hovering the series, but the following code (http://jsfiddle.net/fw852fy9/4/) does not work properly. What's wrong?

Highcharts.chart('container', {
        chart: {
            type: 'scatter'
        },
    plotOptions: {
      series: {
        lineWidth:1,
              states: {
                  hover: {
                      lineWidthPlus: 2,
            marker: {
              enabled: true,
              radius:3,
              states: {
                hover: {
                  fillColor:'#FF0000',
                  lineColor:'#00FF00',
                  lineWidth:3,
                  radius:12
                }
              }
            }  
                  }
              },
        marker: {
          enabled: true,
          radius:3,
          states: {
                  hover: {
              fillColor:'#FF0000',
              lineColor:'#00FF00',
              lineWidth:3,
              radius:12
              }
          }
        }
      }  
    },
    series: [{
      data: [[29.9, 71.5], [106.4, 129.2], [144.0, 176.0], [135.6, 148.5], [216.4, 194.1], [95.6, 54.4]]
    }]
});

回答1:

Hover state works only for the point which is hovered. If you want to set all the markers to be hovered, you need to change their state programmatically, e.g. on series mouseover/mouseout.

  series: [{
 stickyTracking: false,
events: {
  mouseOver: function() {
    this.data.forEach(p => p.setState('hover'))
  },
  mouseOut: function() {
    this.data.forEach(p => p.setState())
  }
},

example: http://jsfiddle.net/0zu9jmca/