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

0
0

Hi,

A problem appears changing Axis Alignment if Annotations exists, look this simple example:

NumericAxis x, y;
    SciChartSurface c;
    public Sci()
    {
        InitializeComponent();

        c = new SciChartSurface();


        c.XAxes.Add(x = new NumericAxis() { Id = "x" });
        c.YAxes.Add(y = new NumericAxis() { Id = "y" });

        //some limits
        y.VisibleRange = new DoubleRange(-5, 5);
        y.VisibleRangeLimitMode = RangeClipMode.MinMax;

        //a series
        var s = new FastLineRenderableSeries() { XAxisId="x", YAxisId="y"};
        c.RenderableSeries.Add(s);

        //some datapoints
        var ds = new XyDataSeries<double>();
        ds.Append(1, 1);
        ds.Append(2, 2);
        ds.Append(3, 1);
        ds.Append(4, 2);
        s.DataSeries = ds;

        //Add an annotation
        var a = new HorizontalLineAnnotation() { Y1 = 1.5d, YAxisId = "y", Stroke = Brushes.Red, StrokeThickness = 1 };
        c.Annotations.Add(a);

        //appending the chart on a grid
        mG.Children.Add(c);


    }

If you run it all works good. Now, add a button that flip chart, with this code:

private void Button_Click(object sender, RoutedEventArgs e)
    {
        c.Annotations.Clear();

        if (x.AxisAlignment == AxisAlignment.Left)
        {
            x.AxisAlignment = AxisAlignment.Bottom;
            y.AxisAlignment = AxisAlignment.Left;

            var a = new HorizontalLineAnnotation() { Y1 = 1.5d, YAxisId = "y", Stroke = Brushes.Red, StrokeThickness = 1 };
            c.Annotations.Add(a);
        }
        else
        {
            x.AxisAlignment = AxisAlignment.Left;
            y.AxisAlignment = AxisAlignment.Bottom;


            var a = new VerticalLineAnnotation() { Y1 = 1.5d, YAxisId = "y", Stroke = Brushes.Red, StrokeThickness = 1 };
            c.Annotations.Add(a);
        }

    }

Now nothing works good…
Can you solve it?

Thanks.
marc.

Version
5.2.0.11680
  • You must to post comments
0
0

The previous post is mine, with the uncorrect user.
Sorry.
marc.

  • You must to post comments
0
0

Hi Marc, you must specify both XAxisId and YAxisId for annotations where custom axis IDs are used (even Horizontal / VerticalLineAnnotation)

Can you try that and let me know if it works?

Best regards
Andrew

  • You must to post comments
0
0

Hi,

thanks very much, now it works perfectly.

A little suggestion for the future.
SciCharts have a really good architecture that allow to works without troubles.
Horizontal and Verttical line annotationds, contrariwise, are a little bit annoying.
This is because “Horizontal” and “Vertical” is depending on axis positions and, as in my case, I must assign an unknow secondary axys that don’t play any role.
I’ve writed a wrapper that change annotations when axes move, but a really good solution would be a generic AxisLineAnnotation that:

  • Is linked to his Axis and so it is vertical or horizontal depending on axis position
  • It require a secondary axys only if we want to set secondary informations (i.e. the length of the annotation)

Thanks
marc.

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.