Adding one row at a time for stacked bar chart?

17 views
Skip to first unread message

Sam56

unread,
Jun 26, 2017, 12:01:10 AM6/26/17
to Google Visualization API
I am trying to create a stacked bar chart using Google Charts. The data I have is kind of jumpy, for example: Let's say I have a data set like this:
  • 2001, A, 500
  • 2001, B, 200
  • 2001, C, 100
  • 2002, B, 900
  • 2002, C, 400
  • 2003, A, 600
  • 2003, C, 900
The columns are the year and the letter. In Google Charts, you would create this chart like this:
 
var data = new google.visualization.DataTable();
    data
.addColumn('string', 'Topping');
    data
.addColumn('number', 'A');
    data
.addColumn('number', 'B');
    data
.addColumn('number', 'C');


    data
.addRows([

       
['2001', 500, 200, 100],
       
['2002', undefined, 900, 400],
       
['2003', 600, undefined, 900],
   
]);




However, because the data is jumpy and it's not possible to know what comes next, creating a chart like this becomes a headache. Is it possible to create one row at a time like so:
data.addRow['2001', 'A', 500]; data.addRow['2001', 'B', 200], etc? So for example, undefined columns that don't exist won't show up like 2002: A. Is it possible to do something like this?

Daniel LaLiberte

unread,
Jun 26, 2017, 12:54:13 AM6/26/17
to Google Visualization API
We've thought of doing something like that, but haven't gotten around to implementing it.  It is becoming a frequent request, however, so I will try to look into how we might implement it.

--
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-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/2111b4a1-79de-42aa-afdd-0a272d8f3ab8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages