admin管理员组文章数量:1395730
I want to update the tooltip date format dynamically. Like on button click event the tooltip date format will be change to another one. Check out my html:
<div id="container" style="height: 300px"></div>
<button id="dateFormate">changeDateFormat</button>
on Click the button date format chang to %m-%d-%y
Javascript
$(function () {
$('#container').highcharts({
xAxis: {
type: 'datetime'
},
tooltip: {
xDateFormat: '%Y-%m-%d',
shared: true
},
plotOptions: {
series: {
pointStart: Date.UTC(2012, 0, 1),
pointInterval: 24 * 3600 * 1000
}
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}, {
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4].reverse()
}]
});
});
/
I want to update the tooltip date format dynamically. Like on button click event the tooltip date format will be change to another one. Check out my html:
<div id="container" style="height: 300px"></div>
<button id="dateFormate">changeDateFormat</button>
on Click the button date format chang to %m-%d-%y
Javascript
$(function () {
$('#container').highcharts({
xAxis: {
type: 'datetime'
},
tooltip: {
xDateFormat: '%Y-%m-%d',
shared: true
},
plotOptions: {
series: {
pointStart: Date.UTC(2012, 0, 1),
pointInterval: 24 * 3600 * 1000
}
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}, {
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4].reverse()
}]
});
});
http://jsfiddle/hL8ae0yr/
Share Improve this question edited Oct 3, 2015 at 10:53 Davide Pastore 8,73810 gold badges42 silver badges56 bronze badges asked Oct 10, 2014 at 14:10 Ammar Hayder KhanAmmar Hayder Khan 1,3354 gold badges22 silver badges49 bronze badges2 Answers
Reset to default 5You can also define tooltip format in the series, then update a series array with new format.
Example: http://jsfiddle/hL8ae0yr/1/
chart.series[0].update({
tooltip:{
xDateFormat: '%Y/%m/%d',
}
});
This can be done by rebuilding the chart. After the chart has been rendered I cannot find a way to access the chart.tooltip.options to reset. So you can do something like this:
$("#dateFormate").click(function () {
var theChart = $('#container').highcharts();
var initOptions = theChart.options;
var options0 = {
tooltip: {
xDateFormat: '%m-%d-%y'
}
};
optionsNew = Highcharts.merge(initOptions, options0);
$('#container').highcharts(optionsNew);
});
This merges the new tooltip.xDateFormat
with the existing chart options and then recreates the chart.
本文标签: javascriptDynamically update tooltip date format highchartStack Overflow
版权声明:本文标题:javascript - Dynamically update tooltip date format highchart - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744648093a2617518.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论