Pre loader

swift SCICustomAnnotation not displayed on correct location

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums


I am adding a SCICustomAnnotation on a particular graph bar click. But the annotation always gets added to a fixed location and is not varying according to the selection. Whereas if I am adding the annotation during the init(), it’s getting added on the correct location point.
if let annotationValue = viewModel.categoryModel?.value, annotationValue > 0 {
let customAnnotationGreen = SCICustomAnnotation()
customAnnotationGreen.horizontalAnchorPoint = .center
let imageView = UIImageView(image: #imageLiteral(resourceName: “Triangle”))
imageView.frame = CGRect(origin: .zero, size: CGSize(width: 10, height: 10))

                    customAnnotationGreen.customView = imageView// UIImageView(image: #imageLiteral(resourceName: "Triangle"))
                    if let value = viewModel.categoryModel?.graphDataPoints.values[hitTestInfo.dataSeriesIndex].toDouble() {
                        customAnnotationGreen.set(x1: hitTestInfo.dataSeriesIndex)
                        customAnnotationGreen.set(y1: value)
  • You must to post comments

Hi, there.

Hi, there.

Thanks for writing to us.

If I understand your issue correctly, you can subclass SCISeriesSelectionModifier, get selected series, and update your annotation coordinate in some callback, like this

import SciChart.Protected.SCISeriesSelectionModifier
class CustomSelectionModifier: SCISeriesSelectionModifier {
    var onSelectionChange: ((Double) -> Void)?

    override func performSelection(_ renderableSeries: ISCIRenderableSeries) {

        guard let xPosition = (renderableSeries.dataSeries as? SCIXyDataSeries)?.xValues.toArray().first
        else { return }

        onSelectionChange?(xPosition as! Double)


class ColumnChartView: SCDSingleChartViewController<SCIChartSurface> {

    override var associatedType: AnyClass { return SCIChartSurface.self }

    override func initExample() {
        let xAxis = SCINumericAxis()
        xAxis.growBy = SCIDoubleRange(min: 0.1, max: 0.1)
        let yAxis = SCINumericAxis()
        yAxis.growBy = SCIDoubleRange(min: 0, max: 0.1)

        let seriesCollection = SCIRenderableSeriesCollection()

        let yValues = [1, 50, 100];
        for i in 0 ..< yValues.count {
            let dataSeries = SCIXyDataSeries(xType: .double, yType: .double)
            dataSeries.append(x: i, y: yValues[i])

            let rSeries = createSeries(dataSeries: dataSeries)

        let customAnnotationGreen = SCICustomAnnotation()
        customAnnotationGreen.customView = SCIImageView.init(image: #imageLiteral(resourceName: ""))
        customAnnotationGreen.set(x1: 0)
        customAnnotationGreen.set(y1: 105)

        let seriesSelectionModifier = CustomSelectionModifier()
        seriesSelectionModifier.onSelectionChange = { xPosition in
            customAnnotationGreen.set(x1: xPosition)

        self.surface.annotations = SCIAnnotationCollection(collection: [customAnnotationGreen])

        SCIUpdateSuspender.usingWith(surface) {
            self.surface.renderableSeries = seriesCollection//.add(rSeries)

    private func createSeries(dataSeries: SCIXyDataSeries) -> ISCIRenderableSeries {
        let rSeries = SCIFastColumnRenderableSeries()
        rSeries.dataSeries = dataSeries
        rSeries.dataPointWidth = 0.3

        return rSeries
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies