0

We recently purchased a highcharts license and have integrated it with our Grails application.

We're having some difficulty in that we're unable to specify a tool tip formatter in the JSON object that we're returning because it appears that the HighCharts JSON object doesn't conform to the JSON standards.

Specifically, it appears that JSON is not technically allowed to have JavaScript functions as an object property. From the www.json.org website:

A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. A character is represented as a single character string. A string is very much like a C or Java string.

So, when we output our formatting string, it gets wrapped in double quotes, like this:

"formatter": "this.x + ': ' + this.y",

Can we get an enhancement where we specify a tooltip (or tooltip-fn) property as a string, which is the name of a javascript function? For example:

"formatter": "myTooltipFn"

which calls a javascript function like:

myTooltipFn(chart) {
   return chart.x
}
  • there is a grails tooltip plugin http://grails.org/plugin/tooltip - easy to install – Rachel Gallen May 23 '13 at 20:13
  • this is the javascript http://searchco.de/codesearch/view/25243892 – Rachel Gallen May 23 '13 at 20:15
  • [This](http://stackoverflow.com/questions/2001449/is-it-valid-to-define-functions-in-json-results) may be helpful. In general you can pass function as string and then use eval on that string to get function. – Paweł Fus May 24 '13 at 14:15

1 Answers1

0

I've just fixed this after hours of labour. My solution was to add the formatter to the data AFTER the data is sent in JSON format to the browser.

So basically, in the js file that has this line:

$(blah).highcharts(data);

write BEFORE this line:

Data.tooltip.formatter = function() {
    //write function here
}
Luís Cruz
  • 14,780
  • 16
  • 68
  • 100