Skip to content Skip to sidebar Skip to footer

Get Visible Points For A Series In Lightningchartjs

Exists a function in LightningChartJs to get all visible points from a line or point series in a chart? If I zoom the chart I want to show something if no visible points available.

Solution 1:

LightningChart JS doesn't track the data points that are visible at any time. So the method that you have used to solve the issue is the best way currently.

Something like this seems to be reasonably performant.

functiongetDataInRange(data, rangeStart, rangeEnd){
    const inRangeData = []
    const dataLength = data.lengthlet curPoint
    for(let i = 0; i < dataLength; i += 1){
        curPoint = data[i]
        if(curPoint.x >= rangeStart && curPoint.x <= rangeEnd){
            inRangeData.push(curPoint)
        }
    }
    return inRangeData
}

On my personal machine it can process 1 million points in ~10ms ± 2ms. If you only want to know that a point is visible in the range then you could just break the loop as soon as a single point is in the visible range.

Post a Comment for "Get Visible Points For A Series In Lightningchartjs"