0

如何在悬停时将数据显示为百分比?我可以让网格线显示百分比,但悬停总是显示未格式化的数据:1vs 100%

图表

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);
4

1 回答 1

1

想通了:你必须使用工具提示“数据角色”

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 + '%']
]);
于 2012-08-01T22:58:32.967 回答