We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How do you add blank values to chart data

How do you add a blank data cell to a chart’s data?


First I set the DisplayBlanksAs flag:
chart.DisplayBlanksAs = DisplayBlanksAsTypeEx.Gap;

Then I try to add a blank data value:
series.Values.Add(d.GetCell(0, 0, 0, “”));

I also tried using null:
series.Values.Add(d.GetCell(0, 0, 0, null));

In both cases the output slide was corrupted and replaced with a blank slide.

Thanks in advance.
Shaun

Hi Shaun,

Please follow this link for creating chart from scratch which will help you in setting the chart series data. I am still unable to understand the requirement of setting blank chart cell. Please share your requirements in detail along with code snippet so that I may try reproducing the issue on my end and understand your requirements more clearly.

Thanks and Regards,

It is common in certain data sets to plot a blank data point instead of a numerical value. For example, in a line chart you might plot 0 as a blank cell to prevent the line from going to 0. In the chart you just see a gap in the line.


Since yesterday I have found out that you can add a blank cell by using the following method:

ChartDataCellFactory.GetCell(int worksheetIndex, int row, int column);

But, if you add a series where all the data is blank cells, the generated file is still corrupt. I looked into the XML of generated PPTX and it is because the <c:val> node is empty. Even though there is no data, certain other child nodes need to be there.

Use this code to reproduce the problem: (modified version of your sample code)

//Adding new series
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 1, “Series 1”), chart.Type);
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, “Series 2”), chart.Type);
//Adding new categories
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, “Caetegoty 1”));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, “Caetegoty 2”));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, “Caetegoty 3”));
//Take first chart series
ChartSeriesEx series = chart.ChartData.Series[0];
//Now populating series data
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 1, 20));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 1, 50));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 1, 30));
//Take second chart series
series = chart.ChartData.Series[1];
//Now populating series data
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 2));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 2));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 2));

You will need to clear the worksheet first.

Hi Shaun,


I have worked with your requirements and like to share that if you set all the values for a particular series to blank then presentation gets corrupted. An issue with ID 30981 has been created to resolve this issue. As a workaround, if you set any one value inside the series to 0 or some other value then presentation generated is fine. I feel if you set the value of any one series item to 0, then you can still achieve the results. I have used following code snippet as workaround.

//Instantiate PresentationEx class that represents PPTX file
PresentationEx pres = new PresentationEx();

//Access first slide
SlideEx sld = pres.Slides[0];

// Add chart with default data
ChartEx chart = sld.Shapes.AddChart(ChartTypeEx.ClusteredColumn, 0, 0, 300, 300);

//Setting the index of chart data sheet
int defaultWorksheetIndex = 0;

//Getting the chart data worksheet
ChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory;

//Delete default generated series and categories
chart.ChartData.Series.Clear();
chart.ChartData.Categories.Clear();
int s = chart.ChartData.Series.Count;
s = chart.ChartData.Categories.Count;

//Adding new series
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 1, “Series 1”), chart.Type);
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, “Series 2”), chart.Type);

//Adding new categories
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, “Caetegoty 1”));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, “Caetegoty 2”));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, “Caetegoty 3”));

//Take first chart series
ChartSeriesEx series = chart.ChartData.Series[0];

//Now populating series data
/*
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 1, 20));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 1, 50));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 1, 30));
*/
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 1, “”));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 1,""));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 1, “”));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 4, 1, 0));
//Take second chart series
series = chart.ChartData.Series[1];

//Now populating series data
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 2, 0));
ChartDataCell cd = chart.ChartData.ChartDataCellFactory.GetCell(0, 1, 2);
cd.Value = “”;
series.Values.Add(cd);

cd = chart.ChartData.ChartDataCellFactory.GetCell(0, 2, 2);
cd.Value = “”;
series.Values.Add(cd);
cd = chart.ChartData.ChartDataCellFactory.GetCell(0, 3, 2);
cd.Value = “”;
series.Values.Add(cd);

cd = chart.ChartData.ChartDataCellFactory.GetCell(0, 4, 2);
cd.Value = 0;
series.Values.Add(cd);
// Save presentation with chart

Thanks and Regards,

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


This message was posted using Notification2Forum from Downloads module by aspose.notifier.