Completed
Last Updated: 23 Nov 2018 11:34 by Dimitar
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 19 Nov 2018 14:21
Category: ChartView
Type: Bug Report
2
FIX. RadChartView - CartesianGridLineAnnotation.BackColor is not respected when drawing the label for the grid line
To reproduce:
            WaterfallSeries series = new WaterfallSeries();
            series.ShowLabels = true;

            series.DataPoints.Add(new WaterfallDataPoint(50000, false, false, "Beginning\nBalance"));
            series.DataPoints.Add(new WaterfallDataPoint(17000, false, false, "Jan"));
            series.DataPoints.Add(new WaterfallDataPoint(14000, false, false, "Feb"));
            series.DataPoints.Add(new WaterfallDataPoint(-12000, false, false, "Mar"));
            series.DataPoints.Add(new WaterfallDataPoint(69000, true, false, "Q1"));
            series.DataPoints.Add(new WaterfallDataPoint(-22000, false, false, "Apr"));
            series.DataPoints.Add(new WaterfallDataPoint(-18000, false, false, "May"));
            series.DataPoints.Add(new WaterfallDataPoint(500, false, false, "Jun"));
            series.DataPoints.Add(new WaterfallDataPoint(-30000, true, false, "Q2"));
            series.DataPoints.Add(new WaterfallDataPoint(39000, false, true, "Ending\nBalance"));
            this.radChartView1.Series.Add(series);

            CartesianGridLineAnnotation annotation1 = new CartesianGridLineAnnotation();
            annotation1.Label = "Annotation";
            annotation1.ForeColor = Color.Lime;
            annotation1.BackColor = Color.Black;
            this.radChartView1.Annotations.Add(annotation1);

Workaround:

        public RadForm1()
        {
            InitializeComponent();
            this.radChartView1.CreateRenderer += radChartView1_CreateRenderer;

            WaterfallSeries series = new WaterfallSeries();
            series.ShowLabels = true;
     
            series.DataPoints.Add(new WaterfallDataPoint(50000, false, false, "Beginning\nBalance"));
            series.DataPoints.Add(new WaterfallDataPoint(17000, false, false, "Jan"));
            series.DataPoints.Add(new WaterfallDataPoint(14000, false, false, "Feb"));
            series.DataPoints.Add(new WaterfallDataPoint(-12000, false, false, "Mar"));
            series.DataPoints.Add(new WaterfallDataPoint(69000, true, false, "Q1"));
            series.DataPoints.Add(new WaterfallDataPoint(-22000, false, false, "Apr"));
            series.DataPoints.Add(new WaterfallDataPoint(-18000, false, false, "May"));
            series.DataPoints.Add(new WaterfallDataPoint(500, false, false, "Jun"));
            series.DataPoints.Add(new WaterfallDataPoint(-30000, true, false, "Q2"));
            series.DataPoints.Add(new WaterfallDataPoint(39000, false, true, "Ending\nBalance"));
            this.radChartView1.Series.Add(series);
 
            CartesianGridLineAnnotation annotation1 = new CartesianGridLineAnnotation();
            annotation1.Label = "Annotation";
            annotation1.ForeColor = Color.Lime;
            annotation1.BackColor = Color.Black;
            annotation1.PositonOffset = new SizeF(0, -20);
            annotation1.Axis = this.radChartView1.Axes[1] as CartesianAxis;
            annotation1.Value = 70000;
            annotation1.BorderColor = Color.Red;
            annotation1.BorderDashStyle = DashStyle.Solid;
            annotation1.BorderWidth = 1;
            this.radChartView1.Annotations.Add(annotation1);
        }

        private void radChartView1_CreateRenderer(object sender, ChartViewCreateRendererEventArgs e)
        {
            e.Renderer = new CustomCartesianRenderer(e.Area as CartesianArea);
        }
 
        public class CustomCartesianRenderer : CartesianRenderer
        {
            public CustomCartesianRenderer(CartesianArea area) : base(area)
            {
            }
 
            protected override void Initialize()
            {
                base.Initialize();
                for (int i = 0; i <= this.DrawParts.Count - 1; i++)
                {
                    CartesianGridLineAnnotationDrawPart annotationPart = this.DrawParts[i] as CartesianGridLineAnnotationDrawPart;
                    if (annotationPart != null)
                    {
                        this.DrawParts[i] = new CustomCartesianGridLineAnnotationDrawPart((CartesianGridLineAnnotation)annotationPart.Element, this);
                    }
                }
            }
        }

        public class CustomCartesianGridLineAnnotationDrawPart : CartesianGridLineAnnotationDrawPart
        {
            public CustomCartesianGridLineAnnotationDrawPart(CartesianGridLineAnnotation element, CartesianRenderer renderer) : base(element, renderer)
            {
            }

            public override void Draw()
            {
                FieldInfo fi = typeof(CartesianGridLineAnnotation).GetField("model", BindingFlags.NonPublic | BindingFlags.Instance);
                ChartAnnotationModel model = fi.GetValue(this.Element) as ChartAnnotationModel;
                RectangleF
                rect = ChartRenderer.ToRectangleF(model.LayoutSlot);
                rect.Offset(this.ViewportOffsetX, this.ViewportOffsetY);

                Graphics graphics = this.Renderer.Surface as Graphics;
                RadGdiGraphics radGraphics = new RadGdiGraphics(graphics);

                Rectangle clipRect = ChartRenderer.ToRectangle(this.Element.View.GetArea<CartesianArea>().AreaModel.PlotArea.LayoutSlot);
                clipRect.Offset((int)this.ViewportOffsetX, (int)this.ViewportOffsetY);
                graphics.SetClip(clipRect);

                GraphicsPath path = new GraphicsPath();
                path.AddLine(rect.Location, new PointF(rect.Right, rect.Bottom));

                BorderPrimitiveImpl border = new BorderPrimitiveImpl(this.Element, null);
                border.PaintBorder(radGraphics, null, path, rect);

                rect.Size = graphics.MeasureString(this.Element.Label, this.Element.Font);
                rect.Offset(this.Element.PositonOffset.Width + 1, this.Element.PositonOffset.Height + 1);

                TextParams tp = new TextParams();
                tp.font = this.Element.Font;
                tp.foreColor = this.Element.ForeColor;
                tp.paintingRectangle = rect;
                tp.text = this.Element.Label;

                FillPrimitiveImpl fill = new FillPrimitiveImpl(this.Element, null);
                fill.PaintFill(radGraphics, null, rect);
            
                TextPrimitiveHtmlImpl text = new TextPrimitiveHtmlImpl();
                text.PaintPrimitive(radGraphics, 0f, new SizeF(1f, 1f), tp);
            }
        }
Attached Files:
0 comments