Hi,
Please help me to delete datalabels from chart with 0 value.
check the attachment for clarification.
This chart is OLE based chart.
And please reply ASAP. I am waiting for your reply.
Saurabh
Hi,
I think, you will have to remove it from series, remove all values which have 0 value. If you are unable to do it, then please provide me your source xls/xlsx file having this chart.
Hi Saurabh,
check sample code
I am using both aspose.slide as well as aspose.cell.
If you feel this issue is related to aspose.cell. can you move this thread to aspose.cell
Ignore my last post … I thought u r asking to move the post… i already shared my code . please check that
Sorry forgot to attach presentation.
Hi,
Please see the code below, I have deleted the third datapoint and the datalable. You need to make the code generic though.
Please see the source input and output xlsx files and the screenshot.
C#
string filePath = @“F:\Shak-Data-RW\Downloads\source.xlsx”;
Workbook workbook = new Workbook(filePath);
Worksheet worksheet = workbook.Worksheets[0];
Chart chart = worksheet.Charts[0];
//Hide the 3rd datapoint of both series
int dataPointIndex = 2;
//Access the 3rd datapoint from A series and make it transparent
Area dtPointArea = chart.NSeries[0].Points[dataPointIndex].Area;
dtPointArea.ForegroundColor = Color.White;
dtPointArea.Transparency = 1;
//Access the 3rd datapoint from B series and make it transparent
dtPointArea = chart.NSeries[1].Points[dataPointIndex].Area;
dtPointArea.ForegroundColor = Color.White;
dtPointArea.Transparency = 1;
//Delete the values in cell A5
worksheet.Cells[“A5”].PutValue("");
workbook.Save(filePath + “.out.xlsx”);
Screenshot
Hi,
Here is another better approach, I have deleted now cell A5:C5, please see the source, output xlsx files and screenshot.
C#
string filePath = @“F:\Shak-Data-RW\Downloads\source.xlsx”;
Workbook workbook = new Workbook(filePath);
Worksheet worksheet = workbook.Worksheets[0];
//Delete cell A5,B5 and C5
worksheet.Cells.DeleteRange(4, 0, 4, 2, ShiftType.Up);
workbook.Save(filePath + “.out.xlsx”);
Hi,
Can you tell me please , how can I dynamically know which datapoint value is 0.
Saurabh
Hi,
First access your series range using Chart.NSeries[0].Values, it will give you something like this "=Sheet1!$B$3:$B$7"
Now, iterate all the cells in a range B3:B7 and find out the 0 value cells and delete them.
You will have to repeat this for all series found Chart.NSeries property. And also you have to have additional check that you will delete cells only when all the series cells have 0 values.
And to delete the datalable, you need to access the series range using Chart.NSeries[0].XValues, it will again give you range something like this “=Sheet1!$A$3:$A$7” and repeat the same process and delete the datalabel