我使用 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;
}
}
关键是要有一个工具提示格式化程序函数,它只返回this.x + ', ' + this.y
。
有关参考,请参阅工具提示文档。下面的演示。
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;
}
},
});
<html>
<body>
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container"></div>
</body>
</html>