chartview CreateRenderer event not being called or, even better, can I set a Z Order for axes?

1 Answer 18 Views
ChartView
Czeshirecat
Top achievements
Rank 1
Czeshirecat asked on 24 Feb 2022, 03:24 PM

In chart below I had to use 2 category axes to get a trend line to appear in the same zone.

The only problem is that the line series is being drawn behind the stacked bars. I've tried adding axes in the opposite order, added the line series first, then after all the bar series. No difference.
I thought then maybe I could make the pale coloured bars translucent, but the CreateRenderer event isn't being called, I even tested that in a new project, so I gave up on that idea.
Another problem is that I've set the chart to showgrid = true. That's not being shown either.

Can somebody help please?

 

private void CreateChartComponents()
    {
      #region Code
      try
      {
        _categoricalAxis1 = new Telerik.WinControls.UI.CategoricalAxis();
        _categoricalAxis2 = new Telerik.WinControls.UI.CategoricalAxis();
        _linearAxis1 = new Telerik.WinControls.UI.LinearAxis();

        _categoricalAxis1.IsPrimary = true;
        _categoricalAxis2.IsPrimary = true;

        _categoricalAxis1.ShowLabels = false;
        _categoricalAxis2.ShowLabels = false;
        _categoricalAxis2.IsVisible = false;

        _linearAxis1.AxisType = Telerik.Charting.AxisType.Second;
        _linearAxis1.IsPrimary = true;

        chart.Axes.Clear();
        chart.Axes.AddRange(_categoricalAxis1, _linearAxis1, _categoricalAxis2);

        _barSeriesNormal = new Telerik.WinControls.UI.BarSeries();
        _barSeriesUnder = new Telerik.WinControls.UI.BarSeries();
        _barSeriesOver = new Telerik.WinControls.UI.BarSeries();
        _lineSeriesTrend = new Telerik.WinControls.UI.LineSeries();

        _barSeriesNormal.HorizontalAxis = _categoricalAxis1;
        _barSeriesUnder.HorizontalAxis = _categoricalAxis1;
        _barSeriesOver.HorizontalAxis = _categoricalAxis1;
        _lineSeriesTrend.HorizontalAxis = _categoricalAxis2;

        _barSeriesNormal.VerticalAxis = _linearAxis1;
        _barSeriesUnder.VerticalAxis = _linearAxis1;
        _barSeriesOver.VerticalAxis = _linearAxis1;
        _lineSeriesTrend.VerticalAxis = _linearAxis1;

        _barSeriesNormal.CombineMode = Telerik.Charting.ChartSeriesCombineMode.Stack;
        _barSeriesUnder.CombineMode = Telerik.Charting.ChartSeriesCombineMode.Stack;
        _barSeriesOver.CombineMode = Telerik.Charting.ChartSeriesCombineMode.Stack;

        var seriesColor = Color.FromArgb(68, 102, 163);
        var trendColor = Color.Blue;

        _barSeriesUnder.BackColor = Color.AliceBlue;
        _barSeriesUnder.BorderColor = Color.AliceBlue;
        _barSeriesUnder.LegendTitle = "Under Performance";

        _barSeriesOver.BorderColor = seriesColor;
        _barSeriesOver.BackColor = seriesColor;
        _barSeriesOver.Shape = customShape1;
        _barSeriesOver.LegendTitle = "Over Performance";

        _barSeriesNormal.BorderColor = seriesColor;
        _barSeriesNormal.BackColor = seriesColor;
        _barSeriesNormal.LegendTitle = "Expected Performance";

        _lineSeriesTrend.BorderColor = trendColor;
        _lineSeriesTrend.BackColor = trendColor;
        _lineSeriesTrend.LegendTitle = "Trend";

        chart.Series.AddRange(_barSeriesNormal, _barSeriesUnder, _barSeriesOver, _lineSeriesTrend);
        chart.ShowGrid = true;
      }
      catch (Exception err)
      {
        Log4Net.Log.Error(err);
        throw;
      }
      #endregion
    }// function

1 Answer, 1 is accepted

Sort by
1
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 Feb 2022, 11:52 AM
Hello, Claire,

Please have in mind that the order of adding the series to the chart controls the order of rendering: 

Example 1: The LineSeries is rendered over the BarSeries

            BarSeries barSeries = new BarSeries();
            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")); 

            LineSeries lineSeries = new LineSeries();
            lineSeries.DataPoints.Add(new CategoricalDataPoint(150, "Harley"));
            lineSeries.DataPoints.Add(new CategoricalDataPoint(22, "Marshall")); 


            this.radChartView1.Series.Add(lineSeries);
            this.radChartView1.Series.Add(barSeries);

Example 2: The BarSeries is rendered over the LineSeries

            BarSeries barSeries = new BarSeries();
            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")); 

            LineSeries lineSeries = new LineSeries();
            lineSeries.DataPoints.Add(new CategoricalDataPoint(150, "Harley"));
            lineSeries.DataPoints.Add(new CategoricalDataPoint(22, "Marshall")); 

            this.radChartView1.Series.Add(barSeries);
            this.radChartView1.Series.Add(lineSeries);

As to the CreateRenderer event, please have in mind it is necessary to subscribe to it before populating RadChartView with any data. A sample approach how to use the custom rendering functionality in RadChartView is demonstrated in the following help article:

https://docs.telerik.com/devtools/winforms/controls/chartview/customization/custom-rendering 

In case you are still experiencing any further difficulties, it would be greatly appreciated if you can provide a complete code snippet that I can use for building a sample project to replicate the problem you are facing. Thus, we would be able to investigate the precise case and provide further assistance. Thank you in advance for your cooperation. 

I am looking forward to your reply.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Czeshirecat
Top achievements
Rank 1
commented on 01 Mar 2022, 10:38 AM

That's great. Thank you very much
Tags
ChartView
Asked by
Czeshirecat
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or