在 Highstocks 中,将鼠标悬停在图表上时如何更改默认的 time/day 标签?
In Highstocks, how do I change the default time/day labels when hovering over graph?
我已经设法使用格式化程序函数更改了 highcharts/highstocks 中的默认 x-axis 标签,但是尽管查看了 API 我还是不知道如何更改 on-hover 标题(示例:当我将鼠标悬停在图中 'Mark' 的列上时,它显示 'Thursday ..' 以及 Mark 的正确值。但我希望它的标题为 'Mark',以及价值)。我该如何改变这个? (我想使用 highstocks(而不是 highcharts),因为我的数据比展示的多得多)
<html>
<body>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/stock/highstock.js"></script>
<script src="http://code.highcharts.com/modules/data.js"></script>
<div id="container"></div>
</body>
<head>
<script type="text/javascript">
var newLabels = ['Marky', 'Ricky', 'Danny', 'Terry', 'Mikey'];
$('#container').highcharts('StockChart', {
chart: {
type: 'column'
},
credits: {
enabled: false
},
xAxis: {
categories: ['Marky', 'Ricky', 'Danny', 'Terry', 'Mikey'],
labels: {
rotation: -45,
formatter: function() {
return newLabels[this.value];
}},
},
title: {
text: 'Anything But the Index'
},
series: [
{name: '1',data:[0.067028837967,0.0,0.0]},
{name: '1a',data:[0.187515270425,0.18818380744,0.0857142857143]},
{name: '1b',data:[0.31600895865,0.0,0.169987200178,0.399354014733,0.0873578570502]},
{name: '2',data:[0.0,0.0,0.0,0.0,1.0]},
{name: '3',data:[0.998898678414,1.0,1.0,0.998898678414,1.0]},
{name: '4',data:[0.0,0.0,0.0,0.0,0.3]},
{name: '6',data:[0.505930477918,0.0,0.190192368338,0.597371635879,0.285892370193]},
],
scrollbar: {
enabled: true,
},
navigator: {
series: {
type: 'areaspline',
}},
rangeSelector: {
enabled:false,
},
});
</script>
</head>
<div id="container" style="height: 400px; min-width: 310px"></div>
</html>
您想自定义工具提示吗?这是怎么做的。
https://jsfiddle.net/yfgpg5x2/12/
tooltip: {
formatter: function() {
var curTickLabelString = this.points[0].series.xAxis.ticks[this.x].label.textStr;
var tooltipString = "<b>" + curTickLabelString + ":<br></b>";
var curName, curValue, curColor, curGraphic;
for (var i = 0; i < this.points.length; i++) {
curName = this.points[i].series.name;
curValue = this.points[i].y;
curColor = this.points[i].color;
curGraphic = '●';
tooltipString += '<br>'+ curGraphic +' <b style="color: ' + curColor + '">' + curName + ':</b> ' + curValue;
}
return tooltipString;
}
},
在此处阅读有关工具提示的更多信息:
我已经设法使用格式化程序函数更改了 highcharts/highstocks 中的默认 x-axis 标签,但是尽管查看了 API 我还是不知道如何更改 on-hover 标题(示例:当我将鼠标悬停在图中 'Mark' 的列上时,它显示 'Thursday ..' 以及 Mark 的正确值。但我希望它的标题为 'Mark',以及价值)。我该如何改变这个? (我想使用 highstocks(而不是 highcharts),因为我的数据比展示的多得多)
<html>
<body>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/stock/highstock.js"></script>
<script src="http://code.highcharts.com/modules/data.js"></script>
<div id="container"></div>
</body>
<head>
<script type="text/javascript">
var newLabels = ['Marky', 'Ricky', 'Danny', 'Terry', 'Mikey'];
$('#container').highcharts('StockChart', {
chart: {
type: 'column'
},
credits: {
enabled: false
},
xAxis: {
categories: ['Marky', 'Ricky', 'Danny', 'Terry', 'Mikey'],
labels: {
rotation: -45,
formatter: function() {
return newLabels[this.value];
}},
},
title: {
text: 'Anything But the Index'
},
series: [
{name: '1',data:[0.067028837967,0.0,0.0]},
{name: '1a',data:[0.187515270425,0.18818380744,0.0857142857143]},
{name: '1b',data:[0.31600895865,0.0,0.169987200178,0.399354014733,0.0873578570502]},
{name: '2',data:[0.0,0.0,0.0,0.0,1.0]},
{name: '3',data:[0.998898678414,1.0,1.0,0.998898678414,1.0]},
{name: '4',data:[0.0,0.0,0.0,0.0,0.3]},
{name: '6',data:[0.505930477918,0.0,0.190192368338,0.597371635879,0.285892370193]},
],
scrollbar: {
enabled: true,
},
navigator: {
series: {
type: 'areaspline',
}},
rangeSelector: {
enabled:false,
},
});
</script>
</head>
<div id="container" style="height: 400px; min-width: 310px"></div>
</html>
您想自定义工具提示吗?这是怎么做的。
https://jsfiddle.net/yfgpg5x2/12/
tooltip: {
formatter: function() {
var curTickLabelString = this.points[0].series.xAxis.ticks[this.x].label.textStr;
var tooltipString = "<b>" + curTickLabelString + ":<br></b>";
var curName, curValue, curColor, curGraphic;
for (var i = 0; i < this.points.length; i++) {
curName = this.points[i].series.name;
curValue = this.points[i].y;
curColor = this.points[i].color;
curGraphic = '●';
tooltipString += '<br>'+ curGraphic +' <b style="color: ' + curColor + '">' + curName + ':</b> ' + curValue;
}
return tooltipString;
}
},
在此处阅读有关工具提示的更多信息: