1

What i want to do is count the values that i have on 2 or more ControlWrapper in one column but so far i only realised that i can only see the values betwean 1 ControlWrapper "and" another ControlWrapper and i wish to use a "or" not a "and".

https://i.stack.imgur.com/fl2kd.png

here is an image of an example on what i am trieng to do, i wish to see the content betwean 1-3 and 6-8 and what i have in return (at least in this example) is empty

Henrique Alves
  • 37
  • 1
  • 1
  • 9

1 Answers1

1

Google doesn't supply a function to achieve this by default, but you have pretty good tools.
I've made use of their data.getFilteredRows([{column:X, minValue:XY, maxValue:YY}]), by simply creating two sliders (like your picture), adding a listener to whenever any of the two are "changed on", checking the minValue and maxValue of both, passing all four values into a function and then setting the view of another chart to the returned rows.

My listeners looks like this

google.visualization.events.addListener(control, 'statechange', function () {
    stateChangeFunction();
});

The stateChangeFunction() looks like this

function stateChangeFunction() {
    var lowFilter1 = control.getState().lowValue;
    var highFilter1 = control.getState().highValue;
    var lowFilter2 = control2.getState().lowValue;
    var highFilter2 = control2.getState().highValue;

    customFilterChart.setView({
        'rows': customFilter(lowFilter1, highFilter1, lowFilter2, highFilter2)
    });
    customFilterChart.draw();
};

It simply reads the high and low value of both sliders, and then sets the view of my customFilteredChart to the rows that are returned by this function

function customFilter(low1, high1, low2, high2) {
    var rows = []
//Using googles own getFilteredRows
    rows = data.getFilteredRows([{
        column: 1,
        minValue: low1,
        maxValue: high1
    }]);
//Then doing the same with the other two values.
    rows = rows.concat(data.getFilteredRows([{
        column: 1,
        minValue: low2,
        maxValue: high2
    }]));
//Removing duplicate rows to avoid displaying them twice.
    var uniqueRows = rows.reduce(function(a,b){if(a.indexOf(b)<0)a.push(b);return a;},[]);

    return uniqueRows
}

Also I'd like to credit Christian Landgren for this wonderful reply.

And finally, here is the fiddle I made it in: Fiddle

Community
  • 1
  • 1
Henrik Aronsson
  • 1,383
  • 9
  • 17
  • I find it intresting on how it is always possible to manipulate the code when they or the librarys dont support such functions. But thank you, this was exacly what i was looking for and thanks to Christian Landgren as well. – Henrique Alves May 22 '15 at 11:18