Hello, Stephan,
In the
DrawSeriesParts method of the custom
BarSeriesDrawPart class you have access to the
CartesianRenderer via the
Renderer property. You need to cast it to the custom renderer that you have and thus you will have access to the
RenderParameter property. Please refer to the following code snippet:
public Form1()
{
InitializeComponent();
this.radChartView1.CreateRenderer += new ChartViewCreateRendererEventHandler(radChartView1_CreateRenderer);
BarSeries barSeries = new BarSeries("Performance", "RepresentativeName");
barSeries.Name = "Q1";
barSeries.DataPoints.Add(new CategoricalDataPoint(177, "Harley"));
barSeries.DataPoints.Add(new CategoricalDataPoint(128, "White"));
barSeries.DataPoints.Add(new CategoricalDataPoint(143, "Smith"));
barSeries.DataPoints.Add(new CategoricalDataPoint(111, "Jones"));
barSeries.DataPoints.Add(new CategoricalDataPoint(118, "Marshall"));
this.radChartView1.Series.Add(barSeries);
}
void radChartView1_CreateRenderer(object sender, ChartViewCreateRendererEventArgs e)
{
RenderParameter param = new RenderParameter();
param.Color = Color.Red;
e.Renderer = new CustomCartesianRenderer(param, e.Area as CartesianArea);
}
}
public class RenderParameter
{
public Color Color { get; set; }
public RenderParameter()
{
}
}
public class CustomCartesianRenderer : CartesianRenderer
{
internal RenderParameter RenderParameter { get; set; }
public CustomCartesianRenderer(CartesianArea area) : base(area)
{
}
public CustomCartesianRenderer(RenderParameter renderParameter, CartesianArea area) : base(area)
{
RenderParameter = renderParameter ?? throw new ArgumentNullException(nameof(renderParameter));
}
protected override void Initialize()
{
base.Initialize();
for (int i = 0; i < this.DrawParts.Count; i++)
{
BarSeriesDrawPart linePart = this.DrawParts[i] as BarSeriesDrawPart;
if (linePart != null)
{
this.DrawParts[i] = new CustomBarSeriesDrawPart((BarSeries)linePart.Element, this);
}
}
}
}
public class CustomBarSeriesDrawPart : BarSeriesDrawPart
{
public CustomBarSeriesDrawPart(BarSeries series, IChartRenderer renderer) : base(series, renderer)
{
}
public override void DrawSeriesParts()
{
CustomCartesianRenderer customRenderer = this.Renderer as CustomCartesianRenderer;
RenderParameter param= customRenderer.RenderParameter;
Graphics graphics = customRenderer.Graphics;
RadGdiGraphics radGraphics = new RadGdiGraphics(graphics);
for (int j = 0; j < this.Element.DataPoints.Count; j++)
{
RadRect slot = this.Element.DataPoints[j].LayoutSlot;
RectangleF temp = new RectangleF((float)(this.OffsetX + slot.X), (float)(this.OffsetY + slot.Y), (float)slot.Width, (float)slot.Height);
RectangleF barBounds = new RectangleF(temp.X + 10,temp.Y + 10,temp.Width,temp.Height + 10);
DataPointElement childElement = (DataPointElement)this.Element.Children[j];
float realWidth = barBounds.Width * childElement.HeightAspectRatio;
barBounds.Width = realWidth;
barBounds.Height = Math.Max(barBounds.Height, 1f);
radGraphics.FillRectangle(barBounds, Color.LightGray);
}
base.DrawSeriesParts();
}
}
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Progress is here for your business, like always.
Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.