Pre loader

Tag: LabelProvider

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

1 vote
18k views

Hi

I want to override the default AxisLabelTemplate for a DateTimeAxis beyond the normal circumstances.
Setting the AxisLabelTemplate to a StaticResource is easy enough, but all I have inside the Template is the CursorFormattedDataValue and I want to be able to send in something more then a simple string.

<ControlTemplate x:Key="RolloverModifierAxisLabelTemplateDefault">
    <Border Background="LightGray" 
            Opacity="0.80" 
            BorderThickness="0"
            CornerRadius="5"
            Padding="2"
            Visibility="{Binding IsXAxis, Converter={StaticResource BoolToVisibilityConverter}}">
        <TextBlock Text="{Binding CursorFormattedDataValue}" />
    </Border>
</ControlTemplate>

Extending the LabelProviderBase gives me the opportunity to override the FormatCursorLabel method, but it only returns a string and not an object and therefore I can not pass my own data structure to be used inside the AxisLabelTemplate.

How can we solve this issue? Is there a workaround, or is this something you need to implement?

0 votes
8k views

If I make my own implementation of AxisLabelprovider for a CategoryDatetimeAxis I get different DateTime.Kind settings depending on the function called to format a label.
I put in the values as DateTime.Kind = DateTimeKind.Utc to the DataSeries<DateTime, double>

I have this implementation for my labelprovider:

public class CategoryAxisLabelProvider : TradeChartAxisLabelProvider

    public override string FormatLabel(IComparable dataValue)
    {
        DateTime value = (DateTime)Convert.ChangeType(dataValue, typeof(DateTime));
        if (value.Kind != DateTimeKind.Local)
        {
            value = value.ToLocalTime();
        }

        string s = value.ToString("HH:mm:ss\nfff 'ms'");
        return s;
    }

    public override string FormatCursorLabel(IComparable dataValue)
    {
        // do something
    }

If FormatCursorLabel is called the “dataValue” has DateTime.Kind = DateTimeKind.Utc.
If FormatLabel is called the “dataValue” has Datetime.Kind = DateTimeKind.Unspecified. (Although the value is UTC)

How to handle DateTimeKind.Unspecified? Is it Utc or does it depend on what I put into the dataseries?

  • Uwe Hafner asked 9 years ago
  • last active 9 years ago
0 votes
7k views

How can I create CustomCategoryLabelProvider?
How can i do this?
This example does not work for me

1 vote
12k views

Hi, I want to color the axis label by its value,

eg.
value < 0 -> show red color
value = 0 -> show gray color
value > 0 -> show green color

similar to this question, but in javascript platform, it seems the LabelProvider has function related to the value(string) formatting only. Is there any ways to styling the label? Thanks!

0 votes
7k views

Is there a way to provide custom text for the labels in a PieChartSegment? I want to format the text, but haven’t been able to find a label formatter for the pie charts.

0 votes
6k views

I have a simple line renderable series in iOS with an SCIDateTimeAxis for X and an SCINumericAxis for Y. At this point all I’m trying to do is format the Y-axis labels and cursor labels as currency. According to the documentation, this should be as simple as:

yAxis.textFormatting = "$%f"

But it does not appear to properly use this formatting. The Y-axis is showing values like “$%f1400” when formatting a value for 14.

So, I instead attempted creating my own label provider by overriding SCINumericLabelProvider:

class CurrencyLabelProvider: SCINumericLabelProvider {

static let formatter: NumberFormatter = {
    let formatter = NumberFormatter()
    formatter.numberStyle = .currency
    return formatter
}()

override func formatLabel(_ dataValue: SCIGenericType) -> NSAttributedString! {
    let value = dataValue.doubleData
    let string = CurrencyLabelProvider.formatter.string(from: NSNumber(value: value))!
    return NSAttributedString(string: string)
}
}

Then assigning:

yAxis.labelProvider = CurrencyLabelProvider()

This works to properly format the axis labels. So, I also override SCINumericLabelProvider to provide the cursor labels:

 override func formatCursorLabel(_ dataValue: SCIGenericType) -> NSAttributedString! {
    let value = dataValue.doubleData
    let string = CurrencyLabelFormatter.formatter.string(from: NSNumber(value: value))!
    return NSAttributedString(string: string)
}

This then properly formats the cursor label for the Y-axis- but it also formats the X-axis cursor:
Formatted Cursor

