Fill in missing dates on charts

4,036 views
Skip to first unread message

NA

unread,
Aug 15, 2011, 10:12:03 AM8/15/11
to Google Visualization API
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"}}
);
}

asgallant

unread,
Aug 15, 2011, 10:16:16 AM8/15/11
to google-visua...@googlegroups.com
Try adding a date for your missing values, but set the data points for that date to null; that will give you a chart with a hole in it on that date.

NA

unread,
Aug 15, 2011, 2:02:00 PM8/15/11
to Google Visualization API
Thanks, but I knew that :) I wanted to see if there's a way to avoid
doing this. ... I realize that sounds lazy, but it's really not ;)

I think this is something that the charts should be able to do on
their own, without my having to modify the underlying data table. They
should be able to detect that the x axis values are date or datetime
objects, and ultimately I should be able to suggest something like
{xTicksEvery:'day'} to get the axis to automatically add in the
missing days (or hours, or minutes, or whatever).

The problem with adding a date for my missing values is that I now am
altering the underlying data set. What may have been a sparse table
is now filled in with nulls. Any logic that was based on the number
of rows being equal to the number of observations needs to be
rewritten. Related to this, any aggregations that used *.count now
need to use a custom aggregation function that ignores null entries.

It's not the end of the world, but I do believe that the charts should
be able to do this themselves, without my having to add the missing
date values. It would make things a lot cleaner.

Looks like I'll need to put in an enhancement request.

And thanks for the suggestion, though; I do appreciate the tips you've
given me and others on here.

Jinji

unread,
Aug 16, 2011, 12:51:11 PM8/16/11
to google-visua...@googlegroups.com
What you're suggesting isn't supported yet, but we hear you...


--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.


NA

unread,
Aug 17, 2011, 10:20:41 AM8/17/11
to Google Visualization API
Thanks for listening ;) Any plans for putting this in an upcoming
release? It could be backwards compatible by appearing as an option
that has a default of "null", so that the current no-fill spacing is
used.



Jinji

unread,
Aug 17, 2011, 11:33:16 AM8/17/11
to google-visua...@googlegroups.com
Sorry, but we can't speak of future plans. Specifically regarding the upcoming release, I'm afraid it won't include this feature.




--

NA

unread,
Aug 17, 2011, 1:21:10 PM8/17/11
to Google Visualization API
Why aren't you willing to speak about future plans? The unwillingness
to let customers know where you're heading makes it difficult to work
with your product.

In fact, you'd think that your product manager would want to share
this information with his clients. Instead, you seem to be very
secretive and don't even put out release notes or even announce when
an update is pushed.

What's the reason for being so secret? You have a good product, but
stand out in how difficult you've made yourselves to work with!

Khubetov Dmitry

unread,
Aug 22, 2011, 1:31:07 PM8/22/11
to Google Visualization API
Agree with Jinji
This solution is already ambaded into "Scatter Chart"
The only You need is to connect the dots. No?

NA

unread,
Aug 23, 2011, 7:46:56 AM8/23/11
to Google Visualization API
I'm not sure what you are agreeing with.

There is a workaround - I've been using it for a few months now. But
this is a deficiency in the charts. If the x-axis were a "category"
axis, this would be fine. But in the case where the x-axis is a date
(or any other numerical axis), this behavior distorts the appearance
of the charts and is very much a bug. Jinji has agreed so, but hasn't
indicated when this will be fixed.

And that's my second question - why isn't the GVIZ team willing to
speak of their plans for the product? I've never seen a product
management team so secretive about their tools. Some "haziness" is
natural when identifying release dates, but the GVIZ team won't even
comment the slightest amount. Along with the various other problems
pointed out in these threads, it adds to the perception that this
isn't a real product, but just another beta that Google shares ...

Reply all
Reply to author
Forward
0 new messages