Overlaying a trend line series over a stacked bar chart. How please?

1 Answer 137 Views
ChartView
Czeshirecat
Top achievements
Rank 2
Iron
Iron
Czeshirecat asked on 23 Feb 2022, 04:08 PM

Winforms. Jan 2022 software version.
I'm converting a very old version of teechart chart into Telerik RadChartView

What I'm seeing is this

What I want is, as in the following chart, where the stacked bars are overlayed with a trend line.
In the above, the stacked bar and line series are both using the same horizontal category axis but the line chart is following on from, rather than overlaying the stacked bars. I did try creating a 2nd category axis but then the auto scaling of the 2nd axis wasnt the same as the first. Stacking the line series didn't work either

How do I fix this please? There's only 2 points defined for the trend chart.

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 Feb 2022, 07:49 AM

Hello, Claire,

Note that the CategoricalAxis adds the axis values in the order of adding the data points. If the BarSeries and the LineSeries share common axis values, they will be placed at the same location on the chart view. 

I have prepared a sample code snippet for your reference demonstrating how to achieve a similar result is the desired one: 

            Random rand = new Random();
            
            BarSeries barSeries = new BarSeries(); 
 
            for (int i = 0; i < 20; i++)
            { 
                barSeries.DataPoints.Add(new CategoricalDataPoint(rand.Next(1, 200), i)); 
            }
            
            LineSeries lineSeries = new LineSeries();
            lineSeries.PointSize = new SizeF(8, 8);
            lineSeries.Shape = new DiamondShape();
            lineSeries.DataPoints.Add(new CategoricalDataPoint(rand.Next(1, 200), 9));
            lineSeries.DataPoints.Add(new CategoricalDataPoint(rand.Next(1, 200), 14));
           
            this.radChartView1.Series.Add(barSeries); 
            this.radChartView1.Series.Add(lineSeries);


I hope this information helps. If you need any further assistance please don't hesitate to contact me.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
ChartView
Asked by
Czeshirecat
Top achievements
Rank 2
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or