谷歌图表工具提示百分比

时间:2014-05-12 20:01:16

标签: tooltip google-visualization

我的图表很简单,就像这样:

function drawVisualization() {

  var data = google.visualization.arrayToDataTable([
    ['week', 'rate'],
    ['1',   0.156],
    ['2',   0.232],
    ['3',   0.446],
    ['4',   0.832],
    ['5',   0.702],
    ['6',   0.773],
    ['7',   0.842],
    ['8',   0.413],
    ['9',   0.278],
    ['10',   0.323],
    ['11',   0.312],
    ['12',   0.309],
    ['13',   0.134],
    ['14',   0.137]
  ]);

  new google.visualization.LineChart(document.getElementById('visualization')).
      draw(data, {curveType: "function",
                  width: 500, height: 400,
                  vAxis: {maxValue: 1}}
          );
}

但我没有IDEA如何格式化数据列以在工具提示中显示为一个百分比。你们能帮忙吗?

2 个答案:

答案 0 :(得分:3)

使用NumberFormatter:

var formatter = new google.visualization.NumberFormat({pattern: '#%'});
formatter.format(data, 1); // format column 1

您可能还想格式化y轴:

vAxis: {
    maxValue: 1,
    format: '#%'
}

答案 1 :(得分:0)

Add a column like this

{role: 'tooltip'}

I had the same problem and fixed it.

See for yourself!