question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

formatter callback function, how to do it?

See original GitHub issue

Based on my limited experience, it looks like most of work for create a highchart is about specifying the config object (which by itself is pretty powerful). But I haven’t figured out a way to write formatter callback function. Obviously I can’t access the chart data with this.y. What would be the right way to define my own formatter function?

Thanks.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
realbuggercommented, Apr 6, 2016

@kirjs you’re right. All I need is to pass it as part of the config object. Actually that’s the first thing I did. However, it turned out that I mistakenly used ES6 arrow function to define formatter callback function, where this means differently than defining it with function keyword.

This was how I did it initially.

...
// Wrong. 'this' here refers to the current react component, this.y is undefined
formatter: () => this.y + ' %' 
...

Once I change to the vanilla function definition, problem solved.

...
// Correct. 'this' here refers to the data point 
formatter: function() {return this.y + ' %';} 
...

I never paid much attention to the nuance of arrow function. Now lessons learned. Closing the thread.

0reactions
keithdmoorecommented, Apr 19, 2018

For anybody using TypeScript, here is the solution:

tooltip: {
   formatter: function() {
       var self: any = this;
       return self.point.category; 
   }               
},
Read more comments on GitHub >

github_iconTop Results From Across the Web

Formatter Callback Functions - Philipp Salvisberg's Blog
An Arbori query can return multiple columns and multiple rows. A tuple contains the columns of a single row. Therefore, a callback function...
Read more >
Format tooltip with custom callback function formatter
The following code shows how to format tooltip with custom callback function formatter. Example. <!DOCTYPE html> <html> ...
Read more >
Setting formatter callback using highcharts-convert.js
I tried putting the formatter function outside the definition of the callback, but highcharts-convert.js won't accept that. How do I set a dataLabel ......
Read more >
tooltip.formatter | highcharts API Reference
Point> A callback function for formatting the HTML output for a single point in the tooltip. Like the pointFormat string, but with more...
Read more >
setFormatter() – Set Formatter Callback - PHP
Define a formatting callback function with optional arguments for this column. ... 'record' => associative array of all fields values for this record,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found