Gauge Chart - How to format the legend value

620 views
Skip to first unread message

Bevan

unread,
Sep 28, 2014, 9:32:37 PM9/28/14
to google-visua...@googlegroups.com
Hello,

I have the following:
<script type="text/javascript">
      google.load("visualization", "1", {packages:["gauge"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
var sales = @todaySales;
var dayTarget = @dailyTarget;
var apdTarget = 22500;
        var data = google.visualization.arrayToDataTable([
          ['Label', 'Value'],
          ['Today', sales],           
        ]);
        var options = {
          width: 400, height: 400,
 redFrom: 0, redTo: apdTarget,
 greenFrom: apdTarget, greenTo: dayTarget,
          minorTicks: 5, max: dayTarget
        };
        var chart = new google.visualization.Gauge(document.getElementById('daily_Sales'));
        chart.draw(data, options);
      };
Now, I want to format the value to a currency, $12.34. 

The variable 'sales' is a numerical value to 10 decimal places extracted from an SQL database with aspx prior to this gauge code, declared as @todaySales

I want to format the label and tried this:
           ['Label', 'Value'],
          ['Today', {v: sales, f: 'C']]        
uh, No.

What can I do?

Sergey Grabkovsky

unread,
Sep 29, 2014, 10:06:28 AM9/29/14
to google-visua...@googlegroups.com
Hi Bevan, you were on the right track. You just need to specify the full string value that you want to show up. I'm not sure what "C" was supposed to mean in your context, but that would just make the letter "C" show up instead of your value. You'd need to specify it as "$12.34". Here's an example of how to do that: http://jsfiddle.net/u1bgkq66/

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

Bevan

unread,
Sep 30, 2014, 7:07:42 PM9/30/14
to google-visua...@googlegroups.com
Ok, but this just gives me exactly that - the figure $12.34 instead of the actual value of the pointer.

Sergey Grabkovsky

unread,
Oct 1, 2014, 9:45:23 AM10/1/14
to google-visua...@googlegroups.com
I'm not sure what you mean by "the actual value of the pointer". You will have to specify a different string for every datum. Or you could use the NumberFormat to do this automatically for every datum: https://developers.google.com/chart/interactive/docs/reference?hl=ja#numberformatter

--
Reply all
Reply to author
Forward
0 new messages