Completed
Last Updated: 18 Aug 2020 09:03 by ADMIN
Release R1 2019
ADMIN
Hristo
Created on: 28 Nov 2016 15:17
Category: ChartView
Type: Bug Report
3
FIX. RadChartView - CartesianSeries data points labels are not clipped if they are displayed outside of the view
Note: similar to the axis, the series should also have ClipLabels property which will control whether the labels will be clipped or not.

How to reproduce: zoom and pan along the chart
public Form1()
{
    InitializeComponent();

    this.radChartView1.CreateRenderer += radChartView1_CreateRenderer;
    this.radChartView1.ShowPanZoom = true;

    BarSeries barSeries = new BarSeries();
    Random rand = new Random();
    for (int i = 1; i < 10; i++)
    {
        barSeries.DataPoints.Add(new CategoricalDataPoint(rand.Next(100), i));
    }

    barSeries.ShowLabels = true;
    this.radChartView1.Series.Add(barSeries);
}

Workaround:
 public partial class Form1 : Form
 {
     public Form1()
     {
         InitializeComponent();

         this.radChartView1.CreateRenderer += radChartView1_CreateRenderer;
         this.radChartView1.ShowPanZoom = true;

         BarSeries barSeries = new BarSeries();
         Random rand = new Random();
         for (int i = 1; i < 10; i++)
         {
             barSeries.DataPoints.Add(new CategoricalDataPoint(rand.Next(100), i));
         }

         barSeries.ShowLabels = true;
         this.radChartView1.Series.Add(barSeries);
     }

     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; i++)
         {
             BarLabelElementDrawPart labelPart = this.DrawParts[i] as BarLabelElementDrawPart;
             if (labelPart != null)
             {
                 this.DrawParts[i] = new CustomLabelElementDrawPart((BarSeries)labelPart.Element, this);
             }
         }
     }
 }

 public class CustomLabelElementDrawPart : BarLabelElementDrawPart
 {
     public CustomLabelElementDrawPart(ChartSeries owner, IChartRenderer renderer)
         : base(owner, renderer)
     { }
     
     public override void Draw()
     {
         Graphics graphics = this.Renderer.Surface as Graphics;
         CartesianSeries cartesianSeries = this.Element as CartesianSeries;
         if (cartesianSeries != null)
         {
             CartesianArea area = (CartesianArea)cartesianSeries.GetType().GetField("area", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(cartesianSeries);
             RectangleF clipRect = (RectangleF)area.GetType().GetMethod("GetCartesianClipRect", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(area, new object[] { });//.GetCartesianClipRect();
             graphics.SetClip(clipRect);
         }

         base.Draw();

         graphics.ResetClip();
     }
 }
1 comment
ADMIN
Dimitar
Posted on: 07 Nov 2018 14:13
CartesianSeries has a new property: ClipLabels (by default set to false) and it can be used like this:

BarSeries barSeries = new BarSeries("Performance", "RepresentativeName");
barSeries.Name = "Q1";
barSeries.ClipLabels = true;