Line chart - legends created for each datapoint instead of creating it per series

Hi Team,
The issue is happening with the line chart for below scenario.
Scenario : when we have only one series multiple category axis values (data-points) for the same series.
Issue : Legends are created per data-points instead of series.

PFB screenshots for the same:
Chart:
image.png (21.3 KB)
Datasheet:
image.png (5.1 KB)

I wanted to know what can be the cause for the above Issue.
Also note that this works when we have multiple series , in this case the legends are created per series
PFB screenshots for working scenario:
Chart working:
image.png (16.2 KB)

Datasheet working :
image.png (7.8 KB)

Revert back in case of any queries.

@mrajgopal.22,

Thanks for the screenshots and details.

Could you please create your desired chart in MS Excel manually, save the Excel and post us to demonstrate your desired chart. We will check and devise some code segments to accomplish the task.

Also, share your current sample (runnable) code (that you are using) that creates your undesired chart, we might update your code directly and accordingly for your requirements.

PS. please zip the Excel file(s) or other files prior attaching.

1 Like

Thanks for replying…!!
PFB the excel file attached.

testdata_exp.zip (36.8 KB)

The code we use is part of a huge framework . Will try and get a sample of that soon.

Looking forward for positive reply.

@mrajgopal.22,

Thanks for the sample file.

I have written a sample code to create your desired chart for your reference. I have used your sample file as template file for chart’s source data and created the custom chart accordingly in the expected sheet. Please refer to the sample code and write/update your code by yourselves:
e.g.
Sample code:

       Workbook workbook = new Workbook("f:\\files\\testdata_exp.xlsx");

       //Get the worksheet.
       Worksheet sheet = workbook.getWorksheets().get("expected");

       //Create chart
       int chartIndex = sheet.getCharts().add(ChartType.LINE_WITH_DATA_MARKERS, 26, 1, 51, 17);
       Chart chart = sheet.getCharts().get(chartIndex);

       //Set properties of chart title
       //chart.getTitle().setText("Chart title");

       //Set properties of nseries
       chart.getNSeries().add("=DataSheet1!E2:E13", true);
       chart.getNSeries().setCategoryData("=DataSheet1!A2:A13");

       //set series name
       chart.getNSeries().get(0).setName("=DataSheet1!$B$2");


       chart.getNSeries().get(0).getMarker().setMarkerStyle(ChartMarkerType.DIAMOND);
       chart.getNSeries().get(0).getMarker().setMarkerSize(7);
       chart.getNSeries().get(0).getMarker().getArea().setFormatting(FormattingType.NONE);
       chart.getNSeries().get(0).getBorder().setColor(com.aspose.cells.Color.getGreen());

       chart.getPlotArea().getArea().setFormatting(FormattingType.NONE);


       chart.getCategoryAxis().getMajorGridLines().setColor(com.aspose.cells.Color.getLightGray());
       chart.getValueAxis().getMajorGridLines().setColor(com.aspose.cells.Color.getLightGray());



       chart.getLegend().setPosition(LegendPositionType.LEFT);

       workbook.save("f:\\files\\out1.xlsx");

Hope, this helps a bit.

Thanks Amjad_Sahi,

I tried with the sample code I am getting the expected one.
I have one question regarding the legends , is there any possibilities where the legends are created as per the datapoint values, instead of series.

Usually I observe that legends are always associated with series. But wanted to know whether there is any edge cases for this.

@mrajgopal.22,

Good to know that the suggested code segments create your expected chart.

We are not sure about your query. Aspose.Cells follows MS Excel standards and specifications when creating charts, so you may check in MS Excel manually by creating different charts accordingly.