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

0
0

I am trying to make a custom Label Provider by extending NumericLabelProvider as it is described here:
https://www.scichart.com/documentation/android/current/webframe.html#Axis%20Labels%20-%20LabelProvider%20API.html

private class PercentLabelProvider : NumericLabelProvider
{
    public override string FormatLabel(Java.Lang.IComparable dataValue)
    {
        return string.Format("{0:P0}", dataValue);
    }
}

However, this is not possible, because FormatLabel can not be overridden.
This is the error message:
“cannot override inherited member ‘FormatterLabelProviderBase.FormatLabel(IComparable)’ because it is not marked virtual, abstract, or override”

DateLabelProvider has the same problem.

I need need to use both.

Is there a solution for this issue?

Version
Xamarin Android 3.0.0.4167
  • You must to post comments
1
0

Hi Wii O,

You need to override signature which returns IChartSequence ( it has different name because it clashes with method which returns string). We have a several examples in our demo app which shows how to create custom LabelProvider:

public class BillionsLabelProvider : NumericLabelProvider
{
    public override ICharSequence FormatLabelFormatted(IComparable dataValue)
    {
        return new String(base.FormatLabelFormatted((Double)(ComparableUtil.ToDouble(dataValue) / Math.Pow(10, 9))) + "B");
    }
}

Also you can implement ILabelFormatter interface and pass it via constructor into NumericLabelProvider/DateLabelProvider :

    class CustomLabelFormatter : Object, ILabelFormatter
    {
    public void Update(Object axis)
    {
    }

    public ICharSequence FormatLabelFormatted(double dataValue)
    {
        return new String(result);
    }

    public ICharSequence FormatCursorLabelFormatted(double dataValue)
    {
        return new String(result);
    }
    }

    xAxis.LabelProvider = new NumericLabelProvider(new CustomLabelFormatter());

There is an example in our demo as well for this approach. This approach is more suitable when you need to provide completely custom formatting, without using base implementation results.

Is this suitable for your needs?

Best regards,
Yura

  • You must to post comments
0
0

I tried to override FormatLabelFormatted() on the NumericLabelProvider, but that didn’t work because FormatLabelFormatted() was never called.

However, the second suggestion, implementing a custom ILabelFormatter and passing an instance to the NumericLabelProvider does work!

I can work with that. Thank you.

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.