Completed
Last Updated: 24 Jan 2015 14:35 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 16 Dec 2014 11:31
Category: ChartView
Type: Bug Report
0
FIX. RadChartView - Line and area series are not rendered correctly when the CartesianArea.Orientation is Horizontal
To reproduce:

SteplineSeries stepLineSeries = new SteplineSeries();
stepLineSeries.DataPoints.Add(new CategoricalDataPoint(12, "Jan"));
stepLineSeries.DataPoints.Add(new CategoricalDataPoint(42, "Apr"));
stepLineSeries.DataPoints.Add(new CategoricalDataPoint(28, "Jul"));
stepLineSeries.DataPoints.Add(new CategoricalDataPoint(12, "Oct"));
this.radChartView1.Series.Add(stepLineSeries);  

CartesianArea area = this.radChartView1.Area as CartesianArea ;
area.Orientation = Orientation.Horizontal;

Please refer to the attached screenshots.

Workaround: use LineSeries with custom CartesianRenderer:

public Form1()
{
    InitializeComponent();

    this.radChartView1.CreateRenderer += radChartView1_CreateRenderer;

    LineSeries lineSeries = new LineSeries();
    lineSeries.DataPoints.Add(new CategoricalDataPoint(12, "Jan"));
    lineSeries.DataPoints.Add(new CategoricalDataPoint(42, "Apr"));
    lineSeries.DataPoints.Add(new CategoricalDataPoint(28, "Jul"));
    lineSeries.DataPoints.Add(new CategoricalDataPoint(12, "Oct"));
    this.radChartView1.Series.Add(lineSeries);
    
    CartesianArea area = this.radChartView1.Area as CartesianArea ;
    area.Orientation = Orientation.Horizontal;
}

private void radChartView1_CreateRenderer(object sender, ChartViewCreateRendererEventArgs e)
{
    e.Renderer = new CustomCartesianRenderer((CartesianArea)e.Area);
}

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++)
        {
            LineSeriesDrawPart drawPart = this.DrawParts[i] as LineSeriesDrawPart;
            if (drawPart != null)
            {
                this.DrawParts[i] = new CustomLineDrawPart((LineSeries)drawPart.Element, this);
            }
        }
    }
}

public class CustomLineDrawPart : LineSeriesDrawPart
{
    public CustomLineDrawPart(LineSeriesBase series, IChartRenderer renderer) : base(series, renderer)
    {
    }

    protected override GraphicsPath GetLinePaths(PointF[] points)
    {
        GraphicsPath path = new GraphicsPath();
        PointF x;
        PointF y;
        List<PointF> pointsList = points.ToList();

        CartesianArea area = this.Element.Parent as CartesianArea;
        if (area != null && area.Orientation == Orientation.Horizontal)
        {
            pointsList = pointsList.OrderBy(p => p.Y).ThenBy(p => p.X).ToList();
        }
        
        if (pointsList.Count > 1)
        {
            for (int i = 1; i < pointsList.Count; i++)
            {
                x = pointsList[i - 1];
                y = pointsList[i];
                path.AddLine(x.X, x.Y, y.X, x.Y);
                path.AddLine(y.X, x.Y, y.X, y.Y);
            }
        }
        else
        {
            return null;
        }

        return path;
    }
}

0 comments