更改HighCharts散点图中的线条颜色时出现控制台错误

时间:2017-06-27 15:23:00

标签: debugging events highcharts scatter-plot

我在使用HighCharts散点图(JSFiddle demo this)中悬停系列时,已采用here解决方案来更改线条颜色:

$(function () {
    $('#container').highcharts({
        chart: {
            type: 'scatter',
        },
        plotOptions: {
            scatter: {
                lineWidth:1,
                marker: {
                    radius: 1,
                    symbol:'circle',
                    fillColor: '#800000',
                    states: {
                        hover: {
                            enabled: true,
                            radius:0,
                            radiusPlus:2,
                            lineColor: '#ff0000',
                            fillColor: '#ff0000'
                        }
                    }
                },
                events: {
                    mouseOver: function () {

                        this.chart.series[this.index].update({
                            color: 'red'
                        });
                    },
                    mouseOut: function () {

                        this.chart.series[this.index].update({
                            color: "#b0b0b0"
                        });                           
                    }
                }
            }
        },
        series: [{
            name: 'A',
            color: "#b0b0b0",
            data: [[38,42],[39,39],[35,45],[35,54],{x:36,y:35,marker:{radius:8,symbol:'circle'}}
            ]
        }, {
            name: 'B',
            color: "#b0b0b0",
            data: [[46,56],[47,67],[48,69],[50,55],{x:52,y:57,marker:{radius:8,symbol:'circle'}}
            ]
        }]
    });
});

该脚本可以运行但运行Web控制台我看到每个系列的悬停都会导致TypeError: g.firePointEvent is not a function error

在我的另一个脚本中,错误为TypeError: hoverPoint.firePointEvent is not a function

这是HighCharts的错误还是可以避免它?

1 个答案:

答案 0 :(得分:1)

问题是由您在操作之前调用的更新引起的。因此,您尝试在结束之前引用更新的点。解决方案是使用attr()方法并在路径上更改SVG颜色。

events: {
      mouseOver: function() {

        this.chart.series[this.index].graph.attr({
            stroke: 'red'
        });
      },
      mouseOut: function() {
                    this.chart.series[this.index].graph.attr({
            stroke: '#b0b0b0'
        });
      }
    }

演示: