Highcharts Highstock 如何更改 OHLC 系列数据工具提示顶部的标签?
Highcharts Highstock How do I change the label on top of tooltip for OHLC series data?
问题
运行 下面的片段在 Firefox 浏览器中,顶部的工具提示标签是“打开”。如何用新标签“已调整”替换顶部工具提示标签“打开”?
这是原始代码段中的csv数据:
<pre id="csv" style="display: none">
date,open,high,low,close
2006-05-20, 63.26, 64.88, 62.82, 64.51
2006-05-22, 63.87, 63.99, 62.77, 63.38
</pre>
强制解
在代码片段中,我可以通过将 CSV header“open”替换为名称“Adjust”来强制获得所需结果,如下所示:
<pre id="csv" style="display: none">
date,Adjust,high,low,close
2006-05-20, 63.26, 64.88, 62.82, 64.51
2006-05-22, 63.87, 63.99, 62.77, 63.38
</pre>
不过,我更喜欢更改工具提示中的名称,而不是更改 CSV 中的 header,因此我不认为这是已批准的解决方案。
片段
<html>
<head>
<title>
AAPL Combined OHLC and Moving Average
</title>
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
</head>
<body>
<div id="chart-container" style="width: 100%; height: 100%; margin: 0 auto"></div>
<pre id="csv" style="display: none">
date,open,high,low,close
2006-05-20, 63.26, 64.88, 62.82, 64.51
2006-05-22, 63.87, 63.99, 62.77, 63.38
2006-05-23, 64.86, 65.19, 63.00, 63.15
2006-05-24, 62.99, 63.65, 61.56, 63.34
2006-05-25, 64.26, 64.45, 63.29, 64.33
2006-05-26, 64.31, 64.56, 63.14, 63.55
2006-05-30, 63.29, 63.30, 61.22, 61.22
2006-05-31, 61.76, 61.79, 58.69, 59.77
</pre>
<script type="text/javascript">
Highcharts.stockChart('chart-container', {
rangeSelector: {
selected: 2
},
title: {
text: 'AAPL Stock Price'
},
plotOptions: {
series: {
turboThreshold: 0
},
ohlc: {
color: 'black',
tooltip: {
// pointFormat: 'Adjusted'
}
}
},
data: {
csv: document.getElementById('csv').innerHTML,
seriesMapping: [{
x: 0,
open: 1,
high: 2,
low: 3,
close: 4
}]
},
series: [{
type: 'ohlc', // bars
visible: true,
// set color in plotOptions
tooltip: {
// pointFormat: 'Adjusted'
}
}]
});
</script>
</body>
</html>
如果我取消注释一个或两个 pointFormat 语句(在上面显示的工具提示选项中),那么工具提示中将不再显示开盘价、最高价、最低价和收盘价数据 pop-up。相反,工具提示中只会出现“已调整”一词。
设置系列名称,禁用firstRowAsNames
属性并在数据选项中将startRow
设置为1:
data: {
firstRowAsNames: false,
startRow: 1,
...
},
series: [{
name: 'Adjust',
...
}]
现场演示: http://jsfiddle.net/BlackLabel/fkh0oa2s/
API参考:
问题
运行 下面的片段在 Firefox 浏览器中,顶部的工具提示标签是“打开”。如何用新标签“已调整”替换顶部工具提示标签“打开”?
这是原始代码段中的csv数据:
<pre id="csv" style="display: none">
date,open,high,low,close
2006-05-20, 63.26, 64.88, 62.82, 64.51
2006-05-22, 63.87, 63.99, 62.77, 63.38
</pre>
强制解
在代码片段中,我可以通过将 CSV header“open”替换为名称“Adjust”来强制获得所需结果,如下所示:
<pre id="csv" style="display: none">
date,Adjust,high,low,close
2006-05-20, 63.26, 64.88, 62.82, 64.51
2006-05-22, 63.87, 63.99, 62.77, 63.38
</pre>
不过,我更喜欢更改工具提示中的名称,而不是更改 CSV 中的 header,因此我不认为这是已批准的解决方案。
片段
<html>
<head>
<title>
AAPL Combined OHLC and Moving Average
</title>
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
</head>
<body>
<div id="chart-container" style="width: 100%; height: 100%; margin: 0 auto"></div>
<pre id="csv" style="display: none">
date,open,high,low,close
2006-05-20, 63.26, 64.88, 62.82, 64.51
2006-05-22, 63.87, 63.99, 62.77, 63.38
2006-05-23, 64.86, 65.19, 63.00, 63.15
2006-05-24, 62.99, 63.65, 61.56, 63.34
2006-05-25, 64.26, 64.45, 63.29, 64.33
2006-05-26, 64.31, 64.56, 63.14, 63.55
2006-05-30, 63.29, 63.30, 61.22, 61.22
2006-05-31, 61.76, 61.79, 58.69, 59.77
</pre>
<script type="text/javascript">
Highcharts.stockChart('chart-container', {
rangeSelector: {
selected: 2
},
title: {
text: 'AAPL Stock Price'
},
plotOptions: {
series: {
turboThreshold: 0
},
ohlc: {
color: 'black',
tooltip: {
// pointFormat: 'Adjusted'
}
}
},
data: {
csv: document.getElementById('csv').innerHTML,
seriesMapping: [{
x: 0,
open: 1,
high: 2,
low: 3,
close: 4
}]
},
series: [{
type: 'ohlc', // bars
visible: true,
// set color in plotOptions
tooltip: {
// pointFormat: 'Adjusted'
}
}]
});
</script>
</body>
</html>
如果我取消注释一个或两个 pointFormat 语句(在上面显示的工具提示选项中),那么工具提示中将不再显示开盘价、最高价、最低价和收盘价数据 pop-up。相反,工具提示中只会出现“已调整”一词。
设置系列名称,禁用firstRowAsNames
属性并在数据选项中将startRow
设置为1:
data: {
firstRowAsNames: false,
startRow: 1,
...
},
series: [{
name: 'Adjust',
...
}]
现场演示: http://jsfiddle.net/BlackLabel/fkh0oa2s/
API参考: