To display SecondayHorizontalAxis from the top in excel for chart type column

Hi! Team,
I want to display the invisible bar for the column chart along with Labels.
And I want to display Labels on SecondaryHorizontalAxis, it is getting displayed,
but SecondaryHorizontalAxis is not starting from Top, it is starting after some gap, due to which it is not aligned.
Please help me out with this thanks.

@Rohan_Wankar,

Please zip and attach the following resource files:

  1. Your input Excel file (if any)
  2. Output Excel file containing your undesired chart
  3. Excel file with your expected chart in it, you may create/update the chart in MS Excel manually to save the Excel file
  4. Your current sample code (runnable without compile time errors) to generate the output Excel file containing your undesired chart in it.

After getting the above resource files, we will start evaluating your issue/requirements and assist you accordingly.

Hi @Amjad_Sahi,

To start with, I am attaching the excel file which @Rohan_Wankar has mentioned. In the attached excel, there is a secondary horizontal axis, which is not starting from the top of the y axis, instead there is a space as shown below :

image.png (22.7 KB)

Could you please help us in pushing this axis from the top of yaxis first manually in the excel file? then we can go with programmatical approach. attaching the excel as well. MultibarVertical+Label.zip (10.9 KB)

Thanks in advance!

Regards,
Thilak Babu

@Thilakbabu,

I am sorry but we could not understand your needs precisely, so do not know how to accomplish the task in MS Excel manually. As requested kindly perform your task in MS Excel manually for your chart’s desired display/formatting and save the file to provide us here, we will check on how to do it via Aspose.Cells APIs.

Hi! @Amjad_Sahi,
@Thilakbabu has attached the zip file which has the working excel, we want to display the SecondaryHorizontal Axis for Chart from top.
Please let me know in case of further details.

@Rohan_Wankar,

@Thilakbabu attached the zipped archive in his post but it does not have his expected chart in the file “MultibarVertical+Label.xlsx” rather he asked me to do it manually in MS Excel:

I tried but could not accomplish the task in MS Excel manually, so I asked him to provide your expected chart (created in MS Excel manually) in the file.
Anyways, is the chart in “MultibarVertical+Label.xlsx” your expected chart, please confirm? We will devise a code segment via Aspose.Cells APIs after your confirmation.

yes @Amjad_Sahi

@Rohan_Wankar,

See the following sample code to accomplish your task. You may refer to the code segment and update or write your code for your custom needs accordingly. I used your file for chart’s data source and generate the custom chart in a new sheet.
e.g.
Sample code:

            Workbook workbook = new Workbook("e:\\test2\\MultibarVertical+Label.xlsx");
            Worksheet worksheet = workbook.Worksheets["DataSheet"];

            Worksheet sheet = workbook.Worksheets[workbook.Worksheets.Add()];

            int chartIndex = sheet.Charts.Add(ChartType.Column, 5, 2, 21, 15);
            //Accessing the instance of the newly added chart
            Chart chart = sheet.Charts[chartIndex];
            
            chart.NSeries.Add("=((DataSheet!$C$2,DataSheet!$C$4),DataSheet!$C$6,DataSheet!$C$8)", true);
            chart.NSeries.Add("=((DataSheet!$C$3,DataSheet!$C$5),DataSheet!$C$7,DataSheet!$C$9)", true);
            //Add category data for the primary series.
            chart.NSeries.CategoryData = "=(DataSheet!$A$2,DataSheet!$A$4,DataSheet!$A$6,DataSheet!$A$8)";

            chart.NSeries[0].Name = "Coffee";
            chart.NSeries[1].Name = "Tea";

            chart.NSeries.Add("=((DataSheet!$D$2,DataSheet!$D$4),DataSheet!$D$6,DataSheet!$D$8)", true);
            chart.NSeries.Add("=((DataSheet!$D$3,DataSheet!$D$5),DataSheet!$D$7,DataSheet!$D$9)", true);
            
            chart.NSeries[2].PlotOnSecondAxis = true;
            chart.NSeries[2].Name = "Coffee";
            chart.NSeries[2].DataLabels.ShowValue = true;
            chart.NSeries[2].DataLabels.Position = LabelPositionType.InsideBase;
            chart.NSeries[3].PlotOnSecondAxis = true;
            chart.NSeries[3].Name = "Tea";
            chart.NSeries[3].DataLabels.ShowValue = true;
            chart.NSeries[3].DataLabels.Position = LabelPositionType.InsideBase;

            chart.NSeries[2].Area.FillFormat.FillType = FillType.None;
            chart.NSeries[3].Area.FillFormat.FillType = FillType.None;

            chart.SecondValueAxis.IsVisible = true;
            
            chart.PlotArea.Area.ForegroundColor = Color.White;

            chart.Legend.Position = LegendPositionType.Bottom;
            chart.Legend.LegendEntries[2].IsDeleted = true;
            chart.Legend.LegendEntries[3].IsDeleted = true;

            workbook.Save("e:\\test2\\out1.xlsx");

Hope, this helps a bit.

Hi! @Amjad_Sahi
I want to display another chart with an invisible bar from the top. But SecondaryHorizontal axes position is still not getting changed.
I tried setting the series for other chart plotOnSecondAxis to true.
But no success.
Can you help in plotting the invisible bar from the top of the SecondaryHorizontal axis?
thanks!

Please provide the following artifacts and resource files, so we could evaluate your task:

  1. Current output Excel file by Aspose.Cells APIs containing your undesired custom chart.
  2. An Excel file containing your desired chart (invisible bar plotted from the top of the SecondaryHorizontal axis), you may create the chart in MS Excel manually.
  3. Your current sample code that you are using that creates your undesired chart.

Please note, Aspose.Cells follows MS Excel standards and specifications when creating or manipulating charts. So, if MS Excel cannot accomplish your task manually, Aspose.Cells cannot do it as well.