HighCharts: Accessing Zoomed Series Data

HighCharts: Accessing Zoomed Series Data



If i zoom an HighStock multi series chart (using either the Navigator or the Range Selector), is there a way to fetch the point.y data only for the zoomed series?



For example, if I am showing the sales information for a period across multiple branches (each branch plotted as series), and if zoomed to a week, I would like to know the total of sales for the week across the branches. Does highstock provide access to the zoomed dataset?




2 Answers
2



A very brute force approach to this is to loop over your data upon zooming and evaluate if it is visible. That is, is a given point within the range of the x-axis (and y-axis, if you allow zoom in that direction)?


chart:
events:
redraw: function()
sum = 0;
xAxis = this.xAxis[0];
// Loop over your series
this.series[0].data.forEach(function(point)
// Add to sum if within x-axis visible range
if(point.x >= xAxis.min && point.x <= xAxis.max)
sum += point.y;

// If too large, stop summing
if(point.x > xAxis.max)
return;

);
// Print sum
console.log('Visible sum: '+sum);





See this JSFiddle demonstration of it in use.



You might evaluate xAxis.events.setExtremes, but it offers min and max values that might change after it takes effect, which might give some unexpected results.


xAxis.events.setExtremes


min


max






This seems like an unnecessarily expensive operation. Hopefully someone can bring something with better performance

– Halvor Holsten Strand
Sep 16 '18 at 20:25






Thanks Halvor, or may be we could just directly filter the series dataset for the zoom period and then sum it up. (which will not involve checking the point values) I will check that.

– thanikkal
Sep 17 '18 at 6:45



You can check isInside flag on every point:


isInside


redraw: function()
var sum = 0;

Highcharts.each(this.series[0].points, function(point)
if (point.isInside)
sum += point.y;

);
console.log(sum)



Live demo: http://jsfiddle.net/BlackLabel/7kmzhecy/






This doesnt work for highstock chart reliably (havent tried for hicharts alone), using Navigator or the Range Selector. I need to debug and see where its getting off.

– thanikkal
Sep 17 '18 at 14:28







It should work fine with Highstock: jsfiddle.net/BlackLabel/ab6192v7

– ppotaczek
Sep 17 '18 at 15:06



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế