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

0
0

Hi,

this is my scenario: I want to create a “band annotation”, a stretched box with some text.
I can use Text annotation but I want that annotation stretch in some directions.

In example, X1 = extreme left (as X1=0 in relative mode), X2 = Some X Axis Value, Y1 = Some Y Axis Value, Y2= Some Y Axis Value. This is a band without definite X1 value.

Or: X1 = Some axis value, Y1 = Some Axis Value, X2 = extreme right, Y2=Extreme Bottom, this is a rectangle that stretch to the bottom right corner.

At the end I must place a text in the center of box.

Can you help me?

Thank’s
marc.

Version
v4.0.30319
  • You must to post comments
0
0

Solved by myself:`var ta = new SciChart.Charting.Visuals.Annotations.BoxAnnotation();

            ta.AnnotationCanvas = SciChart.Charting.Visuals.Annotations.AnnotationCanvas.BelowChart;
            ta.Background = new SolidColorBrush(Common.Color.FromArgb((int)r["Color"]));
            ta.XAxisId = c.Axes[0].UI.Id;
            ta.YAxisId = c.Axes[1].UI.Id;
            c.UI.Annotations.Add(ta);

            if (depth.HasValue) ta.X1 = depth.Value;
            else BindingOperations.SetBinding(ta, SciChart.Charting.Visuals.Annotations.BoxAnnotation.X1Property, new Binding("VisibleRange") { Source = c.Axes[0].UI, Converter = new RangeConverter(true) });

            if (depthto.HasValue) ta.X2 = depthto.Value;
            else BindingOperations.SetBinding(ta, SciChart.Charting.Visuals.Annotations.BoxAnnotation.X2Property, new Binding("VisibleRange") { Source = c.Axes[0].UI, Converter = new RangeConverter(false) });

            if (value.HasValue) ta.Y1 = value.Value;
            else BindingOperations.SetBinding(ta, SciChart.Charting.Visuals.Annotations.BoxAnnotation.Y1Property, new Binding("VisibleRange") { Source = c.Axes[1].UI, Converter = new RangeConverter(true) });

            if (valueto.HasValue) ta.Y2 = valueto.Value;
            else BindingOperations.SetBinding(ta, SciChart.Charting.Visuals.Annotations.BoxAnnotation.Y2Property, new Binding("VisibleRange") { Source = c.Axes[1].UI, Converter = new RangeConverter(false) });

            var ct = new ControlTemplate(typeof(SciChart.Charting.Visuals.Annotations.BoxAnnotation));
            var ef = new FrameworkElementFactory(typeof(Border));
            ef.Name = "PART_BoxAnnotationRoot";
            ef.SetValue(Border.MarginProperty, new TemplateBindingExtension(Border.MarginProperty));
            ef.SetValue(Border.BackgroundProperty, new TemplateBindingExtension(Border.BackgroundProperty));
            ef.SetValue(Border.BorderBrushProperty, new TemplateBindingExtension(Border.BorderBrushProperty));
            ef.SetValue(Border.BorderThicknessProperty, new TemplateBindingExtension(Border.BorderThicknessProperty));
            ef.SetValue(Border.CornerRadiusProperty, new TemplateBindingExtension(Border.CornerRadiusProperty));

            var tb = new FrameworkElementFactory(typeof(TextBlock));
            tb.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
            tb.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
            tb.SetValue(TextBlock.TextProperty, r["Text"].ToString());
            ef.AppendChild(tb);

            ct.VisualTree = ef;
            ta.Template = ct;`
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.