1

I want to add a control filter to a StackedColumnChart. I am using com.googlecode.gwt-charts 0.9.10 and com.google.gwt.google-apis 1,0,2. I have been using the showcase at https://gwt-charts.appspot.com/ as a reference - specifically the Category Filter example.

My goal is to enable the user to select the categories that will be displayed in the stacked bar chart, I cannot see how I can use the CategoryFilter due to the layout of the data.

I created a playground project with a small amount of test data. The datatable is created by

DataTable dataTable = DataTable.create();
    dataTable.addColumn(ColumnType.STRING, "event");
    dataTable.addColumn(ColumnType.NUMBER, "apples");
    dataTable.addColumn(ColumnType.NUMBER, "pears");
    dataTable.addColumn(ColumnType.NUMBER, "oranges");
    
    for(int i=0;i<5;i++)
    {
        int row = dataTable.addRow() ;
        dataTable.setValue(row, 0, "E"+i);
        dataTable.setValue(row, 1, i+1);
        dataTable.setValue(row, 2, i+2);
        dataTable.setValue(row, 3, i+3);
    }
  

The issue is that if a try to create a dashbord and filter for this chart I have to specify the category column.via a call to CategoryFilterOptions.setFilterColumnIndex(int).

Clearly CategoryFilter is not the correct approach - this will work fine for charts such as pie charts where you have a category selection within a datatable column BUT not for stacked column charts.

what is the best approach to enable the user to select the categories to include in a stackedcolumn chart

  • I don't know if you've taken a look at this, but on the page itself they give you an example of how to do it https://gwt-charts.appspot.com/#categoryfilter – SeiryuV Aug 25 '23 at 09:31
  • Yes i have looked at the category filter examples in the showcase and the example will not work for a stacked. Column chart. Thanks – Dave Breeze Aug 27 '23 at 05:51

1 Answers1

1

Being unable to find a filter that would work I:

  • added a ListBox and populated with every category within the stackColumn chart
  • cloned the DataTable to create a "shadow" table
  • on the listbox being upfated removed non-selected categories from the shadow table and re-drew the chart from the shadow table

this works but it would have been nice to use a built-in filter