HighCharts dynamic high/low extreme markers

2019-08-10 07:24发布

I am wanting to display a marker on the highest and lowest point value in view along the y axis on a line series. I know how to add a marker manually but would like to add/remove them dynamically if a zoom/pan or anything else alters the visible high/low points is there a way to know this and the new high/low to add/remove the markers?

A previous SO question asked for similar advice with this mockup image: http://cl.ly/image/1f0m3l241e2S. The answer though is providing it with your data source, which wouldn't update via zoom/pan or streaming data.

I could potentially loop through the data source myself(2D Array), find the high/low and set them, doing the same on zoom/pan events if I can loop through only the zoomed section of the array. Though if I have dataGrouping set to true, the array of values I iterate over may not match up correctly?

标签: highcharts
1条回答
The star\"
2楼-- · 2019-08-10 08:05

You can do this by

1) using the getExtremes() method to get the high/low data points

2) using the afterSetExtremes() event to capture a zoom event and recalculate

A couple of potentially relevant posts:

You can set this up in a function, to loop through your data and look for a match to the high/low data points, and from them build a scatter series marking the high/low points on the chart.

An example that marks the points both on chart load and zoom:

function sample, gets the relevant x value at which to place the marker matching the high/low data point:

$.each(chart.series[0].data, function(i,point) {
    if(point.y == maxData && point.x <= maxTime && point.x >= minTime) {
        xMax = point.x;
    }
    if(point.y == minData && point.x <= maxTime && point.x >= minTime) {
        console.log(point);

        xMin = point.x;
    }
});

{{UPDATE:

Important to note this issue:

If you are going to use column or area series, you will need to get the min and max from the series object instead of the getExtremes() method, because the chart internally sets the dataMin to 0 for those series types.

Easy enough to adapt the function accordingly.

And on a similar note, if you are going to use a boxplot, columnrange, or other similar series without an explicit y value, you will have to update accordingly as well.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.

查看更多
登录 后发表回答
相关问题
查看全部
相关文章
查看全部
收藏的人(6)