How to create chart in ppt using given data

Hi,
I want to create editable chart (Bar,pie.etc) in ppt using given data in Java .
I tried to export graph which is in excel to ppt but it is not editable.

@kedar.675,

I have observed your requirements and like to share that Aspose.Slides also supports MSO chart supported by PowerPoint which include bar, clustered and pie charts. I suggest you to please visit this documentation section link for your kind reference.

Hi Mudassir,
Thanks for replying. The data is available in excel from that i have to create charts and after that i have to export it into ppt. How to access that data and create graph from that

@kedar.675,

I have observed your requirements and like to share that Aspose.Slides does allow ReadWorkbookStream() and WrtiteWorkbookStream() methods to read and write chart data workbooks containing chart data edited using Aspose.Cells. However, the chart data needs to be organized in same way or of similar type as of source type. There is no mechanism available to simply pass a chart data from excel and Aspose.Slides may automatically create a chart for that. Please visit following thread link for further elaboration of concept as well.

However, the best option is to create a chart directly using Aspose.Slides without involving external workbooks. You may read data from external workbook and may use that to generate the chart using Aspose.Slides directly.

Hii mudassir,
i tried readWorkbookStream() and writeWorkbookStream() it is generating graph but it is taking only four columns not all.

@kedar.675,

Can you please share the working sample project along with source presentation, generated presentation and desired output presentation. We will be able to investigate the issue further on our end on provision of requested information.

Hi Mudassir,
thanks for replying the sample code is as follows

public class SlidesTest {
public static void main(String[] args) throws Exception {
License license = new License();
// license.setLicense(“‪C:\Users\k\Downloads\Aspose.Cells.lic”);
com.aspose.slides.License l = new com.aspose.slides.License();
// l.setLicense(“C:\Users\k\Downloads\Aspose.Slides.lic”);
Presentation pres = new Presentation();

    IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Pie, 50, 50, 500, 400);
    byte[] msln =chart.getChartData().readWorkbookStream();
    Workbook workbook = new com.aspose.cells.Workbook("C:\\Users\\k\\Desktop\\a1.xlsx");
    java.io.ByteArrayOutputStream mem = new java.io.ByteArrayOutputStream();
    workbook.save(mem, com.aspose.cells.SaveFormat.XLSX);
    chart.getChartData().getChartDataWorkbook();
     chart.getChartData().writeWorkbookStream(mem.toByteArray());
    
    

     pres.save("C:\\Users\\k\\Desktop\\response1.pptx",SaveFormat.Pptx);

}}

a1.zip (39.9 KB)

@kedar.675,

I have observed your requirement. Actually, when you change the chart data from some other workbook, you also need to set the data range in new excel sheet for its linking with chart. Please try using following sample code on your end.

  public static void TestChartData() throws Exception
{
    String path="C:\Aspose Data\a1\";
    Presentation pres = new Presentation();

    IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Pie, 50, 50, 500, 400);
    byte[] msln =chart.getChartData().readWorkbookStream();
    chart.getChartData().getChartDataWorkbook().clear(0);
    Workbook workbook=null;
    try {
        workbook = new com.aspose.cells.Workbook(path+"a1.xlsx");
    } catch (Exception ex) {
        Logger.getLogger(JavaApplication1.class.getName()).log(Level.SEVERE, null, ex);
    }
    java.io.ByteArrayOutputStream mem = new java.io.ByteArrayOutputStream();
    workbook.save(mem, com.aspose.cells.SaveFormat.XLSX);

    chart.getChartData().getChartDataWorkbook();
     chart.getChartData().writeWorkbookStream(mem.toByteArray());
 
     chart.getChartData().setRange("Sheet1!$A$1:$B$9");
     IChartSeries series=chart.getChartData().getSeries().get_Item(0);
     series.getParentSeriesGroup().setColorVaried(true);
     pres.save(path+"response2.pptx",SaveFormat.Pptx);

}

Thank you very much mudassir. It works for me. Really appreciate your support. :slight_smile: :+1::+1: