Search code examples
iosscichart

SciCharts - ISCIAxisCore visible min and max index


I am using the SciChart API for 2D Charts from SciCharts, I wanted to know if it is possible to know the min and max visible index/indices from ISCIAxisCore.

I need to get this information from the callback made to SCIVisibleRangeChangeListener when visible range as changed. So I can calculate some extended information, all the data is stored in a few arrays and the graph is only showing a section of it and I need to show some average values based on the visible range of the graph.

I know I could use Swift API to get the index out of the array but this seems to me like the most inefficient way of getting the visible min and max index of the data set, as it will need to search in a data set that can span more than 5k records.


Solution

  • I suspect, you are looking for one of the following:

    I added the following listener with prints into our Line Chart Example, which showcases how to use getIndicesXRange:

    xAxis.visibleRangeChangeListener = { (axis, oldRange, newRange, animated) in
        guard animated == false else { return }
    
        if let axis = axis, let min = newRange?.minAsDouble, let max = newRange?.maxAsDouble {
            let indicesRange = SCIIndexRange()
            dataSeries.getIndicesXRange(indicesRange, xCoordinateCalculator: axis.currentCoordinateCalculator)
    
            print("Values: \(min) : \(max)")
            print("Min: \(indicesRange.min), Max \(indicesRange.max)")
        }
    }
    

    Hope that helps.