如何在线性回归的Highcharts散点图中隐藏工具提示中的系列名称

时间:2018-01-20 04:41:12

标签: javascript charts highcharts tooltip

我使用Highcharts 4.2.3创建线性回归图表。我正在关注这个演示:

http://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/demo/combo-regression/

这是演示中的代码:

Highcharts.chart('container', {
    xAxis: {
        min: -0.5,
        max: 5.5
    },
    yAxis: {
        min: 0
    },
    title: {
        text: 'Scatter plot with regression line'
    },
    series: [{
        type: 'line',
        name: 'Regression Line',
        data: [[0, 1.11], [5, 4.51]],
        marker: {
            enabled: false
        },
        states: {
            hover: {
                lineWidth: 0
            }
        },
        enableMouseTracking: false
    }, {
        type: 'scatter',
        name: 'Observations',
        data: [1, 1.5, 2.8, 3.5, 3.9, 4.2],
        marker: {
            radius: 4
        }
    }]
});

我试图在散点图的工具提示中隐藏系列名称Observations,但无法使其正常工作。我不知道在哪里放这个代码:

tooltip: {
  formatter: function() {
    return this.x + ', ' + this.y;
  }
}

1 个答案:

答案 0 :(得分:1)

我修改了你的演示并在这里创建了一个新的DEMO

以下是代码:

Highcharts.chart('container', {
    xAxis: {
        min: -0.5,
        max: 5.5
    },
    yAxis: {
        min: 0
    },
    title: {
        text: 'Scatter plot with regression line'
    },
    series: [{
        type: 'line',
        name: 'Regression Line',
        data: [[0, 1.11], [5, 4.51]],
        marker: {
            enabled: false
        },
        states: {
            hover: {
                lineWidth: 0
            }
        },
        enableMouseTracking: false
    }, {
        type: 'scatter',
        name: 'Observations',
        data: [1, 1.5, 2.8, 3.5, 3.9, 4.2],
        marker: {
            radius: 4
        }
    }],
    tooltip: {
      formatter: function() {
       return this.x + ', ' + this.y;
      }
    },
});

Tooltip Documentation供您进一步参考