Dynamic options series reference

19 views
Skip to first unread message

Gibono

unread,
Feb 18, 2016, 9:26:43 AM2/18/16
to Google Visualization API
Hi,

I've got a dynamic DataTable (the number of columns is not fix => database related).

Here is an exemple of the dataTable:

{
 
"cols": [{
 
"id": "Month",
 
"label": "Month",
 
"type": "string"
 
}, {
 
"id": "2015",
 
"label": "2015",
 
"type": "number"
 
}, {
 
"id": "Average",
 
"label": "Average",
 
"type": "number"
 
}],
 
"rows": [{
 
"c": [{
 
"v": "January"
 
}, {
 
"v": 1
 
}, {
 
"v": 1
 
}]
 
}, {
 
"c": [{
 
"v": "February"
 
}, {
 
"v": 2
 
}, {
 
"v": 2
 
}]
 
}]
}

or

{
 
"cols": [{
 
"id": "Month",
 
"label": "Month",
 
"type": "string"
 
}, {
 
"id": "2015",
 
"label": "2015",
 
"type": "number"
 
},
 {
 
"id": "2016",
 
"label": "2016",
 
"type": "number"
 
}, 
{
 
"id": "Average",
 
"label": "Average",
 
"type": "number"
 
}],
 
"rows": [{
 
"c": [{
 
"v": "January"
 
}, {
 
"v": 1
 
}, {
 
"v": 1
 
}]
 
}, {
 
"c": [{
 
"v": "February"
 
}, {
 
"v": 2
 
}, {
 
"v": 2
 
}]
 
}]
}

So it depends of the number of years....


I'd like to do somehting like this:

var firstYear = 2015;
var data = new google.visualization.DataTable(jsonData);
var curYear = new Date().getFullYear();
var nbYears= (curYear-firstYear)+1;
   
var options = {
  title
: 'My graph',
  vAxis
: {title: 'CHF'},
  hAxis
: {title: 'Month'},
  seriesType
: 'bars',
  series
: {nbYears: {type: 'line'}}
};





or


var options = {
   title
: 'My graph',
   vAxis
: {title: 'CHF'},
   hAxis
: {title: 'Month'},
   seriesType
: 'bars',
   series
: {lastIndex: {type: 'line'}}
};

or

var options = {
   title
: 'My graph',
   vAxis
: {title: 'CHF'},
   hAxis
: {title: 'Month'},
   seriesType
: 'bars',
   series
: {'Average': {type: 'line'}}
};


How can I do that?`

Thanks for the answers.

Daniel LaLiberte

unread,
Feb 18, 2016, 9:38:37 AM2/18/16
to Google Visualization API
You can't do it quite like that, though in the future, we could probably support referencing a series by its column id.  Instead, you'll need to do something like this:



var options = {
   title : 'My graph',
   vAxis: {title: 'CHF'},
   hAxis: {title: 'Month'},
   seriesType: 'bars',
   series: {}
};
options.series[nbYears] = {type: 'line'};


--
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 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/1bf7ea1d-9614-44d8-88fa-cc6eceb6f451%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Gibono

unread,
Feb 18, 2016, 9:52:58 AM2/18/16
to Google Visualization API
Works like a charm.

THANKS!
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.



--

Gibono

unread,
Feb 18, 2016, 9:55:30 AM2/18/16
to Google Visualization API
Uhm I'me greedy...

Is there a way to get the last index?

Gibono

unread,
Feb 18, 2016, 9:58:59 AM2/18/16
to Google Visualization API
Found it:

data.getNumberOfColumns()
Reply all
Reply to author
Forward
0 new messages