score:1
Is there any way I can use that function in my tooltip and generate second date in tooltip headerFormat[?]
headerFormat: string
The HTML of the tooltip header line. Variables are enclosed by curly brackets.[...]
As you can see tooltip.headerFormat
only takes strings which are static in nature. Variables like {point.key}
will be handled by search and replace mechanism. So you can not use a function for tooltip.headerFormat
(what a pitty!).
If you want to use a formatter that can handle values dynamically, which means by a callback function you have to use tooltip.formatter:
formatter: Highcharts.TooltipFormatterCallbackFunction
Callback function to format the text of the tooltip from scratch.[...]
As you can see when you try tooltip.formatter
for the first time it seems that you have to rewrite your tooltip code base. But that is probably because you haven't checked your prerequisite enough before starting to write. Also doing this in this answer would be just definitely too much...
The "+5 years"-portion:
var oDate = new Date( point.key );
return (5 + oDate.getFullYear()) + '/' + // add 5 years
(1 + oDate.getMonth()) + '/' + // (January gives 0)
oDate.getDate();
Note: The above is only true for regular years but not every year actually has 365 days
In case you want to also implement leap years in your calculation I recommend a framework like momentjs.com.
score:2
tooltip: {
shared : true,
useHTML : true,
formatter: function() {
var aYearFromNow = new Date(this.x);
aYearFromNow.setFullYear(aYearFromNow.getFullYear() + 5);
var tooltip = '<table><span style="font-size: 16px">'
+ Highcharts.dateFormat('%e/%b/%Y', new Date(this.x)) + ' - '
+ Highcharts.dateFormat('%e/%b/%Y', aYearFromNow)
+ '</span><br/><tbody>';
//loop each point in this.points
$.each(this.points, function(i, point) {
if (point.series.name === 'Observations') {
tooltip += '<tr><th style="font-size: 14px; color: ' + point.series.color
+ '">' + point.series.name + ': </th>'
+ '<td style="font-size: 14px">' + point.y + '℃' + '</td></tr>';
} else if (point.series.name === 'BOXPLOT') {
const x = this.x;
const currentData = this.series.data.find(data => data.x === x);
const boxplotValues = currentData ? currentData.options : {};
tooltip += `<span style="font-size: 14px; color: #aaeeee">
Max: ${boxplotValues.high.toFixed(2)}<br>
Q3: ${boxplotValues.q3.toFixed(2)}<br>
Median: ${boxplotValues.median.toFixed(2)}<br>
Q1: ${boxplotValues.q1.toFixed(2)}<br>
Low: ${boxplotValues.low.toFixed(2)}<br></span>`;
} else {
tooltip += '<tr><th style="font-size: 14px; color: ' + point.series.color
+ '">' + point.series.name + ': </th><td style="font-size: 14px">'
+ point.point.low + '℃ -' + point.point.high + '℃' + '</td></tr>'
+ '</tbody></table>';
}
});
return tooltip;
}
},
Source: stackoverflow.com
Related Query
- How to configure Highcharts tooltip.headerFormat with getDate() + 5
- How to edit tooltip in Highcharts C# code
- how to use highcharts tooltip formatter in python code
- How can I make HighCharts 4.2.5 with boost.js invoke the tooltip formatter?
- How to have multiple highcharts with different series data in vuejs without repeating code
- How to force tooltip to show in multiple graphs in highcharts with Vue 3?
- How to position highcharts tooltip above chart with outside:true
- How to display extra data in highcharts bubble chart tooltip with datetime x-axis
- Highcharts - how to have a chart with dynamic height?
- How to use highcharts with angular 5?
- How to include highcharts with bower?
- how to import highcharts with webpack and babel
- How to prevent highcharts from shortening labels with ellipsis
- How to export the whole page or html content with Highcharts not just the chart?
- Highcharts - How to display legend symbol inside the tooltip
- How To Use Epoch Time With Highcharts Series Data?
- How to get rangeSelector to work with HighCharts
- Highcharts how to remove headers from tooltip
- Highcharts - How to hide series name and Y value in tooltip
- Highcharts : Chart with drilldown how to obtain click event of drill up button
- Highcharts - How to remove connecting line between fixed tooltip and point
- How to use highcharts with princeXML?
- Highcharts - How to remove tooltip arrows
- How to enable or disable a Highcharts tooltip when a button is clicked?
- How to structure Angular with Highcharts and lots of dynamic data
- How to modify Highcharts x-axis tooltip text
- How can I configure the legend with a specific height in highstock?
- Highcharts How to get decimal point values on y-axis with big numbers
- How do I use an Highcharts Solid Gauge in angular 6 with typescript?
- How to hide one series data info in tooltip using highcharts
More Query from same tag
- How to dynamically draw a separator on a pie chart
- Selecting a point programmatically on stockchart from HighCharts library in GWT (Also in native JS)
- Highcharts - How to sort data by name?
- multiple Y axis - margin
- Highchart - xAxis weekly date can start given day?
- Highcharts, no animation when updating number of series in chart
- Highcharts Highmaps the data does not match with polygons correctly
- Highcharts pie color of a part when i click on this
- Highcharts: Creating gantt chart having stacked rows
- Highcharts problem with decimals if there are many data points
- Include hidden series in exported CSV using Highcharts v8.0
- Showing HighCharts in A JQuery Mobile application
- How to hide the context menu on clicking outside uisng JS?
- How to include RSI and Volume in the same chart?
- Graphing data from mysql
- highchart click event Brakedown browser in iphone
- How to make cursor pointer on mouse hover only on a particular PieChart slice?
- How to plot line per category in highcharts?
- How to render a vertical line when the mouse cursor is on the chart using highcharts?
- How to display highchart series line marker symbol from tooltip formatter?
- Highcharts add series, data format
- how can i add popup to flags in highchart?
- highcharts waterfall not summing correctly
- Highcharts: print chart without designated button
- Highchart: drawgraph based on chart name
- How to read data from in Javascript
- how to use high chart when number of lines are dynamic
- highcharts not loading in tabs
- Highcharts custom symbol
- Javascript - Highcharts - input data array of arrays