Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Charts - How to pass a dynamic variable in options.series?

I'm making a reporting tool that uses Google Charts graphics. I want to create Combo Charts but the number of datas is dynamic so i have to pass a variable "nbEGP" in options.series:

/* Création de graphique Google Chart */

function drawChart(array, title, div, type, nbEGP) {

var data = new google.visualization.arrayToDataTable(array);

// Set chart options
var options = {
    'title' : title,
    'width' : '80%',
    'height' : '600',
    seriesType : "bars",
    series : {
            nbEGP : {
            type : "line"
        }
    }
};

...

chart.draw(data, options);
}

but it doesn't work. If i try to display options.series I can see it did not put the value of my variable but the name "nbEGP".

like image 753
Doutriaux Olivier Avatar asked Apr 19 '13 14:04

Doutriaux Olivier


1 Answers

I finally managed doing like this:

// Set chart options
var options = {
    'title' : title,
    'width' : '80%',
    'height' : '600',
    seriesType : "bars",
    series : ""
};

myObj = {};
myObj[nbEGP] = {type : "line"};
options.series = myObj;
like image 171
Doutriaux Olivier Avatar answered Sep 20 '22 00:09

Doutriaux Olivier