rxmnnxfpvg
rxmnnxfpvg

Reputation: 31033

Google Visualization API: Column Chart %

How do I get data displayed as a percentage on hover? I can get the gridlines to show percentages, but the hover always shows unformatted data: 1 vs 100%.

chart

var data = google.visualization.arrayToDataTable([
        ['Who', 'Percentage'],
        ['Unlike Me', 0],
        ['Like Me', 1]
    ]);
var options = {
      vAxis: { format:'#%'}, // Makes gridlines have percentages (correct)
      format: '#%' // Does nothing
};

var div = $('#graph').get([0]);
var chart = new google.visualization.ColumnChart(div);
chart.draw(data, options);

Upvotes: 0

Views: 1983

Answers (1)

rxmnnxfpvg
rxmnnxfpvg

Reputation: 31033

Figured it out: you have to use tooltip "data roles":

data.addColumn('string', 'Who'); // Implicit domain column.
data.addColumn('number', 'Percentage'); // Implicit data column.
data.addColumn({type:'string', role:'tooltip'}); // Tooltip with percentages 
data.addRows([
    ['Like Me', 0, 0 * 100 + '%'],
    ['Unlike Me', 1, 1 * 100 + '%']
]);

Upvotes: 1

Related Questions