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

0
0

Hi,

I am using SciChart_iOS_SDK_3.0.0.5074 with Swift 5.

I want to show string type on X-axis. I am using below code snippet.

class YearsLabelProvider: SCILabelProviderBase<SCINumericAxis> {

   var xLabels: [String] = ["Test", "Test", "Test", "Test", "Test", "Test", "Test", "Test",     "Test", "Test", "Test", "Test", "Test", "Test"]

   func update(_ axis: ISCIAxisCore!) { }

   override func formatLabel(_ dataValue: ISCIComparable!) -> ISCIString! {
        let index = Int(dataValue.toDouble())
        return NSString(string: index >= 0 && index < xLabels.count ? xLabels[index] : "")
    }

    override func formatCursorLabel(_ dataValue: ISCIComparable!) -> ISCIString! {
        let index = Int(dataValue.toDouble())

        var result: String?

        if (index >= 0 && index < xLabels.count) {
            result = xLabels[index]
        }
        return NSString(string: result!)
    }
}

Application crashes while loading with the following error –

” *** Terminating app due to uncaught exception ‘Initializer not allowed Exception’, reason: ‘Parameterless initializer of Chart.YearsLabelProvider class shouldn’t be used. Please use one of the designated initializers instead'”

Kindly help us resolving this issue since this is a showstopper issue.
I would also like to know about what data SCIXyDataSeries accepts when we are working with strings.

Version
3.0.0.5074
  • You must to post comments
1
0

Hello and good morning! 🙂

I believe the error you are seeing is because you haven’t overridden the appropriate constructor for LabelProvider.

There is a code sample of a label provider in our Github repository here.

import SciChart.Protected.SCILabelProviderBase

class SCDThousandsLabelProvider: SCILabelProviderBase<ISCINumericAxis> {

    // Ensure constructor is overridden
    init() {
        super.init(axisType: ISCINumericAxis.self)
    }

    override func formatLabel(_ dataValue: ISCIComparable!) -> ISCIString! {
        return NSString(string: "\(dataValue.toDouble() / 1000.0)k") // %.1fk format
    }

    override func formatCursorLabel(_ dataValue: ISCIComparable!) -> ISCIString! {
        return formatLabel(dataValue)
    }
}

Also more information in our documentation can be found here:

Creating your own LabelProvider

You might want to create a your own, fully custom, LabelProvider. To
do so, – we simply create a class that inherits SCILabelProviderBase
and provide the proper ISCIAxis @protocol(), which should correspond
to the axis which will use your label provider. From there, you can
override the following, similarly to the Label Formatter

Let me know if this helps!

Best regards,
Andrew

  • You must to post comments
1
0

see a sample implementation

xAxis.labelProvider = SCINumericLabelProvider(labelFormatter: YearsLabelProvider())

class YearsLabelProvider: ISCILabelFormatter {

    var xLabels: [String]

    init() {
        xLabels = ["Test1", "Test2", "Test3", "Test4", "Test5", "Test6", "Test7", "Test8", "Test9", "Test10", "Test11", "Test12", "Test13", "Test14"]
    }

    func update(_ axis: ISCIAxisCore!) { }

    func formatLabel(_ dataValue: Double) -> ISCIString! {
        // return a formatting string for tick labels
        let index = Int(dataValue)
        return NSString(string: index >= 0 && index < xLabels.count ? xLabels[index] : "")
    }

    func formatCursorLabel(_ dataValue: Double) -> ISCIString! {
        // return a formatting string for modifiers’ axis labels
        return formatLabel(dataValue)
    }
}
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.