Menu

Gauge label number formatting problem

Mario
2013-04-29
2013-05-22
  • Mario

    Mario - 2013-04-29

    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!

     
  • Shawn Quinn

    Shawn Quinn - 2013-04-29

    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);
    
     
  • Mario

    Mario - 2013-05-06

    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.

     
  • Shawn Quinn

    Shawn Quinn - 2013-05-22

    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.)

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.