0

我想创建一个 CategoryFilter,它将在数组中搜索一个值,而不仅仅是匹配该列。

例如,如果我有以下 DataTable 包含有关 T 恤的数据:

var data = new google.visualization.DataTable();
data.addColumn("string", "ItemName");
data.addColumn("number", "Price");
data.addColumn("string", "Size");
data.addRows([
  // Loop through and add some records
]);

我可以轻松地创建一个 CategoryFilter 来过滤大小

var sizePicker = new google.visualization.ControlWrapper({
  "controlType": "CategoryFilter",
  "containerId": "size-picker",
  "options": {
    "filterColumnLabel": "Size"
  }
});

到目前为止,这一切都很好。

现在假设我希望每条 T 恤记录都包含一系列可用的衬衫颜色。

所以基本上我想有这样的记录

[ "Crew T-Shirt", "10", "Large", [ "Blue", "Striped", "White" ]]

Then a CategoryFilter has a list of the colors, and when a color is picked the filter searches the array and if it contains the selected color, it's included in the result set.

现在由于DataTable 的 addColumn()方法不支持数组,我不知道该怎么做。我什至找不到覆盖过滤方法的方法。这样的事情可能吗?

4

1 回答 1

0

大多数人在 DataTable 中列出所有组合,使用几个CategoryFilters 并将它们全部绑定在一个Dashboard. 例如:

var data = google.visualization.arrayToDataTable([['Item Name', 'Price', 'Size', 'Color'],
  ['Crew T-Shirt', '10', 'Large', 'Blue'],
  ['Crew T-Shirt', '10', 'Large', 'Striped'],
  // etc...
]);

var sizePicker = new google.visualization.ControlWrapper({
  "controlType": "CategoryFilter",
  "containerId": "size-picker",
  "options": { "filterColumnLabel": "Size" } });
var colorPicker = new google.visualization.ControlWrapper({
  'controlType': 'CategoryFilter',
  'containerId': 'color-picker',  // or whatever....
  'options': { 'filteredColumnLabel': 'Color'} });
var dashboard = new google.visualization.Dashboard( DOC.EL_BY_ID('XXX') );
dashboard.bind([sizePicker, colorPicker], [ CHART1, CHART2, etc. ]);
dashboard.draw(dataTable);
于 2013-07-17T13:23:36.990 回答