At this point, the X-axis is already assigned an SCIDateTimeLabelProvider- the X-axis is not assigned CurrencyLabelProvider. But it seems to be overridden by the Y-axis label provider or simply unused. The X-axis labels are formatted as dates properly, but X-axis cursor values are just numbers when not being interfered with by the Y-axis label provider.

Am I misunderstanding something or are these all bugs in the iOS SDK? We’re currently evaluating whether this package will meet our needs and it certainly appears to be riddled with issues.

  • Sean Young asked 5 years ago
  • last active 5 years ago
0 votes
7k views

I’m using Xamarin.iOS and the SciChart.iOS NuGet. When adding a LabelProvider to an axis the iPhoneSimulator with iOS 13.2 crashes without warning or exception back to the phone menu. This issue is not present on Android using the same API usage pattern.

This effect is not just in my own apps but can be replicated by running the latest Examples app on the same simulator. Examples which demonstrate the same behaviour include “Custom Theme”, Stacked Column Side by Side Chart”, “Using Theme Manager”, all of which set the LabelProvider in the source code.

Is this a known bug? Maybe an incompatibility with the latest version of Xamarin.iOS.

I noticed that this issue has been reported before.

This is a deal breaker for us at the moment as formatting axis labels is pretty crucial.

1 vote
10k views

Hi!

I have 2 solutions of xamarin forms using scichart: one of them is the demo from github repo of scichart (2.2.1.839), and the other is my own solution using scichart 2.5.0.946.

The problem is when I attach a labelprovider (the same as the github example) to one of my numerical axes, the app automatically closes on the device (both), neither of the two solutions shows an error or exception.

0 votes
8k views

I am trying to implement a waterfall chart with uniform heatmap. The data is updated from the top of the chart and keeps pushing the old data down. I would like to show the y-axis with time. How can I update the y-axis with updated data?

Assume the heatmap is 256 height, I created the zValues array with min value when draw the heatmap:

const SPECTROGRAM_WIDTH = 256; 
const minPower = -200;
spectrogramZValues.current = Array.from(Array(SPECTROGRAM_HEIGHT), () => Array(SPECTROGRAM_WIDTH).fill(minPower));

Update zValues array when new data come:

    spectrogramZValues.current.shift();
        spectrogramZValues.current.push(newData);

When the first data pushed to the chart. There will be one row shown in the axis with timestamp t1. When the second data comes, the top row of the y-axis should be t2 and the t1 is pushed down. When the waterfall chart is filled with 256 data, the bottom of the y-axis should be t1 and the top of the y-axis should be t256. Is it possible to implement this?

Now I am using the uniform heatmap to implement it with yStart=0 and yStep=1. I tried to add the labelProvider to the y-axis to show the timestamp of each row. I am keeping an array locally to store the timestamp of each row which will be updated with the new data. I tried to map this array and return the timestamp in the y-axis labelProvider. But it doesn’t work. The y-axis will not be refreshed when data updated.

        yAxis.labelProvider.formatLabel = (dataValue) => {
        const ts = timestampArray[dataValue];
        if (ts) {
            const timeObj = new Date(ts);
            const hours = ('0' + timeObj.getHours()).slice(-2);
            const minutes = ('0' + timeObj.getMinutes()).slice(-2);
            const seconds = ('0' + timeObj.getSeconds()).slice(-2);
            const milliseconds = ('0' + timeObj.getMilliseconds()).slice(-3);
            return `${hours}:${minutes}:${seconds}.${milliseconds}`;
        } else {
            return "";
        }
    };
  • Quyen Sy asked 11 months ago
  • last active 10 months ago
0 votes
7k views

In example https://www.scichart.com/example/wpf-chart-example-stacked-column-side-by-side/ there is a LabelProvider with hardcoded labels. How can I bind it to a collection of Labels?

0 votes
11k views

Hi guys,

I have some troubles with piecharts in swift. I want to provide custom labels outside of the piecharts segments. I found a screenshot of a nested piechart attached to an issue in your issue tracker. Thats what I want to do in swift, but I couldn’t find out a way to do so. Could you please provide an example code?

Thanks a lot in advance!
Alex

0 votes
9k views

I would like to implement a custom DateTime axis LabelProvider with the following behavior:

  • Show full date and time at the start of the visible region
  • Show only time on all other ticks unless the date changes from the previous tick.

So, an axis might look like:

10/01/2016 23:00 23:30 10/02 00:00 00:30 01:00

It seems this is doable as long as 00:00:00 appears as one of the label values, but I’m not sure l can be guaranteed. It is likely that none of the entries in the series would contain that exact value. One entry might be 23:59:17 and the next 00:01:13.

Is there any way for a LabelProvider to determine what the preceding label value was?

Bill

0 votes
12k views

Hi there,

I’m trying to display little icons as axis labels using the LabelProvider API and NSAttributedString (with NSTextAttachmet). Is this supported? Here’s a minimal example:

import UIKit
import Foundation
import SciChart
import SciChart.Protected.SCILabelProviderBase

class ViewController: UIViewController {

    private lazy var chart: SCIChartSurface = {
        let c = SCIChartSurface(frame: .zero)
        c.xAxes.add(items: SCINumericAxis())

        let yAxis = SCINumericAxis()
        yAxis.labelProvider = SymbolLabelProvider()
        c.yAxes.add(items: yAxis)
        return c
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

        SCIChartSurface.setRuntimeLicenseKey(myLicenseKey)

        view.addSubview(chart)
        chart.translatesAutoresizingMaskIntoConstraints = false
        let guide = self.view.safeAreaLayoutGuide
        NSLayoutConstraint.activate([
            chart.leadingAnchor.constraint(equalTo: guide.leadingAnchor),
            chart.trailingAnchor.constraint(equalTo: guide.trailingAnchor),
            chart.topAnchor.constraint(equalTo: guide.topAnchor),
            chart.bottomAnchor.constraint(equalTo: guide.bottomAnchor),
        ])
    }
}

class SymbolLabelProvider: SCILabelProviderBase<SCINumericAxis> {

    lazy var numberFormatter: NumberFormatter = {
        let f = NumberFormatter()
        f.allowsFloats = true
        f.maximumFractionDigits = 2
        return f
    }()

    init() {
        super.init(axisType: ISCINumericAxis.self)
    }

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

        let intValue = Int(dataValue.toDouble())
        let font = UIFont.init(descriptor: axis.tickLabelStyle.fontDescriptor, size: UIFont.systemFontSize * 4)

        if intValue.isMultiple(of: 2) {
            let i = UIImage(systemName: "circle", withConfiguration: UIImage.SymbolConfiguration(font: font))
            return NSAttributedString(attachment: NSTextAttachment(image: i!))
        } else {
            let attributes: [NSAttributedString.Key: Any] = [
                .font: font,
                .foregroundColor: UIColor.yellow,
            ]
            return NSAttributedString(string: numberFormatter.string(for: dataValue.toDouble())!, attributes: attributes)
        }
    }
}

See attached screenshot for the result.

If this is not supported: any suggestions / ideas for a workaround?

Thanks
—Matthias

1 vote
10k views

I am using the 2D Heatmap with text as my working prototype. I wish to have a secondary Axis on the opposite side of my man Axis that displays a count for that row or column. To display this information is simple enough through using the LabelProvider (although two lines maybe a bit tricky), and I can do some stuff with the TickProvider when it gets a bit too busy.

My question is on how I can position these TickLabels to be in the center of a row/column?

My first thought was I could be cheeky and set the margin value to offset it in its style but it seems it only works so far with the TickLabel just displayed below the tick.

        <Style x:Key="LeftAxisLabelStyle" TargetType="s:NumericTickLabel">
                   <Setter Property="Margin" Value="0,0,0,-30"/>
        </Style>

enter image description here

What I am trying to achieve seems to be the default positioning for column charts, and histograms. I was wondering if there is a behind the scenes option or an override I’ve missed to set this?

Alternatively annotations maybe the way to go but I get the impression that this is more for on chart labels rather than for Axis?

p.s. I think when dealing with multiple Axes, you should give an warning/error if an “Id” is not given to secondary Axis as the graph will just show blank.

0 votes
0 answers
10k views

I’m using the YAxes property of the chart to data bind to a collection of NumericAxisViewModels. Is there a way to rotate the tick labels in this scenario. I can’t define a style in XAML and then assign it to the Axis because the axis is created in scichart somewhere. All I have is the axis view model. I have a LabelProvider but it doesn’t seem to support rotation unless I access the ParentAxis. Ultimately I would like to rotate some vertical axis and not other but I might be able to live with rotating all of them.

I have tried defining a style in xaml that applies to all numeric axis but it didn’t work:

<Style TargetType="{x:Type s:DefaultTickLabel}">
        <Setter Property="LayoutTransform">
            <Setter.Value>
                <RotateTransform Angle="-90"/>
            </Setter.Value>
        </Setter>
    </Style>

Adding a LabelProvider sort of works but seems a little hacky and doesn’t set the scale appropriately ( I have to zoom to extends to see the labels). Is this the way I am supposed to do it?

public override string FormatLabel(IComparable dataValue) {
        var style = new Style(typeof(DefaultTickLabel));
        style.Setters.Add(new Setter(DefaultTickLabel.LayoutTransformProperty, new  RotateTransform(-90.0)));
        ParentAxis.TickLabelStyle = style;
0 votes
8k views

Hello SciChart team,

How do I serialize custom tick placement and labels, generated by TickProviderAPI and LabelProvider? Actually, the main problem is that I need to export high quality (i.e. higher than actual figure size on screen) PNG images in MVVM application and method ExportToFile(fileName, ExportType.Png, false, new Size(…, …)) produces axis ticks and labels as if they were controled by original MinorDelta and MajorDelta parameters. ExportToFile() without size parameter produces output correctly, so that must be due to not-serialized TickProvider and LabeProvider properties (?), which in exported serialized surface string does not exist.

Thank you!

1 vote
5k views

I need to export a load of images from one graph. Export from the View is very long. So, I’ve implemented the export in memory like in this example:
https://support.scichart.com/index.php?/Knowledgebase/Article/View/17213/34/rendering-chart-to-bitmap-in-memory

Export is fast and flexible. One of my axes has a custom label provider, but I see a default axis labels after export. Export from View gives correct label values. Here is the code of the label provider:

public class MyCustomLabelProvider: NumericLabelProvider
{

    public override string FormatLabel(IComparable dataValue)
    {
        return string.Format("{0:" + this.ParentAxis.TextFormatting + "}", 1 / (double)dataValue);
    }

    public override string FormatCursorLabel(IComparable dataValue)
    {
        return string.Format("{0:" + this.ParentAxis.TextFormatting + "}", 1 / (double)dataValue);
    }
}

And a code of export:

    var sciChartSurface = new SciChartSurface();
    ThemeManager.SetTheme(sciChartSurface, "BrightSpark");
    sciChartSurface.YAxes = new AxisCollection()
    {
        new NumericAxis()
        {
            AxisAlignment = AxisAlignment.Left,
            VisibleRangeLimitMode = RangeClipMode.MinMax,
            LabelProvider = new MyCustomLabelProvider(),
            DrawMajorGridLines = false,
            DrawMinorGridLines = false,
            DrawMajorBands = false,
        }
    };
    sciChartSurface.XAxes = new AxisCollection()
    {
        new NumericAxis()
        {
            AxisAlignment = AxisAlignment.Bottom,
            LabelProvider = new CurvatureLabelProvider(),
            VisibleRangeLimitMode = RangeClipMode.MinMax,
            DrawMajorGridLines = false,
            DrawMinorGridLines = false,
            DrawMajorBands = false
        }
    };

    sciChartSurface.RenderableSeries = new ObservableCollection<IRenderableSeries>()
    {
        new FastLineRenderableSeries() { DataSeries = lineSeries, Stroke = Colors.Green }
    };

    ...

    sciChartSurface.XAxes.FirstOrDefault().VisibleRange = new DoubleRange(0, 100);
    sciChartSurface.ExportToFile(Path.Combine(folderPath, $"Object.png"), ExportType.Png, false, new Size(1500, 750));

Any suggestions?

0 votes
8k views

Hi there,

I recently realized that since upgrading to scichart version 5 my custom label provider has stopped working. With version 4 it has always been working fine.

The interesting thing is that the custom label provider works fine when making use of a “standard” NumericAxisViewModel:

IAxisViewModel newAxis = new NumericAxisViewModel ();
newAxis.TickProvider = new CustomTickProvider();
newAxis.LabelProvider = new CustomLabelProvider();

When applying the same logic to a LogarithmicNumericAxisViewModel however, the label providers “FormatLabel” is never called and so no custom labels are shown:

IAxisViewModel newAxis = new LogarithmicNumericAxisViewModel();
newAxis.TickProvider = new CustomTickProvider();
newAxis.LabelProvider = new CustomLabelProvider();

After doing some research I found out that the labelprovider is never attachd to the IAxisCore as the Init function of the labelprovider is never called when its set as the labelprovider of LogarithmicNumericAxisViewModel. (When its attached to a NumericAxisViewModel it is properly called). I suspect there’s bug somewhere in the LogarithmicNumericAxisViewModel that causes this unexpected behavior.

Any help would be appreciated.

Thanks in advance,

Mathieu.

0 votes
8k views

Hi

I would like to modify the DateTimeAxis to have the date shown static below the time.
Currently I can’t figure out how to code something like that.

The basic idea is to have the date label

a) on the left and right of the date axis and moving with midnight
b) as bar below the time stamp

Is it possible to modify the DateTimeAxis to achieve both use cases?

To visualize, what I’m trying to achieve find some mocks below (neglect the time, midnight just moved to 18:19:30 :-))

0 votes
5k views

Hi!

I have a chart that display time-series data and sometimes I have a few minutes of data, other times I have hours. All of the data points are taken every minutes. The X-Axis starts at 0 minutes and progresses from there.

My goal is to have the Axis Title say “Minutes” if there are < 120 points of data. If there are > 120 points of data then I want the Axis to be titled “Hours” and then divide the X-Axis label by 60.

I’ve started with this: https://www.scichart.com/documentation/v5.x/webframe.html#Axis%20Labels%20-%20LabelProvider%20API.html

and it’s doing about what I expect. I check the AxisCore’s Range and if the range is > 120 I set the AxisCore.AxisTitle to “Hours”, otherwise “Minutes”. So far so good.

The problem is that doing it this way means I have labels such as “48.333333” for the hours.

If, on the other hand, when I create the XYSeries that I’m plotting I pass in the already-divided-by-60 values, SciChart seems to select whole numbers so instead of showing me something like “48.333333” it would either show me “48” or it would use 50 or another whole number for the tick marks.

So my question: Is this doable by just writing a custom LabelProvider? Do I need to write a custom Axis class instead? Or somehow tell the Axis that’s in-use to recalibrate itself by dividing all of the elements by 60 before computing tick marks?

In the images I’m attaching, one plot shows me plotting a series where when I create series the x-value is being divided by 60 before I call .Append() on the series. The other one shows what happens when I use my custom LabelProvider and divide by 60 when the Axis label is drawn.

Thanks!

-David

0 votes
3k views

Hello,

On our SciChart’s XAxis we are using a NumericAxis and within the NumericAxis we bind to a LabelProvider. In the UI, this works perfectly and we get the XAxis appearing with the titles we desire (as strings writing over the numeric values 0, 1, 2, …). Meanwhile the YAxis doesn’t use any LabelProvider and stays numeric. The XAxis.LabelProvider is an IList of strings.

Although this works great in the UI, when I export the SciChart it does not pick up the LabelProvider and the exported image only contains the numeric values 0, 1, 2, … on the XAxis.

I do the export as following:

SciChartSurfaceBase.ExportToFile(filename, SciChart.Core.ExportType.Png, useXamlRenderSurface, exportedSize);

Is there a way to get the ExportToFile command to acknowledge the LabelProvider is there like it does with the UI?

Thank you!
Hannah

0 votes
6k views

We are using NumericAxis for the y-axis and x-axis of a bar chart. The x-axis uses a LabelProvider (to convert integers to strings) and a TickLabelStyle (to rotate the label by 270 degrees so it is vertical going from the bottom to the top). We find that sometimes the y-axis is not drawn (however, it will be drawn if the chart is resized or re-painted).

The work-around to the problem is adding spaces to the front of the shorter labels so all of the labels are all the same length. However, this work-around does not work for every case.

Have you seen this issue before and is there a better solution? Thanks!

0 votes
3k views

I have a custom LabelProvider and TickProvider implemented for my X axis. In general the label culling works fine, but sometimes it shows the first tick label and starts culling with the second, and other times it starts with the first tick label immediately. I would like to always show the first tick label, and then cull from that point. Is this possible?

I found this post from 5 years ago, which indicates I would need to do the culling myself, but was hoping maybe there have been some updates on this?

https://www.scichart.com/questions/wpf/always-show-visiberange-minmax-labels-on-x-axis

1 vote
0 answers
1k views

Hello,
I am trying to generate a graph where the ticks and the labels will be added from TickProvier and LabelProvider. But when there is not enough space, it doesn’t show most of the labels, where it can only skip one label in the middle of two labels (Please check the attached photo). I can not set IsLabelCullingEnabled = true as I do not want any overlap on labels.

I have shared a sample project. Here, I always want to show all the ticks generated from the TickProvider. But how can I handle the labels, so that I can decide inside LabelProvider(Or any other place) if I should set a label empty or not based on the previous label position?

Showing 24 results

Try SciChart Today

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

Start TrialCase Studies