Adding series to chart in Open Office file

Hi Team,

Could you please provide me the code to get what I have added in the sheet manually. Please provide me the sample code.

Regards
YasaswiniNew folder.zip (11.1 KB)

@YaSaSwini,

Thanks for the template file and details.

Please try our latest version/fix (e.g Aspose.Cells for Java v18.5.x). See the following sample code for your reference. I have opened your template ODS file and used its data for chart’s data source. I added a new chart to the first worksheet to mimic the chart with your designer chart in the sheet. I finally generated both XLSX and ODS file(s) which contain the new chart for your reference:
e.g
Sample code:

Workbook workbook = new Workbook("f:\\files\\TestOpenOffice.ods");
		WorksheetCollection worksheets = workbook.getWorksheets();

		// Obtaining the reference of the first worksheet
		Worksheet worksheet = worksheets.get(0);
		Cells cells = worksheet.getCells();

		// Adding a chart to the worksheet
		ChartCollection charts = worksheet.getCharts();

		// Accessing the instance of the newly added chart
		int chartIndex = charts.add(ChartType.BAR, 35, 5, 59, 25);
		Chart chart = charts.get(chartIndex);

		SeriesCollection nSeries = chart.getNSeries();
		nSeries.add("E5:F10", true);
		nSeries.setCategoryData("D5:D10");
		
		Series aSeries = chart.getNSeries().get(0);
        String sname = "=E4";
        aSeries.setName(sname);
        
        Series aSeries1 = chart.getNSeries().get(1);
        String sname1 = "=F4";
        aSeries1.setName(sname1);
        

		
		workbook.save("f:\\files\\outsampleChart.xlsx");
		workbook.save("f:\\files\\outsampleChart1.ods", SaveFormat.ODS); 

Hope, this helps a bit.

Hi Amjad,

I tried your sample code. am able to generate the chart in excel whereas if I open the generated open office ods file I could see a blank chart instead of chart with data.

Below is the screenshots for your reference.

image.png (20.2 KB)

image.png (21.3 KB)

Could you please help me on this.

@YaSaSwini,

Which version of the product you are using? I am using our latest version/fix: Aspose.Cells for Java v18.5.x (please try it) and it works fine, see the screenshot of the charts which are displayed when opening the output ODS file into my openoffice.org 3.x.x version: