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

Free Support Forum - aspose.com

Slides are empty

Hello Aspose,

I am wriitng the following code to create an pptx file. The created file is empty. Can anyone give me a hint where goes wrong?

Thanks

John

PresentationEx pres = new PresentationEx();
SlideEx sld = pres.getSlides().get_Item(0);

ChartEx chart = sld.getShapes().addChart(ChartTypeEx.ScatterWithMarkers, 20, 20, 700-20, 500-20);

//chart.setStyle(StyleTypeEx.Style30);
//chart.setStyle(StyleTypeEx.Style38);
//chart.getChartFormat().getEffect3D().
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
chart.getChartData().getChartDataWorkbook().clear(0);
chart.getChartData().getChartDataWorkbook().clear(1);
chart.getChartData().getChartDataWorkbook().clear(2);
int defaultWorksheetIndex = 0;
ChartDataCellFactory fact = chart.getChartData().getChartDataCellFactory();

String titles [] = new String[]{"s1","s2"};
double values[][]=new double[4][2];
values[0]=new double[]{10,15};
values[1]=new double[]{20,25};
values[2]=new double[]{30,35};
values[3]=new double[]{40,45};
int colNum = values.length;
for(int i=0;i<2;i++)
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, i+1, titles[i]), chart.getType());
ChartSeriesEx series = null;
ArrayList colors = new ArrayList();
for(int i=0;i<2;i++)
{
//Take first chart series
series = chart.getChartData().getSeries().get_Item(i);
//series.getValues().removeAt(0);
//series.getValues().removeAt(0);
//Now updating series data
//fact.getCell(defaultWorksheetIndex, 0, i+1, titles[i]);

for(int r=0;r<colNum;r++)
{
double [] value = values[r];
series.getValues().add(fact.getCell(defaultWorksheetIndex, r+1, i+1, DoubleUtil.transferDouble(value[i])));
}
}
//chart.getChartData().getCategories().add(fact.getCell(0, 0, 0, largeCaption));
//String colTitles[]=new String[]{"c1","c2","c3","c4"};
//for(int i=0;i<colNum;i++)
// chart.getChartData().getCategories().add(fact.getCell(0, i+1, 0, colTitles[i]));


// Save presentation with chart
pres.write("D:\\m111.pptx");


Hi John,

I have observed and worked with the sample code shared by you. You are actually adding a Scatter Chart With Markers but adding two series and adding series values. However, when dealing with Scatter Charts, you need to add values in X and Y. Also, there is one series in scatter chart. Your code is absolutely fine if you would have used Clustered Column and Bar charts. I have modified the sample code shared by you in accordance with Scatter Charts. Please share if I may help you further in this regard.

public static void TestChartWork()
{
PresentationEx pres = new PresentationEx();
SlideEx sld = pres.getSlides().get_Item(0);

ChartEx chart = sld.getShapes().addChart(ChartTypeEx.ScatterWithMarkers, 20, 20, 700-20, 500-20);
//ChartEx chart = sld.getShapes().addChart(ChartTypeEx.ClusteredColumn, 20, 20, 700-20, 500-20);

// chart.setStyle(StyleTypeEx.Style30);
// chart.setStyle(StyleTypeEx.Style38);
// chart.getChartFormat().getEffect3D().
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
chart.getChartData().getChartDataWorkbook().clear(0);
chart.getChartData().getChartDataWorkbook().clear(1);
chart.getChartData().getChartDataWorkbook().clear(2);
int defaultWorksheetIndex = 0;
ChartDataCellFactory fact = chart.getChartData().getChartDataCellFactory();

String titles [] = new String[]{“s1”,“s2”};
String CatTitles [] = new String[]{“c1”,“c2”,“c3”,“c4”};
double values[][]=new double[4][2];
values[0]=new double[]{10,15};
values[1]=new double[]{20,25};
values[2]=new double[]{30,35};
values[3]=new double[]{40,45};
int colNum = values.length;

//Adding categories
//for(int i=0;i<4;i++)
// chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, i+1,0, CatTitles[i]));


for(int i=0;i<1;i++)
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, i+1, titles[i]), chart.getType());


ChartSeriesEx series = null;
series = chart.getChartData().getSeries().get_Item(0);

ArrayList colors = new ArrayList();
for(int i=0;i<2;i++)
{
//Take first chart series
// series = chart.getChartData().getSeries().get_Item(i);
// series.getValues().removeAt(0);
// series.getValues().removeAt(0);
//Now updating series data
// fact.getCell(defaultWorksheetIndex, 0, i+1, titles[i]);

for(int r=0;r<colNum;r++)
{
double [] value = values[r];
if(i==0)

series.getXValues().add(fact.getCell(defaultWorksheetIndex, r+1, i+1, value[i]));
// series.getValues().add(fact.getCell(defaultWorksheetIndex, r+1, i+1, value[i]));
else
// series.getValues().add(fact.getCell(defaultWorksheetIndex, r+1, i+1, value[i]));
series.getYValues().add(fact.getCell(defaultWorksheetIndex, r+1, i+1, value[i]));


}
}
// chart.getChartData().getCategories().add(fact.getCell(0, 0, 0, largeCaption));
//String colTitles[]=new String[]{“c1”,“c2”,“c3”,“c4”};
//for(int i=0;i<colNum;i++)
// chart.getChartData().getCategories().add(fact.getCell(0, i+1, 0, colTitles[i]));




// Save presentation with chart
pres.write(“D:\Aspose Data\m111.pptx”);
}


Many Thanks,