Remove legend entry for series

Here is an example:


Presentation pres = new Presentation();

ISlide slide = pres.Slides[0];

//Creating the default chart
IChart chart = slide.Shapes.AddChart(ChartType.ScatterWithSmoothLines, 0, 0, 400, 400);

//Getting the default chart data worksheet index
int wsIndex = 0;

//Getting the chart data worksheet
IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook;

//Delete demo series
chart.ChartData.Series.Clear();

//Add new series
chart.ChartData.Series.Add(fact.GetCell(wsIndex, 1, 1, “Series 1”), ChartType.ScatterWithStraightLinesAndMarkers);

IChartSeries series = chart.ChartData.Series[0];
series.Marker.Size = 10;
series.Marker.Symbol = MarkerStyleType.Star;

series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 2, 1, 1), fact.GetCell(wsIndex, 2, 2, 1));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 3, 1, 1), fact.GetCell(wsIndex, 3, 2, 2));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 4, 1, 1), fact.GetCell(wsIndex, 4, 2, 3));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 5, 1, 1), fact.GetCell(wsIndex, 5, 2, 4));

//Add new series
chart.ChartData.Series.Add(fact.GetCell(wsIndex, 1, 3, “Series 2”), ChartType.ScatterWithMarkers);

series = chart.ChartData.Series[1];
series.Marker.Size = 10;
series.Marker.Symbol = MarkerStyleType.Square;

series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 2, 3, 2), fact.GetCell(wsIndex, 2, 4, 1));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 3, 3, 2), fact.GetCell(wsIndex, 3, 4, 2));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 4, 3, 2), fact.GetCell(wsIndex, 4, 4, 3));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 5, 3, 2), fact.GetCell(wsIndex, 5, 4, 4));

//Add new series
chart.ChartData.Series.Add(fact.GetCell(wsIndex, 1, 5, “Series 3”), ChartType.ScatterWithSmoothLinesAndMarkers);

series = chart.ChartData.Series[2];
series.Marker.Size = 10;
series.Marker.Symbol = MarkerStyleType.Diamond;

series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 2, 5, 3), fact.GetCell(wsIndex, 2, 6, 1));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 3, 5, 3), fact.GetCell(wsIndex, 3, 6, 2));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 4, 5, 3), fact.GetCell(wsIndex, 4, 6, 3));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 5, 5, 3), fact.GetCell(wsIndex, 5, 6, 4));

//Add new series
chart.ChartData.Series.Add(fact.GetCell(wsIndex, 1, 7, “Series 4”), ChartType.ScatterWithMarkers);

series = chart.ChartData.Series[3];
series.Marker.Size = 10;
series.Marker.Symbol = MarkerStyleType.Circle;

series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 2, 7, 4), fact.GetCell(wsIndex, 2, 8, 1));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 3, 7, 4), fact.GetCell(wsIndex, 3, 8, 2));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 4, 7, 4), fact.GetCell(wsIndex, 4, 8, 3));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 5, 7, 4), fact.GetCell(wsIndex, 5, 8, 4));

pres.Save(“AsposeChart.pptx”, SaveFormat.Pptx);

The result is:

chart


I need to remove legend for Series 2 and Series 4.
How can I do this?

I’m not sure why the order of Series 3 and 4 are flipped, but the code you’d need is:

chart.Legend.Entries[i].Hide = true; //i being the index of the item you want to hide



Hi Myroslav,


We are glad to know that things have started working on your end,

Please feel free to contact us if we could be of any help to you.

Best Regards,

Hi!

I tried to use this code

chart.Legend.Entries[i].Hide = true;

But, it seems, there is some bug in Aspose.Slides.
Index of Legend.Entries[] doesn’t correspond index of Series[].

As you can see in example and screenshot that I wrote above, series order is:
Series1
Series2
Series3
Series4
When legend order is
Series1
Series2
Series4
Series3

So, when I tried to remove legend for Series3, it will remove Series4 legend.


As the result, I can’t remove legend for series, because order of series and legend are different.

Do you want to remove the Legend entry based on the Series name or the series index?

There’s some bug with

ChartType.ScatterWithSmoothLinesAndMarkers
that is causing the series to be out of order in the legend. If Series 2 & 4 are both
ChartType.ScatterWithStraightLinesAndMarkers
then everything works as it should.

Hi,



Thanks for sharing your feedback. Can you please provide a working sample code reproducing the issue on your end for said chart type along with generated and desired output for comparison. I will log an issue in our issue tracking system once requested information will be shared.



