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


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


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

  • You must to post comments

Hi Dan,

The VerticalLineAnnotation.LabelValue is expecting a numeric value of IComparable. Unfortunately there is no interface in .NET for IComparableExceptForString 🙂 so we had to use the lowest common denominator interface (IComparable) and hope nobody set the value to a string, or custom class .. Values such as 1.234, or ’22 MAR 2016′ will be valid and will be parsed, but string values won’t.

If you want to place a string value on a VerticalLineAnnotation Axis Label, you can use this code.

    <s:VerticalLineAnnotation VerticalAlignment="Stretch"
            <s:AnnotationLabel LabelPlacement="Axis" Text="Hello Thar!"  />

Best regards,

  • 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
    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
    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 1 result
Your Answer

Please first to submit.