Setting a Column Chart with a Secondary Axis

Hi, I have been working on a chart, which I can now get all the data and put it all together.

However, This data is supposed to show the columns overlapped -- again something I can do.

The issue comes in when I try to make one of the column wider than the other.

In Excel, this is accomplished by setting one of the data series to a secondary axis.

For this, the primary and secondary will be based on the same dataset.

The data set is 

Fiscal YearData1Data2
2015-160.4582320.347062
2016-170.5125630.351189
2017-180.5436090.348293
2018-190.2910270.148673
2019-200.3828720.236021


Here is the code:

chart.ChartType = OfficeChartType.Column_Clustered;
chart.ChartTitle = "";
chart.HasLegend = false;

//Set up the Primary Category Axis
chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 6, 1];
chart.PrimaryCategoryAxis.Border.LineColor = Syncfusion.Drawing.Color.FromArgb(217, 217, 217);

chart.PrimaryValueAxis.NumberFormat = "0%";
chart.PrimaryValueAxis.MajorGridLines.LineProperties.LineColor = Syncfusion.Drawing.Color.FromArgb(217, 217, 217);
chart.PrimaryValueAxis.Border.LineColor = Syncfusion.Drawing.Color.FromArgb(255, 255, 255);
chart.PrimaryValueAxis.MaximumValue = maxAxisValue;

//Set up the Secondary Cateogy Axis
chart.SecondaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 6, 1];
chart.SecondaryCategoryAxis.Visible = false;
chart.SecondaryValueAxis.NumberFormat = "0%";
chart.SecondaryValueAxis.MaximumValue = maxAxisValue;

//Set up the Chart Series Data
IOfficeChartSerie seriesnData1Rates = chart.Series.Add("Data1");
seriesnData1Rates.Values = chart.ChartData[2, 2, 6, 2];
seriesnData1Rates.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
seriesnData1Rates.DataPoints.DefaultDataPoint.DataLabels.Size = 9;
seriesnData1Rates.DataPoints.DefaultDataPoint.DataLabels.NumberFormat = "0%";
seriesnData1Rates.DataPoints.DefaultDataPoint.DataLabels.Bold = false;
seriesnData1Rates.SerieFormat.CommonSerieOptions.Overlap = 100;
seriesnData1Rates.SerieFormat.CommonSerieOptions.GapWidth = 350;
seriesnData1Rates.DataPoints.DefaultDataPoint.DataFormat.Fill.ForeColor = K3dpColor;
seriesnData1Rates.UsePrimaryAxis = true;

IOfficeChartSerie seriesnData1Rates = chart.Series.Add("Data2");
seriesnData2Rates.Values = chart.ChartData[2, 3, 6, 3];
seriesnData2Rates.DataPoints.DefaultDataPoint.DataLabels.IsValue = false;
//seriesnData2Rates.DataPoints[1].DataLabels.Size = 9;
//seriesnData2Rates.DataPoints[1].DataLabels.NumberFormat = "0%";
//seriesnData2Rates.DataPoints[1].DataLabels.Bold = false;
seriesnData2Rates.SerieFormat.CommonSerieOptions.Overlap = 100;
seriesnData2Rates.SerieFormat.CommonSerieOptions.GapWidth = 129;
seriesnData2Rates.DataPoints.DefaultDataPoint.DataFormat.Fill.ForeColor = nK3dpColor;
seriesnData2Rates.UsePrimaryAxis = false;


It fails when trying to set the Secondary Category Axis Category Labels.

chart.SecondaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 6, 1];

Error: System.NullReferenceException: 'Object reference not set to an instance of an object.'


Any idea why this might be happening??


4 Replies

EW Edward Williams October 8, 2021 12:18 PM UTC

Here is a sample of what the chart should look like:



Attachment: Sample_Chart_3cf85914.zip


MR Manikandan Ravichandran Syncfusion Team October 8, 2021 04:52 PM UTC

Hi Edward,

Thank you for contacting Syncfusion support.

We have tried to prepare the sample to generate the chart based on the given screenshot. We have also faced the same problem when we set different overlap and gap width values for each series. Currently, we are validating this problem and we will share the details on 12th October 2021.

Please let us know if you have any other queries.

Regards,
Manikandan Ravichandran 



MR Manikandan Ravichandran Syncfusion Team October 12, 2021 02:36 PM UTC

Hi Edward,

Thank you for your patience.

We are facing some complexities while validating the reported issue. Currently we are validating this issue with high priority and will share the more details about this issue on 13th October 2021 without further delay.

Please let us know if you have any other queries.

Regards,
Manikandan Ravichandran 



MR Manikandan Ravichandran Syncfusion Team October 13, 2021 01:56 PM UTC

Hi Edward,

Thank you for your patience.

On further validating the reported problem, we have found that we are having a support to set the gap width and overlap value commonly for all the series in the chart and does not have a support to set gap width and overlap for each series separately while creating the chart.

We have logged this requirement as a features requests in our database. We don’t have any immediate plans to implement this feature. We will let you know when this feature is implemented.

The status of this feature task can be tracked through the following feedback link:
https://www.syncfusion.com/feedback/29443/provide-support-to-set-gap-width-and-overlap-for-each-series-in-chart

Please let us know if you have any other queries.

Regards,
Manikandan Ravichandran 


Loader.
Up arrow icon