谷歌折线图:如何添加单位?

Ben*_*Ben 7 google-visualization

https://google-developers.appspot.com/chart/interactive/docs/gallery/linechart#Example

如何将单位添加到垂直轴,如"$"或"€"?在示例中,它应该是1.200 $,1.000 $,800 $,600 $和400 $.

只是像这样添加'$'不起作用:

var data = google.visualization.arrayToDataTable([
      ['Year', 'Sales', 'Expenses'],
      ['2004',  1000 '$',      400],
      ['2005',  1170 '$',      460],
      ['2006',  660 '$',       1120],
      ['2007',  1030 '$',      540]
    ]);
Run Code Online (Sandbox Code Playgroud)

我知道,这是一个糟糕的例子,因为销售没有任何单位,但这只是一个例子.

小智 17

您需要在图表选项中添加格式标记,如下所示:

var options = {
    vAxis: {format:'# $'}
};
Run Code Online (Sandbox Code Playgroud)

参考:https://google-developers.appspot.com/chart/interactive/docs/gallery/linechart#Configuration_Options

  • 大!非常感谢你!您是否也知道如何将此格式标签应用于工具提示? (2认同)