Google charts - how to pass dynamic variable to options.series?

I am creating a reporting tool that uses Google Charts graphics. I want to create Combo Charts, but the data number is dynamic, so I need to pass the nbEGP variable to 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 that will not work. If I try to display options.series, I see that this did not put the value of my variable, but the name is "nbEGP".

+5
source share
1 answer

I finally managed to do this:

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

myObj = {};
myObj[nbEGP] = {type : "line"};
options.series = myObj;
+7
source

All Articles