6

我正在制作一个使用 Google Charts 图形的报告工具。我想创建组合图表,但数据的数量是动态的,所以我必须在 options.series 中传递一个变量“nbEGP”:

/* 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);
}

但它不起作用。如果我尝试显示 options.series 我可以看到它没有输入我的变量的值,而是名称“nbEGP”。

4

1 回答 1

9

我终于设法这样做了:

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

myObj = {};
myObj[nbEGP] = {type : "line"};
options.series = myObj;
于 2013-04-26T10:18:55.857 回答