2011-09-04 13 views
9

Utilizando el siguiente código, ¿cómo puedo configurar el formato para que CurrencyValue1 y CurrencyValue2 se muestren con un dólar (como valor de moneda) en el gráfico? documentaciónFormateo de gráficos de Google mediante programación

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' }); 
} 

Respuesta

19

véase: 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: '$', negativeColor: 'red', negativeParens: true}); 
formatter.format(data, 1); 
formatter.format(data, 2); 

Esto dará formato a las columnas dos y tres como el dinero (el prefijo de signo de dólar como "$ 15.00")

+2

Gracias, eres un arma ... –

0

Uso Data.SetFormattedValue y cambiar 3 # PARAM .

De esta manera:

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 
2

Este es el formato perfecto para la moneda brasileña:

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

Works dólar whit bien también, algunos cambian la R$ a $

10500.5 estancia 10.500,50, más prefijo

10500 estancia 10.500,00, más prefijo

Cuestiones relacionadas