Home Forums Chart Support CanvasJS with Electron/Node.js

CanvasJS with Electron/Node.js

Viewing 3 posts - 1 through 3 (of 3 total)
  • #21240

    Hi,

    I’m trying to use CanvasJS with Electron, but I’m getting the bellow error:

    A JavaScript error occurred in the main process
    Uncaught Exception:
    import CanvasJS from ‘canvasjs’;
    ^^^^^^

    SyntaxError: Unexpected token import

    In my code, I’m requiring CanvasJS as below:

    var CanvasJS = require(‘canvasjs’);

    Is there a workaround to solve this issue?

    Best regards

    #21257

    Solved!

    Since Electron doesn’t support ES6 syntaxes, I used babel to convert from ES6 to CommonJS.

    Anyway, there is a error on npm module in the following file:

    node_modules/canvasjs/src/charts/index.js

    The “export” syntaxes must be changed to “import”.

    Best regards

    #21258

    @DanielSore,

    Glad that you figured it out. Also, below are the steps to import CanvasJS chart in an electron app.

    1. Download the library from our download page and save it in your source folder.
    2. To use CanvasJS Chart in your electron app, you need to import CanvasJS from canvasjs.min.js. Please find the below snippet for the same
    var CanvasJS = require('./canvasjs.min')

    Here is a complete code example for integrating Chart with an electon app.

    Basic Column Chart

    __
    Priyanka M S
    Team CanvasJS

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.