Highstock custom min max approximation works properly only at some ranges -
i feeding highstock chart datas mysql. there variables stored every minute if want @ data past 3 months grouped. highstock's default approximation functions give low,high,averare,sum values only. min , max values important me made own approximation function is:
approximation: function (arr) { // first time or point precalculated if ( !ginfo || ginfo.nextpoint) { // first time return first value (arr[0]) var point = ginfo ? ginfo.nextpoint : arr[0]; // save current data next iteration ginfo = {prev : arr, nextpoint : null}; return point; } else { var prev = ginfo.prev, // concat current group previous 1 data = prev.concat(arr), // min, max , positions min = math.min.apply(null, data), max = math.max.apply(null, data), minidx = data.indexof(min), maxidx = data.indexof(max), // order min , max aprox = minidx < maxidx ? [min, max] : [max, min]; // save next aproximation , return current ginfo.nextpoint = aprox[1]; return aprox[0]; } },
actually didn't make found here in forum.
the problem gives me right results @ ranges shown in pictures below:
first picture @ max range - not ok: max range - can't see every min value
as changing range smaller can see every min value: this how should looke @ max range
it happening when zoom in datas grouped in 2 min intervals , scrolling left or right.
at first thought has way groups made changing grouppixelwidth:
value did not help.
having min or max important me , can solve in highstock.
there seems error in approximation function. in 3rd line:
if ( !ginfo || ginfo.nextpoint) {
if
should evaluate false if !ginfo false (it after first time) , ginfo.nextpoint returns false, return false not if null (as set in function), when zero. changing if
condition to:
if (!ginfo || ginfo.nextpoint !== null) {
example error (before fix): http://jsfiddle.net/p2qvx24a/1/
example fix: http://jsfiddle.net/p2qvx24a/
Comments
Post a Comment