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.