Setting Column Property to 'numeric' ?

115 views
Skip to first unread message

Ken Burkhalter

unread,
Dec 20, 2014, 9:54:37 AM12/20/14
to google-visua...@googlegroups.com
My Line Chart input data comes from a csv file with data for 11 columns (x-axis and 10 series).

It is possible, at times, for one, or more, of the csv lines to contain all null data vales, in which case Charting fails with an All series on a given axis must be of the same data type  error comment.

I can stop this by always writing an initial line into the csv file with (11) zeroes [0,0,0,0,0,0,0,0,0,0,0] but that messes up the chart appearance.

I thought it possible to cure this by using the setColumnProperty Method to define all columns as numeric (which is true of all the data).  That is...

var data = new google.visualization.arrayToDataTable(arrayData);
   
// Set chart options
 data
.setColumnProperty (0, 'type', 'number');
 data
.setColumnProperty (1, 'type', 'number');
 data
.setColumnProperty (2, 'type', 'number');
 data
.setColumnProperty (3, 'type', 'number');
 data
.setColumnProperty (4, 'type', 'number');
 data
.setColumnProperty (5, 'type', 'number');
 data
.setColumnProperty (6, 'type', 'number');
 data
.setColumnProperty (7, 'type', 'number');
 data
.setColumnProperty (8, 'type', 'number');
 data
.setColumnProperty (9, 'type', 'number');
 data
.setColumnProperty (10, 'type', 'number');




but it seems to have no effect.  I still get the data type error.

What am I missing?

Daniel LaLiberte

unread,
Dec 20, 2014, 2:40:16 PM12/20/14
to google-visua...@googlegroups.com

Ken,  it would seem that what you tried should work.   But until we can make that happen, how about trying to set up a Data View?

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted

Ken Burkhalter

unread,
Dec 21, 2014, 8:37:17 AM12/21/14
to google-visua...@googlegroups.com


Daniel wrote: "... how about trying to set up a Data View?"



I changed my code to incorporate a dataView.  That code works OK when the csv file does contain nulls (exactly as the non-dataView approach did) but fails in the same "All series on a given axis must be of the same data type "way (as the non-view) when there is a full column of nulls in the csv data.

Attached is my code and a csv file with a null column for your inspection.

Thanks.    [:-)}
temps-view.csv
chartTemps-dataView.html

Ken Burkhalter

unread,
Dec 21, 2014, 8:40:23 AM12/21/14
to google-visua...@googlegroups.com
Woops, found a typo after I posted.

The statement "That code works OK when the csv file does contain nulls (exactly as the non-dataView approach did) "

Should have been "That code works OK when the csv file does not contain nulls (exactly as the non-dataView approach did) "

Daniel LaLiberte

unread,
Dec 21, 2014, 1:48:42 PM12/21/14
to google-visua...@googlegroups.com
Ken,

I built a jsfiddle starting with your html and data, and got it working: http://jsfiddle.net/dlaliberte/88mkcvop/
The significant change is that the arrayToDataTable() call should *not* be preceded by the 'new' keyword.  I'm not sure if that explains everything, but perhaps.   I'll be adding a check for when arrayToDataTable is called that way to prevent other obscure errors from getting past the front door.  Sorry I missed this earlier.

You might try your original code, if you have it, with this fix to see if it works without the DataView.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.



--
dlaliberte@Google.com   5CC, Cambridge MA
daniel.laliberte@GMail.com 9 Juniper Ridge Road, Acton MA

Ken Burkhalter

unread,
Dec 21, 2014, 7:08:09 PM12/21/14
to google-visua...@googlegroups.com
Daniel - You are PURE Genius!!!!  :-)

Works perfectly.

The code I tested with utilizes the DataView visualization.

I tried to get things going without DataView and I believe it failed (I was trying so many different things I'm not really sure what worked or not :-(

Since so many parameters are different between the DataView and without it (eg, sourceColumn: versus set ColumnProperty) that I don't even want to mess with success, so am leaving well enough alone.  :-)

Thank you for your efforts.  I don't think I would have ever thought of the approach you took, so just had my fingers crossed that someone a lot smarter than me was out there somewhere.

Sure glad you chipped in and helped out.

Happy Holidays to you and all the great folks at Google!

Thanks again!
  [:-)}