Many Thanks,

Here is example:


Presentation pres = new Presentation();

ISlide slide = pres.Slides[0];

//Creating the default chart
IChart chart = slide.Shapes.AddChart(ChartType.ScatterWithSmoothLines, 0, 0, 400, 400);

//Getting the default chart data worksheet index
int wsIndex = 0;

//Getting the chart data worksheet
IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook;

//Delete demo series
chart.ChartData.Series.Clear();

//Add new series
chart.ChartData.Series.Add(fact.GetCell(wsIndex, 1, 1, “Series 1”), ChartType.ScatterWithStraightLinesAndMarkers);

IChartSeries series = chart.ChartData.Series[0];
series.Marker.Size = 10;
series.Marker.Symbol = MarkerStyleType.Star;

series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 2, 1, 1), fact.GetCell(wsIndex, 2, 2, 1));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 3, 1, 1), fact.GetCell(wsIndex, 3, 2, 2));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 4, 1, 1), fact.GetCell(wsIndex, 4, 2, 3));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 5, 1, 1), fact.GetCell(wsIndex, 5, 2, 4));

//Add new series
chart.ChartData.Series.Add(fact.GetCell(wsIndex, 1, 3, “Series 2”), ChartType.ScatterWithMarkers);

series = chart.ChartData.Series[1];
series.Marker.Size = 10;
series.Marker.Symbol = MarkerStyleType.Square;

series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 2, 3, 2), fact.GetCell(wsIndex, 2, 4, 1));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 3, 3, 2), fact.GetCell(wsIndex, 3, 4, 2));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 4, 3, 2), fact.GetCell(wsIndex, 4, 4, 3));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 5, 3, 2), fact.GetCell(wsIndex, 5, 4, 4));

//Add new series
chart.ChartData.Series.Add(fact.GetCell(wsIndex, 1, 5, “Series 3”), ChartType.ScatterWithSmoothLinesAndMarkers);

series = chart.ChartData.Series[2];
series.Marker.Size = 10;
series.Marker.Symbol = MarkerStyleType.Diamond;

series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 2, 5, 3), fact.GetCell(wsIndex, 2, 6, 1));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 3, 5, 3), fact.GetCell(wsIndex, 3, 6, 2));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 4, 5, 3), fact.GetCell(wsIndex, 4, 6, 3));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 5, 5, 3), fact.GetCell(wsIndex, 5, 6, 4));

//Add new series
chart.ChartData.Series.Add(fact.GetCell(wsIndex, 1, 7, “Series 4”), ChartType.ScatterWithMarkers);

series = chart.ChartData.Series[3];
series.Marker.Size = 10;
series.Marker.Symbol = MarkerStyleType.Circle;

series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 2, 7, 4), fact.GetCell(wsIndex, 2, 8, 1));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 3, 7, 4), fact.GetCell(wsIndex, 3, 8, 2));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 4, 7, 4), fact.GetCell(wsIndex, 4, 8, 3));
series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(wsIndex, 5, 7, 4), fact.GetCell(wsIndex, 5, 8, 4));


// Remove “Series 3” legend
chart.Legend.Entries[2].Hide = true;


pres.Save(“AsposeChart.pptx”, SaveFormat.Pptx);

Result:


chart



Expected result:

chart



Hi,

I have worked with the sample code shared by you and have been able to observe the issue specified. An issue with ID SLIDESNET-36992 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be automatically notified once the issue will be fixed.

We are sorry for your inconvenience,

Hi,


I have exactly the same issue on aspose slides, but in JAVA. Can you please also fix it for the java version?

Best regards

Hi,

I like to share that once the concerned issue will be resolved for Aspose.Slides for .NET, it will also get resolved for Aspose.Slides for Java as well. We will share the notification with you in this regard once the concerned issue will be resolved.

Many Thanks,

Any updates on the above? Please, have it as priority as this is critical

Hi,

I have verified from our issue tracking system and regret to share that at present the issue is still unresolved. However, it has been scheduled for investigation during Week 2 of 2016. We will be able to share the further news with you in this regard after the investigation results will be shared by our product team.

Many Thanks,

The issues you have found earlier (filed as SLIDESNET-36992) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi ,
Can you please tell me In which version of aspose.-cells it has been fixed?
Thanks

@Chandra1234,

I like to inform that this issue has been fixed in Aspose.Slides 16.2.0. Please share feedback with us if you have any issue.

A post was split to a new topic: Remove legend entry from chart series