When you have a chart that has missing date values, it would be very
helpful to be able to tell the chart that you want an x axis entry for
every year/month/day/hour/minute/second. Otherwise, when the chart is
drawn, the x axis is misleading.
For example, in the code snippet below, we are missing data for
March. But by looking at the chart, you wouldn't know it; it appears
as if there is no missing data.
I consider this a problem because a key purpose of charts is to
clarify these sorts of things, rather than hide them.
I would like to be able to tell the chart to create an x axis entry
for each month. The result should be a tick for March, with no data
rendered on it.
So far, I have been modifying the underlying data set, but this is
messy and clutters the datatable. In the case where your x axis is a
date or datetime object, it's reasonable for the charts to know how to
do this.
Is this already possible? Or should I create an enhancement request?
// =================================
function drawVisualization() {
// Create and populate the data table.
var data = new google.visualization.DataTable();
var raw_data = [['Austria', 1336060, 1538156, 1576579, 1600652,
1968113, 1901067],
['Belgium', 3817614, 3968305, 4063225, 4604684,
4013653, 6792087],
['Czech Republic', 974066, 928875, 1063414, 940478,
1037079, 1037327],
['Finland', 1104797, 1151983, 1156441, 1167979,
1207029, 1284795],
['France', 6651824, 5940129, 5714009, 6190532,
6420270, 6240921],
['Germany', 15727003, 17356071, 16716049, 18542843,
19564053, 19830493]];
var years = [ new Date(2011,0,1), new Date(2011,1,1), new
Date(2011,3,1),
new Date(2011,4,1), new Date(2011,5,1), new
Date(2011,6,1)];
data.addColumn('date', 'Year');
for (var i = 0; i < raw_data.length; ++i) {
data.addColumn('number', raw_data[i][0]);
}
data.addRows(years.length);
for (var j = 0; j < years.length; ++j) {
data.setValue(j, 0, years[j]);
}
for (var i = 0; i < raw_data.length; ++i) {
for (var j = 1; j < raw_data[i].length; ++j) {
data.setValue(j-1, i+1, raw_data[i][j]);
}
}
// 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"}}
);
}
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-visualization-api?hl=en.