Ken Burkhalter

unread,
Dec 21, 2014, 7:23:01 PM12/21/14
to google-visua...@googlegroups.com
Well, I'm a glutton for punishment so I could not resist going back to the old code and trying it.

Using this approach...

 var data = google.visualization.arrayToDataTable(arrayData);

   
// Set chart options
 data
.setColumnProperty (0, 'type', 'number');
 data
.setColumnProperty (1, 'type', 'number');

                yada
, yada.

to initialize the column definitions, there was NO success.  I still get the "same axis data type" error.

BUT, all is well if I add the dataView visualization approach to the process (without the setColumnProperty method but the sourceColumn approach for the dataView).  I have not run across the "sourceColumn" method before and was not aware of it.  I didn't try it with the "data" set, just the "view" set.
 [:-)}

Daniel LaLiberte

unread,
Dec 21, 2014, 7:39:05 PM12/21/14
to google-visua...@googlegroups.com
Ken, I should have also noticed that you were trying to set the type with setColumnProperty.  That doesn't work since the properties are only for additional user-defined properties, not things like 'type'.  But there is no setColumnType() method either.  So to use the DataTable (without the DataView) would have to instead add a header row to your arrayData that specifies the types of the columns and pass that to arrayToDataTable().   

Using the DataView may be cleaner for you after all.  You can read all the documentation on the DataView class at https://developers.google.com/chart/interactive/docs/reference#DataView_setColumns


--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

Ken Burkhalter

unread,
Dec 22, 2014, 11:03:05 AM12/22/14
to google-visua...@googlegroups.com

On Sunday, December 21, 2014 7:39:05 PM UTC-5, Daniel LaLiberte wrote:
... to use the DataTable (without the DataView) would have to instead add a header row to your arrayData that specifies the types of the columns and pass that to arrayToDataTable().   

 Daniel - this morning I just noticed that using the dataView approach caused the labels to disappear from my chart legend.  They are in the 1st line (header) of the CSV file and previously provided labels with the non-DataView approach.

But as soon as I add the DataView visualization the labels disappear.

I restored labels with sourceColumn options (as exampled below) but would prefer to pass the labels in the CSV file for generality.  Is that possible?  I couldn't discover a way to make it work.

var data = google.visualization.arrayToDataTable(arrayData, false);
var view = new google.visualization.DataView(data);
view
.setColumns([
 
{sourceColumn: 0, type: "number", label: "Hour"},
 
{sourceColumn: 1, type: "number", label: "Dwn"},
 
{sourceColumn: 2, type: "number"},
 
{sourceColumn: 3, type: "number", label: "Mid"},
. . . .
. . . .



Thanks.

Daniel LaLiberte

unread,
Dec 22, 2014, 11:10:05 AM12/22/14
to google-visua...@googlegroups.com
Ken,

You can get the column labels from your DataTable data with data.getColumnLabel(i).  So use that expression instead of your literal string value.  In fact, you could use a loop to setup all of the columns for your DataView, building a columns array that you then pass to view.setColumns().

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

Ken Burkhalter

unread,
Dec 22, 2014, 11:49:32 AM12/22/14
to google-visua...@googlegroups.com
Nice!

Works just fine.

This has been a very helpful thread, that I hope will help others too.  I searched for days trying to find this information, without success.

Very grateful for your knowledge and assistance.

I think I now everything I wanted and needed.
 [:-)}
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/TxIRHjJ34sc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualizati...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

-- 
-ken burkhalter
No trees were killed in the sending of this message, but
a large number of electrons were terribly inconvenienced.

Ken Burkhalter

unread,
Dec 22, 2014, 4:44:45 PM12/22/14
to google-visua...@googlegroups.com
Now that everything is working, I thought it would be helpful to post the working file, in the hope it might help others.

See attached (which is a pretty much documented code example) ...
  [:-)}
chartTemps.html
Reply all
Reply to author
Forward
0 new messages