Tooltip Formatter Callback Context
See original GitHub issueHi, i am trying to write a custom tooltip formatter. But when i use the options.tooltip.formatter
callback. The this
context inside the formatter callback gets bound to the tooltip and so i cant access my component data.
You can see this issue here: http://plnkr.co/edit/0ZJ29O8YqxvNW5486CDI?p=preview
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:9 (1 by maintainers)
Top Results From Across the Web
tooltip.formatter | highcharts API Reference
Callback function to format the text of the tooltip from scratch. In case of single or shared tooltips, a string should be returned....
Read more >Highcharts tooltip formatter - Stack Overflow
The tooltip formatter function has access to a number of different parameters. Instead of this.x , you could use this.point.name . For example:...
Read more >Tooltip - Chart.js
A tooltip item context is generated for each item that appears in the tooltip. This is the primary model that the callback methods...
Read more >Format tooltip with custom callback function formatter
Description. The following code shows how to format tooltip with custom callback function formatter.
Read more >Timeline | Tooltip Callback | JET Developer Cookbook - Oracle
Tooltip Callback Overview Animations Selection Context Menu Date and Time Formats Discrete Navigation Timeline Custom Time Axis Formatting Custom Timescale ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This has to do with lexical scopes. There is a way how you can solve the issue, and it involves including in the Highchart’s closure a reference to the component’s
this
. Anywhere you like (for instance in thengOninit
lifecycle hook -once the chart object has been initialised-) do something like this:This way you can reference methods, properties, or injected dependencies in the component, as well as the series, point, and any other information from the formatter’s scope.
Bind or Arrow Functions dont solve the problem, as you can see on my provided plunker: the actual value of the hovered datapoint is the
this
context inside the tooltip formatter function. If i use bind or an arrow function, i will set the context to my component and i will lose the datapoint value.