Google Visualization API堆积图表的工具提示?

时间:2012-04-18 14:25:47

标签: javascript google-visualization

我想在Google Visualization API上的工具提示中添加一些自定义文字。我使用堆积图表来表示百分比,我想为原始数字添加一些额外的值,这些值只会显示在工具提示中,而不会影响图表本身。

这是我目前的代码:

  var dt = new google.visualization.DataTable(
     {
       cols: [{id: 'Year', label: 'year', type: 'string'},
              {id: 'Golf', label: '% time on golf', type: 'number'},
              {id: 'Soccer', label: '% time on soccer', type: 'number'},
             ],
       rows: [{c:[{v: '1996'}, {v: 11}, { v: 10} ]},
              {c:[{v: '1997'}, {v: 2}, { v: 10} ]},
              {c:[{v: '1998'}, {v: 2}, { v: 10} ]},
              {c:[{v: '1999'}, {v:2}, { v: 10} ]},
              {c:[{v: '2000'}, {v:7, f:'7.000'}, { v: 10} ]}
             ]
     },
   0.6
)
  var ac = new google.visualization.AreaChart(document.getElementById('visualization'));
  ac.draw(dt, {
    isStacked: true,
    width: 600,
    height: 400,
    vAxis: {title: "% of time"},
    hAxis: {title: "Year"}
  });

如何添加原始数据和额外的工具提示,以便当我将鼠标悬挂在1996年(比方说)时,它会显示另一个数字?

我希望我可以将行更改为:

rows: [{c:[{v: '1996'}, {v: 11, raw_value: 17}, { v: 10, raw_value: 16} ]},

然后指定工具提示的内容以包含raw_value

1 个答案:

答案 0 :(得分:0)

刚刚找到了我自己的问题的答案,我会在这里写下来以防其他人有同样的问题(以及为了节省其他人的麻烦)。

答案接近我所希望的:在f中使用rows为工具提示提供格式化值。像这样:

rows: [{c:[{v: '1996'}, {v: 11, f: 17}, { v: 10, f: 16} ]},