Only way I made it work was by using a javascript formatter:
chart.setOption("plotOptions/gauge/dataLabels/formatter", getGaugeLabelFormatter());
private native JavaScriptObject getGaugeLabelFormatter() /-{
return function() {
return '' + this.y.toFixed(2) + ' ';
}
}-/;
Thanks for the help in advance!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I haven't mess around with gauge formatters myself, but note that I believe your first example is just going into the configuration options as a string. In order to have something pass through the system as JSON, you'll need to set it up as a JSONObject instead. E.g.
JSONObject options = new JSONObject();
options.put("thing", new JSONString("value"));
chart.setOption("x/y/z", options);
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry, I got thrown off by your JSON looking "{this.y:.2f}" syntax in your original post. I see now that you were trying to utilize one of Highchart's newer format strings, in which case the string format you were using is correct. Haven't tried it myself, but I'm guessing what you probably may want is something like "{point.y:.2f}" or just ""{y:.2f}" instead though. More details here:
(Also note that you'll need to be including the Highcharts 3.0 javascript library in order to make use of the new "plotOptions/gauge/dataLabels/format" option.)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I am having problems with formatting the numbers in gauge labels. This is the code, but it does not work.
chart.setOption("plotOptions/gauge/dataLabels/enabled", true);
chart.setOption("plotOptions/gauge/dataLabels/format", "{this.y:.2f}");
Only way I made it work was by using a javascript formatter:
chart.setOption("plotOptions/gauge/dataLabels/formatter", getGaugeLabelFormatter());
private native JavaScriptObject getGaugeLabelFormatter() /-{
return function() {
return '' + this.y.toFixed(2) + '
';
}
}-/;
Thanks for the help in advance!
I haven't mess around with gauge formatters myself, but note that I believe your first example is just going into the configuration options as a string. In order to have something pass through the system as JSON, you'll need to set it up as a JSONObject instead. E.g.
Hi Shawn,
I am not sure what do you mean by the code above?
What is "thing" supposed to represent?
Although, I did try some things with JSONObject, but no luck.
Thank's for the suggestion.
Sorry, I got thrown off by your JSON looking "{this.y:.2f}" syntax in your original post. I see now that you were trying to utilize one of Highchart's newer format strings, in which case the string format you were using is correct. Haven't tried it myself, but I'm guessing what you probably may want is something like "{point.y:.2f}" or just ""{y:.2f}" instead though. More details here:
http://docs.highcharts.com/#formatting
(Also note that you'll need to be including the Highcharts 3.0 javascript library in order to make use of the new "plotOptions/gauge/dataLabels/format" option.)