PptxGenJS add chart show nothing

1.2k views Asked by At

I am working with an export function by using PptxGenJS. It does not work even with basic example code from demo source code on official Github. I am working with export charts.

My steps:

  • Install PptxGenJS and import like normal npm package.
  • Copy code from official demo: slide.addChart( pptx.charts.BAR, arrDataRegions, optsChartBar1 );

The result:

  • Chart show nothing in exported slider.
  • Open with Microsoft Powerpoint 2013, it shows some error similar to this question.
  • My codesanbox even worse, no file were downloaded.

My notable package versions:

"react": "^16.13.1",
"pptxgenjs": "^2.6.0",

My environment versions:

  • node version: v10.17.0
  • npm version: v6.11.3
  • Windows 10 Pro 1903, OS build 18362.1082

Both two versions of Pptxgenjs do not work. Any thoughts on this? Thanks for any idea. I'm giving up on this library.

1

There are 1 answers

1
Boopathy On

Maybe case-sensitive. Change your BAR to bar like below,

import pptxgen from "pptxgenjs";

let pres = new pptxgen();
let slide = pres.addSlide();
let dataChartAreaLine = [
            {
                name: "Actual Sales",
                labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
                values: [1500, 4600, 5156, 3167, 8510, 8009],
            },
            {
                name: "Projected Sales",
                labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
                values: [1000, 2600, 3456, 4567, 5010, 6009],
            },
        ];

        slide.addChart(pres.ChartType.bar, dataChartAreaLine, { x: 2, y: 2, w: 6, h: 3, showLegend: true });

pres.writeFile("Sample Presentation.pptx");