Pre loader

Tag: AnnotationLabel

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

0 votes
15k views

It seems that if the axis is collapsed, all associated annotation labels are not visible (but their annotation line is visible).
Is there property or the like that will allow labels to be shown which are associated with a collapsed axis?

1 vote
11k views

Hello everyone,

I am the beginner of SciChart, now I able to create a candlestick chart with a HorizontalLineAnnotation but it doesn’t display well.

I have checked-out this tutorial

https://www.scichart.com/documentation/v5.x/webframe.html#The%20HorizontalLineAnnotation%20Type.html

I tried to convert the C# code and XML document to Kotlin but it seems there are no class AnnotationLabel found from the library.

Bellow is my screenshot

enter image description here

You can see the issue is the HorizontalLineAnnotation doesn’t contain the label (with value). What I need is it should have a label as bellow

enter image description here

Bellow is my implementation (in Kotlin)

val xAxis = sciChartBuilder.newCategoryDateAxis().build()
    val yAxis = sciChartBuilder
            .newNumericAxis()
            .build()
val currentAnnotation = sciChartBuilder
            .newHorizontalLineAnnotation()
            .withBackgroundColor(0xFFFCB51E.toInt())
            .withYValue(currentValue).build()

val rSeries = sciChartBuilder.newCandlestickSeries()
            .withStrokeUp(upColor)
            .withFillUpColor(upColor)
            .withStrokeDown(downColor)
            .withFillDownColor(downColor)
            .withDataSeries(dataSeries)
            .build()

    UpdateSuspender.using(surface) {
        Collections.addAll(surface.xAxes, xAxis)
        Collections.addAll(surface.yAxes, yAxis)
        Collections.addAll(surface.annotations, currentAnnotation)
        Collections.addAll(surface.renderableSeries, rSeries)
        Collections.addAll(surface.chartModifiers, sciChartBuilder.newModifierGroupWithDefaultModifiers().build())
    }

Can someone please help me on this?

  • Vo Hoa asked 6 years ago
  • last active 6 years ago
0 votes
8k views

We have a SciChartSurface that displays data, and includes a collection of threshold lines that can be modified by the user by dragging.
To accomplish this, we are using a class that inherits from ChartModifierBase that includes an attached property for binding an IEnumerable:

public static readonly DependencyProperty ThresholdsSourceProperty =
    DependencyProperty.Register
    (
        "ThresholdsSource",
        typeof(IEnumerable),
        typeof(CustomThresholdModifier),
        new PropertyMetadata(null, OnThresholdsSourceChanged)
     );

public IEnumerable ThresholdsSource
{
    get { return (IEnumerable)GetValue(ThresholdsSourceProperty); }
    set { SetValue(ThresholdsSourceProperty, value); }
}

The property includes a callback method (OnThresholdsSourceChanged) which is used to populate the Annotations collection of the parent SciChartSurface:

private static void OnThresholdsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    var thresholdAnnotationModifier = d as CustomThresholdModifier;
    if (thresholdAnnotationModifier != null)
    {
        var newValue = e.NewValue as IEnumerable;
        if (newValue == null) return;

        thresholdAnnotationModifier.RebuildAnnotations();
    }
}

private void RebuildAnnotations()
{
    if ((ParentSurface == null) || (ThresholdsSource == null)) return;

    var annotationCollection = ParentSurface.Annotations;
    annotationCollection.Clear();

    foreach (IThresholdViewModel item in ThresholdsSource)
    {
        var threshold = new CustomHorizontalLineAnnotation{ DataContext = item };
        annotationCollection.Add(threshold);
    }
}

When this code is run, a binding exception occurs, but not until all of the code is successful. The exception:

System.Windows.Data Error: 2 : Cannot find governing FrameworkElement
or FrameworkContentElement for target element.
BindingExpression:Path=RotationAngle; DataItem=null; target element is
‘RotateTransform’ (HashCode=28139356); target property is ‘Angle’
(type ‘Double’)

The exception is clearly thrown downstream by some WPF thread, or I’d be able to wrap a try/catch around this and have better details.

If I comment out the line that creates the CustomHorizontalLineAnnotation, no exception.
If I add a short artificial delay before the first creation of CustomHorizontalLineAnnotation, no exception.
If I set “ShowLabel” = False in the HorizontalLineAnnotation, no exception.
If I add a dummy creation of CustomHorizontalLineAnnotation in the constructor of my CustomThresholdModifier, no exception.
If I add a dummy creation of AnnotationLabel in the constructor of my CustomThresholdModifier, no exception.

In short, the root cause of the binding exception seems to be coming from the creation of an AnnotationLabel in HorizontalLineAnnotation, either through setting ShowLabel=True, or adding it to the AnnotationLabels collection of the HorizontalLineAnnotation.

Any thoughts? I’d like to use the dummy creation of AnnotationLabel in the constructor as the solution to the problem, but this feels too much like a hack, and likely wont pass muster for my team. Maybe there’s some “best practice” being violated here, in using the modifier to update the annotation on property change?

Thanks!

0 votes
8k views

I have a DateTime X Axis, to which I have added a custom label provider – namely to convert UTC display time to LocalTime.

This works just fine for the AxisLabels, but I also have vertical line annotations and they are NOT using the label provider and are thus showing UTC times.

Is there any way to make the vertical line annotations use the same label provider? Or some way to override the vertical line annotation label function to set the time to local?

Picture Attached.

0 votes
0 answers
8k views

Hello again!
I’m working with changing font properties. I have two questions:

1) Is there any way to apply such properties as FontWeight (Bold), FontStyle (UnderLine, Italic) to the text drawn in InternalDraw method (renderContext.DrawText)?

2) Also I’m using horizontalLineAnnotation with AnnotationLabels. I need to change the same properties as in the question above to the text in AnnotationLabel in code behind. Here is the code snippet to change FontWeight:

var tempAnnotationLabel = new AnnotationLabel
                {
                    Text = fluidValue.Name,
                    LabelPlacement = LabelPlacement.TopLeft,
                    FontSize = 11,
                    FontWeight = FontWeights.Bold,
                };

But when I’m displaying this horizontalLineAnnotation, FontWeight is the same as before. How can I do this?

Thanks in advance

0 votes
0 answers
6k views
.

Problem was a mistake on my side, please remove this question.

  • T0 bi asked 3 years ago
  • last active 3 years ago
0 votes
3k views

Hi,

I’m trying to convert Java code to swift and I need the AnnotationLabel’s setAxisLabelStyle equivalent.

AnnotationLabel annotationLabel = new AnnotationLabel(getContext());
annotationLabel.setLabelPlacement(LabelPlacement.Axis);

            annotationLabel.setAxisLabelStyle(new Action1<AnnotationLabel>()
            {
                @Override
                public void execute(AnnotationLabel annotationLabel)
                {
                    annotationLabel.setFontStyle(new FontStyle(37.0f, Color.BLUE));
                    annotationLabel.setBackgroundResource(R.drawable.current_price);
                }
            });

How can i apply this code in swift?

Showing 7 results

Try SciChart Today

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

Start TrialCase Studies