以编程方式格式化谷歌图表

发布于 2024-12-03 00:35:54 字数 645 浏览 1 评论 0原文

使用以下代码如何设置格式,以便CurrencyValue1和CurrencyValue2在图表中显示为美元(作为货币值)?

function drawChart() {
    var data = new google.visualization.DataTable();
    data.addColumn('date', 'Date');
    data.addColumn('number', 'CurrencyValue1');
    data.addColumn('number', 'CurrencyValue2');

    data.addRows(1);
    data.setValue(0, 0, new Date(2011, 8, 12));
    data.setValue(0, 1, 300.0000);
    data.setValue(0, 2, 759.1707);

    var chart = new google.visualization.LineChart(document.getElementById('chart_div'));

    chart.draw(data, { width: 660, height: 470, title: 'Heading', is3D: true, backgroundColor: '#f5f3e5' });
}

Using the following code how can I set the formatting so that CurrencyValue1 and CurrencyValue2 is shown with a dollar (as a currency value) in the chart?

function drawChart() {
    var data = new google.visualization.DataTable();
    data.addColumn('date', 'Date');
    data.addColumn('number', 'CurrencyValue1');
    data.addColumn('number', 'CurrencyValue2');

    data.addRows(1);
    data.setValue(0, 0, new Date(2011, 8, 12));
    data.setValue(0, 1, 300.0000);
    data.setValue(0, 2, 759.1707);

    var chart = new google.visualization.LineChart(document.getElementById('chart_div'));

    chart.draw(data, { width: 660, height: 470, title: 'Heading', is3D: true, backgroundColor: '#f5f3e5' });
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

屋檐 2024-12-10 00:35:54

请参阅文档:http://code.google.com/intl /cs-CZ/apis/chart/interactive/docs/reference.html#numberformatter

var data = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addColumn('number', 'CurrencyValue1');
data.addColumn('number', 'CurrencyValue2');

var formatter = new google.visualization.NumberFormat(
      {prefix: '

这会将第二列和第三列的格式设置为金钱(以美元符号为前缀,如“$15.00”)

, negativeColor: 'red', negativeParens: true}); formatter.format(data, 1); formatter.format(data, 2);

这会将第二列和第三列的格式设置为金钱(以美元符号为前缀,如“$15.00”)

see documentation: http://code.google.com/intl/cs-CZ/apis/chart/interactive/docs/reference.html#numberformatter

var data = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addColumn('number', 'CurrencyValue1');
data.addColumn('number', 'CurrencyValue2');

var formatter = new google.visualization.NumberFormat(
      {prefix: '

This will format columns two and three like money (prefixed with dollar sign like "$15.00")

, negativeColor: 'red', negativeParens: true}); formatter.format(data, 1); formatter.format(data, 2);

This will format columns two and three like money (prefixed with dollar sign like "$15.00")

简单 2024-12-10 00:35:54

这是巴西货币的完美格式:

  var formatter = new google.visualization.NumberFormat({decimalSymbol: ',',groupingSymbol: '.', negativeColor: 'red', negativeParens: true, prefix: 'R$ '});
  formatter.format(data, 1);

也适用于美元,有些将 R$ 更改为 $

10500.5 保留 10.500,50,更多前缀

10500 留在 10.500,00,更多前缀

This is perfect format to Brazilian currency:

  var formatter = new google.visualization.NumberFormat({decimalSymbol: ',',groupingSymbol: '.', negativeColor: 'red', negativeParens: true, prefix: 'R$ '});
  formatter.format(data, 1);

Works fine whit dollar also, some change the R$ to $

10500.5 stay 10.500,50, more prefix

10500 stay 10.500,00, more prefix

伴随着你 2024-12-10 00:35:54

使用 Data.SetFormattedValue 并更改 3# 参数。

像这样:

For i As Integer = 0 To dt.Rows.Count - 1
....

   str.Append("data.setValue( " & i & "," & 0 & "," & "'" & Cadena & "');")
   str.Append("data.setValue(" & i & "," & 1 & "," & Valor & ") ;")
    str.Append("data.setFormattedValue(" & i & "," & 1 & ",'" &  FormatCurrency(Valor.Replace(".", ",")) & "') ;")
next 

Use Data.SetFormattedValue and change 3# param.

Like this:

For i As Integer = 0 To dt.Rows.Count - 1
....

   str.Append("data.setValue( " & i & "," & 0 & "," & "'" & Cadena & "');")
   str.Append("data.setValue(" & i & "," & 1 & "," & Valor & ") ;")
    str.Append("data.setFormattedValue(" & i & "," & 1 & ",'" &  FormatCurrency(Valor.Replace(".", ",")) & "') ;")
next 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文