我正在尝试使用基于相同数据集的多个图表创建Google Charts仪表板。但是,不同的图表需要不同的数据列,每次我尝试限制ChartWrapper视图中的列时,都会出错。这是我的代码:
google.charts.load('current', {packages: ['corechart', 'bar', 'controls']});
google.charts.setOnLoadCallback(drawDashboard);
function drawDashboard() {
var data = google.visualization.arrayToDataTable([
['Institution', 'Ineligible', 'Active', 'Closed With Outcome', 'Closed Outside Process', 'Closed Without Outcome',
'Eligibile'],
['CAC', 144, 35, 38, 4, 175, 115 ],
['SPF', 62, 2, 12, 1, 93, 4 ],
['CM', 69, 18, 10, 7, 64, 32 ],
['IP', 36, 4, 28, 24, 38, 62 ],
['EVM', 77, 7, 8, 2, 78, 19 ],
['RMC', 63, 5, 9, 1, 62, 18 ],
['MRI', 17, 5, 1, 5, 8, 3 ],
['IRM', 8, 0, 2, 1, 10, 5 ],
]);
var dashboard = new google.visualization.Dashboard(
document.getElementById('dashboard_div'));
var iamFilter = new google.visualization.ControlWrapper({
'controlType': 'CategoryFilter',
'containerId': 'iam_filter',
'options': {
'filterColumnLabel': 'IAM',
'ui': {
'caption': "Choose mechanisms",
'label': '',
'labelStacking': 'vertical',
'selectedValuesLayout': 'belowWrapping',
'cssClass': 'ChartControl',
}
},
});
var columnChart = new google.visualization.ChartWrapper({
'chartType': 'ColumnChart',
'containerId': 'id_outcomes',
'options': {
colors: ['#1b5869', '#42bb9a', '#bec3c7', '#9953b5', '#4c96da'],
animation: {
"startup": true,
duration: 1000,
easing: 'out',
},
legend: { position: 'right'},
bar: { groupWidth: '75%' },
isStacked: true,
},
'view': {'columns': [0,2,3]},
});
dashboard.bind(iamFilter, columnChart);
dashboard.draw(data);
}
在上面的例子中,我得到的错误是:
无效的列索引3.应该是[0-2]范围内的整数。
但如果我将其更改为'view':{'columns':[0,2]},我得到的错误是:
无效的列索引2.应该是[0-1]范围内的整数。
view属性在ControlWrapper上工作正常,但我需要它才能在ChartWrapper上工作,因为单个ControlWrapper需要过滤多个图表的数据。
非常感谢任何建议!