Pre loader

Get 'is not a valid Comparable Type' exception when programmatically adding VerticalLineAnnotation to WPF chart

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
0

I’m adding an annotation to a chart with a DateTime x-axis. Without a label the annotation is successfully added. However, if I specify a label I get an InvalidOperationException when Add() is called. The exception message is “The Type this is a test is not a valid Comparable Type”}:

                var annotation = new VerticalLineAnnotation
                {
                    VerticalAlignment = VerticalAlignment.Stretch,
                    ShowLabel = true,
                    X1 = time.DateTime,
                    Stroke = System.Windows.Media.Brushes.Orange,
                    LabelPlacement = LabelPlacement.TopRight,
                    LabelValue = "this is a test",
                    LabelsOrientation = Orientation.Vertical
                };

                MyChart.Annotations.Add(annotation);

The LabelValue is obviously of type string and non-null and indeed of type IComparable. Any reason I can’t add it?

Version
4.2.2.9777
  • You must to post comments
0
0

I had the same issue as Dan, wanting to display a non-date string when using a DateTime X axis. The workaround of adding child AnnotationLabels doesn’t work when using the view model, i.e. VerticalLineAnnotationViewModel. No labels appear.

An alternative workaround is to use the LabelTextFormatting property to assign your desired text – you may want to escape some or all of it (single quotes) to prevent it being parsed as a DateTime format string.
E.g. if setting in code

vm.LabelTextFormatting = "'My desired label'";

or equivalent if setting in XAML.

  • You must to post comments
0
0

I am considering applying server-side licensing for my javerScript application.

In the document below, there is a phrase “Our server-side licensing component is written in C++.”
(https://support-dev.scichart.com/index.php?/Knowledgebase/Article/View/17256/42/)

However, there is only asp.net sample code on the provided github.
(https://github.com/ABTSoftware/SciChart.JS.Examples/tree/master/Sandbox/demo-dotnet-server-licensing)

I wonder if there is a sample code implemented in C++ for server-side licensing.

Can you provide c++ sample code?
Also, are there any examples to run on Ubuntu?

  • Dan Pilat
    For example, the vertical line appears, but not the text: annotation = new VerticalLineAnnotation { VerticalAlignment = annotation.VerticalAlignment, ShowLabel = false, X1 = time.DateTime, Stroke = Brushes.Orange }; annotation.Content = new AnnotationLabel { LabelPlacement = LabelPlacement.TopLeft, Text = measurement.Annotation };
  • Andrew Burnett-Thompson
    I have actually tried the above in v4.2.x Annotations are Easy example by modifying the VerticalLineAnnotation which already has a child AnnotationLabel. Try it in the example, Maybe the Code behind translation isn’t correct
  • Dan Pilat
    I have to create annotations dynamically – but I’ll see about making it a resource so at least it’s declared in xaml. I find it interesting that the example can set the label to a string. How is that so given the IComparable restriction you mentioned before?
  • Andrew Burnett-Thompson
    Because VerticalLineAnnotation.LabelValue must be numeric, but AnnotationLabel.LabelValue accepts a formatted string. Before you do any big changes — test it out. See if it works.
  • Dan Pilat
    I was referring to line 69 of the “Annotations are Easy” example that sets a HorizontalLineAnnotation LabelValue property to a string value. …HorizontalLineAnnotation HorizontalAlignment=”Right” FontSize=”12″ FontWeight=”Bold” LabelPlacement=”TopLeft” LabelValue=”Right Aligned, with text on left”… By the way, it isn’t the Content property that’s set, but rather the AnnotationLabels property that gets initialized via xaml. I got everything working by simply declaring my annotations using xaml resources.
Showing 2 results
Your Answer

Please first to submit.

Try SciChart Today

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

Start TrialCase Studies