2012-05-21 10 views
19

El siguiente ejemplo es de Google para crear un ColumnChart usando Google Charts¿Error de la carta de Google? El eje no a partir de 0

function drawVisualization() { 
// Create and populate the data table. 
var data = google.visualization.arrayToDataTable([ 
['Year', 'Austria', 'Belgium', 'Czech Republic', 'Finland', 'France', 'Germany'], 
['2003', 1336060, 3817614,  974066,  1104797, 6651824, 15727003], 
['2004', 1538156, 3968305,  928875,  1151983, 5940129, 17356071], 
['2005', 1576579, 4063225,  1063414,  1156441, 5714009, 16716049], 
['2006', 1600652, 4604684,  940478,  1167979, 6190532, 18542843], 
['2007', 1968113, 4013653,  1037079,  1207029, 6420270, 19564053], 
['2008', 1901067, 6792087,  1037327,  1284795, 6240921, 19830493] 
]); 

// Create and draw the visualization. 
new google.visualization.ColumnChart(document.getElementById('visualization')). 
    draw(data, 
     {title:"Yearly Coffee Consumption by Country", 
     width:600, height:400, 
     hAxis: {title: "Year"}} 
); 
} 

que trabaja perfectamente, sin embargo, sólo quiero un valor por columna para lo cambio a:

function drawVisualization() { 
// Create and populate the data table. 
var data = google.visualization.arrayToDataTable([ 
['Month', 'How many'], 
['07', 193], 
['08', 114], 
['09', 158] 
]); 

// Create and draw the visualization. 
new google.visualization.ColumnChart(document.getElementById('visualization')). 
    draw(data, 
     {title:"Yearly Coffee Consumption by Country", 
     width:600, height:400, 
     hAxis: {title: "Year"}} 
); 
} 

Y ahora el eje vertical no comienza en 0, pero está cerca del valor más bajo, en este caso 114 - ¿es esto un error? Todavía quiero que se muestre desde 0, ya que es muy confuso en un vistazo rápido como este

¿Alguna idea?

+0

Sólo he dado cuenta de este comportamiento en los gráficos de columnas combinado (febrero '16) – roberthuttinger

Respuesta

15

Si usted no tiene los datos en el gráfico vAxis: {minValue: 0} no será de ayuda. Así opción de configuración viewWindow puede utilizar:

var options = { 
    vAxis: { 
     viewWindow: { 
      min:0 
     } 
    } 
}; 
var chart = new google.visualization.ComboChart(document.getElementById('chart_div')); 
chart.draw(dataTable, options); 
+1

Para la nueva API esta es la respuesta correcta – rents

Cuestiones relacionadas