SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components

0
0

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.
Ex:
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)
                        self.columnChart.annotations.add(customAnnotationGreen)
                    }
                }
Version
4.3.0.5721
Images
  • You must to post comments
0
0

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) {
        super.performSelection(renderableSeries)

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

        onSelectionChange?(xPosition as! Double)

        deselectAllBut(renderableSeries)
    }
}

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)
            seriesCollection.add(rSeries)
        }

        let customAnnotationGreen = SCICustomAnnotation()
        customAnnotationGreen.customView = SCIImageView.init(image: #imageLiteral(resourceName: "image.arrow.green"))
        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.xAxes.add(xAxis)
            self.surface.yAxes.add(yAxis)
            self.surface.renderableSeries = seriesCollection//.add(rSeries)
            self.surface.chartModifiers.add(SCDExampleBaseViewController.createDefaultModifiers())
            self.surface.chartModifiers.add(seriesSelectionModifier)
        }
    }

    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.