Java Error Occurs while Creating a Chart Using Aspose.Slides for Node.js

Hi Support,
I’m getting this error while creating chart.

sld = presentation.getSlides().get_Item(4);

for (let i = 0; i < sld.getShapes().size(); i++) {
    const shape = sld.getShapes().get_Item(i);
    console.log('shape.getName()', shape.getName());

    if (shape.getName() == 'Chart 0') {
        const chart = shape;
        // Sets the index for the chart data sheet
        defaultWorksheetIndex = 0;
        // Gets the chart data worksheet
        fact = chart.getChartData().getChartDataWorkbook();

        chart.getChartData().getSeries().clear();
        chart.getChartData().getCategories().clear();

        fact = chart.getChartData().getChartDataWorkbook();
        chart.getChartData().getSeries().add(fact.getCell(0, 0, 1, 'Series 1'), chart.getType());
        series = chart.getChartData().getSeries().get_Item(0);

        chart.getChartData().getCategories().add(fact.getCell(0, 1, 0, 'C1'));
        series.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 1, 1, 24));
        chart.getChartData().getCategories().add(fact.getCell(0, 2, 0, 'C2'));
        series.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 2, 1, 23));
        chart.getChartData().getCategories().add(fact.getCell(0, 3, 0, 'C3'));
        series.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 3, 1, -10));
        chart.getChartData().getCategories().add(fact.getCell(0, 4, 0, 'C4'));
        series.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 4, 1, null));
    }
}

Error:
image.png (28.1 KB)

type or paste code here

type or paste code here

@karanmarsh,
Thank you for contacting support.

Could you please share the presentation file you used?

Hi,
I’m tried to attach the base file here which I have used in presentation to create a new one but it is not allowing as the “pptx” format is not supported to upload.

@andrey.potapov

Hi,
I’ve attached the full code snippet here for reference. Even if I try to create chart with no reference it is throwing error while creating category axis.

var license = new asposeSlides.License();
license.setLicense('aspose.slidesforNode.jsviaJava.lic');

var presentation = new asposeSlides.Presentation();

console.log('pres', presentation);

sld = presentation.getSlides().get_Item(0);

chart = sld.getShapes().addChart(asposeSlides.ChartType.Line, 0, 0, 400, 400);

// Gets the default chart data worksheet index
defaultWorksheetIndex = 0;

// Gets the chart data worksheet
fact = chart.getChartData().getChartDataWorkbook();
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();

chart.getChartData().getSeries().add(fact.getCell(0, 0, 1, 'Series 1'), chart.getType());
series = chart.getChartData().getSeries().get_Item(0);

chart.getChartData().getCategories().add(fact.getCell(0, 1, 0, "C1"));
series.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 1, 1, 24));
chart.getChartData().getCategories().add(fact.getCell(0, 2, 0, "C2"));
series.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 2, 1, 23));
chart.getChartData().getCategories().add(fact.getCell(0, 3, 0, "C3"));
series.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 3, 1, -10));
chart.getChartData().getCategories().add(fact.getCell(0, 4, 0, "C4"));
series.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 4, 1, null));

chart.getChartData().getSeries().add(fact.getCell(0, 0, 2, 'Series 2'), chart.getType());
//Take second chart series
series2 = chart.getChartData().getSeries().get_Item(1);

//Now populating series data
series2.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 1, 2, 30));
series2.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 2, 2, 80));
series2.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 3, 2, 60));
series2.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 4, 2, 40));

type or paste code here

@karanmarsh,
Thank you for the code example. I will get back to you soon.

@karanmarsh,
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESNODEJS-46

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

You can zip files and upload archives here.

@karanmarsh,
Unfortunately, we can’t reproduce the issue, but our developers have analyzed the stack trace and found that the exception related to commons-lang3-node-java.jar that is used in node_modules/java.
It seems you are using modern JDKs, but the commons-lang3-node-java version does not support them.
The list of supported versions:

JAVA_0_9(1.5F, “0.9”),
JAVA_1_1(1.1F, “1.1”),
JAVA_1_2(1.2F, “1.2”),
JAVA_1_3(1.3F, “1.3”),
JAVA_1_4(1.4F, “1.4”),
JAVA_1_5(1.5F, “1.5”),
JAVA_1_6(1.6F, “1.6”),
JAVA_1_7(1.7F, “1.7”),
JAVA_1_8(1.8F, “1.8”),
JAVA_1_9(9.0F, “9”),
JAVA_9(9.0F, “9”)

You can check the current JDK version:

var java = require('java');
var javaVersion = java.callStaticMethodSync('java.lang.System', 'getProperty', 'java.version');
console.log(javaVersion);

We suggest installing the latest JDK 1.8, adding it to JAVA_HOME and running compile-java8-code.cmd from node_modules\java folder.

Hi @andrey.potapov,

I got this version response.
image.png (11.4 KB)

I’m installing jdk17 and trying again.
image.png (49.2 KB)

@karanmarsh,
Thank you for the details. Please check your results using JDK 1.8.

Hi @andrey.potapov

I’ve downgraded my jdk version from 21 to 17 still the issue persists.

var java = require('java');
var aspose = aspose || {};

asposeSlides = require("aspose.slides.via.java");

// var license = new asposeSlides.License();
// license.setLicense("Aspose.SlidesforNode.jsviaJava.lic");

var pres = new asposeSlides.Presentation("Plane Type Model Template v3.pptx");

sld = pres.getSlides().get_Item(3);

// Creates the default chart
chart = sld.getShapes().addChart(asposeSlides.ChartType.Line, 0, 0, 400, 400);

// Gets the default chart data worksheet index
defaultWorksheetIndex = 0;

// Gets the chart data worksheet
fact = chart.getChartData().getChartDataWorkbook();
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();

chart
  .getChartData()
  .getSeries()
  .add(fact.getCell(0, 0, 1, "Series 1"), chart.getType());
series = chart.getChartData().getSeries().get_Item(0);

chart.getChartData().getCategories().add(fact.getCell(0, 1, 0, "c1"));
series.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 1, 1, 24));
chart.getChartData().getCategories().add(fact.getCell(0, 2, 0, "c2"));
series.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 2, 1, 23));
chart.getChartData().getCategories().add(fact.getCell(0, 3, 0, "c3"));
series.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 3, 1, 10));
chart.getChartData().getCategories().add(fact.getCell(0, 4, 0, "c4"));
series.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 4, 1, null));

chart
  .getChartData()
  .getSeries()
  .add(fact.getCell(0, 0, 2, "Series 2"), chart.getType());
//Take second chart series
series2 = chart.getChartData().getSeries().get_Item(1);

//Now populating series data
series2.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 1, 2, 30));
series2.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 2, 2, 10));
series2.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 3, 2, 60));
series2.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 4, 2, 40));

// chart.setLegend(true);
// chart.getLegend().setOverlay(false);

pres.save("out9.pptx", asposeSlides.SaveFormat.Pptx);
console.log("Done");

This is the code.
image.png (19.3 KB)

image.png (35.2 KB)

This is the error I’m getting. Can you please assist.

@karanmarsh,
I was unable to reproduce the error you described. Please install JDK 1.8 as we mentioned above. You don’t have to downgrade JDK, you can have several JDK versions on your OS.

@andrey.potapov

JDK 1.8 works. Issue resolved. Thanks.

@karanmarsh,
We are glad to know that the issue has been resolved on your end. Thank you for using Aspose.Slides.