Column data structure and AreaChart

76 views
Skip to first unread message

Peetzer

unread,
Jun 20, 2012, 9:54:28 AM6/20/12
to google-visua...@googlegroups.com
Is it possible to use column date (date), value (number) and group on type (string) and show both types (legends) in graph ?

Column value contains all the values which belong to different types.


Date                            value                type
20-06-2012 09:00          10                   'bananas'
20-06-2012 09:30          2                     'tomatos' 
20-06-2012 10:00          5                     'tomatos' 
20-06-2012 10:00          1                     'bananas' 

Or is it only possible to use a column for each type?

Date                            value (label 'bananas')               value2 (label 'tomatos')
20-06-2012 09:00          10                  
20-06-2012 09:30                                                        2                      
20-06-2012 10:00                                                        5 
20-06-2012 10:00          1

asgallant

unread,
Jun 20, 2012, 11:24:21 PM6/20/12
to google-visua...@googlegroups.com
This is not explicitly supported, but you can hack around it using a DataView with calculated columns:

​var view new google.visualization.DataView(data);
view.setColumns([0{
    label'bananas',
    type'number',
    calcfunction (dtrow{
        // if type = bananas, return this value, otherwise return null
        if (dt.getValue(row2== 'bananas'{
            return dt.getValue(row1);
        }
        else {
            return null;
        }
    }
}{
    label'tomatos',
    type'number',
    calcfunction (dtrow{
        // if type = tomatos, return this value, otherwise return null
        if (dt.getValue(row2== 'tomatos'{
            return dt.getValue(row1);
        }
        else {
            return null;
        }
    }
    
}]); 

Draw the chart using this view.

Peter van Raamsdonk

unread,
Jun 21, 2012, 2:02:26 AM6/21/12
to google-visua...@googlegroups.com
Thanks! I thought it would be like this. But actually this is adding a new column, I solved this already in java but good to know this in javascript too.
I gives possibilities :)
 
Regards Peter
 
Ps, is also support planned for filtering on column (show only column 'bananas' or 'tomatos') ? Like catergory filter but not only filter on values.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-visualization-api/-/omorAfOBwCwJ.

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.

asgallant

unread,
Jun 21, 2012, 11:36:58 AM6/21/12
to google-visua...@googlegroups.com
I don't know if anything like this is planned, but I wrote a hack to make it work: http://jsfiddle.net/asgallant/WaUu2/ 

To post to this group, send email to google-visualization-api@googlegroups.com.
To unsubscribe from this group, send email to google-visualization-api+unsub...@googlegroups.com.

Peter van Raamsdonk

unread,
Jun 21, 2012, 12:15:24 PM6/21/12
to google-visua...@googlegroups.com, asgallant
Wow perfect, exactly what I was looking for!

Thank you!!

Regards,

Peter

To view this discussion on the web visit https://groups.google.com/d/msg/google-visualization-api/-/Mt-PtQvfICcJ.
To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.

asgallant

unread,
Jun 21, 2012, 12:38:12 PM6/21/12
to google-visua...@googlegroups.com, asgallant
You are welcome.

Peetzer

unread,
Jun 22, 2012, 7:59:20 AM6/22/12
to google-visua...@googlegroups.com, asgallant
Note, it also wise to set the  'ui.allowNone' to false. It is then not possible to select nothing. Works perfect!

See also this thread;


Regards Peter

Op donderdag 21 juni 2012 18:38:12 UTC+2 schreef asgallant het volgende:

Alex Stone

unread,
Jul 17, 2012, 2:35:24 AM7/17/12
to google-visua...@googlegroups.com
Thanks for the workaround, asgallant. Wondering if there's a way to make the redrawn columns retain their existing order after being selected/deselected, instead of redrawing to the last column?

asgallant

unread,
Jul 17, 2012, 11:32:05 AM7/17/12
to google-visua...@googlegroups.com
Updated, with sorting on the columns to keep them in the original order: http://jsfiddle.net/asgallant/WaUu2/ 

eoionline

unread,
Jul 18, 2012, 11:30:05 AM7/18/12
to google-visua...@googlegroups.com
Thanks, asgallant. As someone new to javascript, my google vis projects have been made much easier with thanks to your answers in the forum.

asgallant

unread,
Jul 18, 2012, 12:28:58 PM7/18/12
to google-visua...@googlegroups.com
You're welcome.
Reply all
Reply to author
Forward
0 new messages