Google charts display money not interest

Given the data for the pie chart:

data = new google.visualization.arrayToDataTable([ ['Sales', 'Revenue Distribution'], ['Author', 5], ['Company', 2], ['Tax', 0.4], ['Payment Processors', 0.9] ]); drawChart(); 

How can I display it as a dollar amount? Either in the tooltip or on the actual chart itself (both are preferable!)

For example, ideally this would work:

 data = new google.visualization.arrayToDataTable([ ['Sales', 'Revenue Distribution'], ['Author', '$5'], ['Company', '$2'], ['Tax', '$0.4'], ['Payment Processors', '$0.9'] ]); drawChart(); 
+6
source share
1 answer

This is possible, and he will apply it to both the slice and the tooltip. What you need to include is the number of the formatter .

Key points are: Create a chart.

 var formatter = new google.visualization.NumberFormat({ prefix: '$' }); formatter.format(data, 1); var options = { pieSliceText: 'value' }; 

First, a formatter is created and applied to the data, the next parameter then makes the pie chart display the formatted value, not the calculated percentage. You can see how it works in this jsfiddle .

Inspired and adapted with the answer here: Google Graphics Card Processing Software

+14
source

Source: https://habr.com/ru/post/916280/


All Articles