mdshields
mdshields

Reputation: 31

Google Graphs - ChartRangeFilter - values in selected range?

I currently have a LineChart which is fed with dates on the x-axis and numbers on thy y-axis (via json/php-mysql). Everything is working as intended but i would like to work with the values inside the range (min, max, avg etc)

I can get the current position of both slider positions like so:

google.visualization.events.addListener(RangeSlider, 'statechange', selectHandler);

        function selectHandler(e){
            currentLeftSliderPos = RangeSlider.getState().range.start;
            currentRightSliderPos = RangeSlider.getState().range.end;
        }  

Those values are date objects, and the only way i can think off is to iterate over the array, but in the array the x-axis values are in the form "Date(dd,mm,yyyy)" strings and not date objects. Im still new to this and would really appreciate andy input/ideas.

Here is a fiddle with a ChartRangeFilter : https://jsfiddle.net/forssux/2joyoz87/

Upvotes: 0

Views: 315

Answers (1)

Leo Skhrnkv
Leo Skhrnkv

Reputation: 1703

You can convert your date strings into date object by using the following code:

//convert to number of milliseconds first
d1 = Date.parse("Date(dd, mm, yyyy)".replace(/, /g,"/").replace(/Date\(|\)/g,''));
//then create a Date object
d_new = new Date(d1)

So create a loop that goes through your string dates and converts them to Date objects.

Hope that helps.

Upvotes: 1

Related Questions