Home Forums StockChart Support Using with nextJs

Using with nextJs

Viewing 2 posts - 1 through 2 (of 2 total)
  • #34496

    Is there any way to use canvasJs with nextJS ?
    I tried to use canvasjs react stockchart in next app and got an error — “document is not defined”

    #34529

    @vedant,

    The error “document is not defined” is thrown because document is only available inside the browser and not on the server. Next js executes the code on server side and that’s why the error is thrown.

    As a solution, you can use dynamic imports to import a chart component and pass ssr: false as the second argument. This way the imported module will only run inside the context of the browser.

    For example if you want display the Chart as a component then import it dynamically as shown below :

    const StockChart = dynamic(() => import("./Chart/StockChart"), { ssr: false });

    Then use it like a component – <StockChart />

    Please take a look at this working sample project to integrate CanvasJS in Next.js. Also, kindly refer to the instructions.txt file for steps to deploy the sample.

    CanvasJS StockChart in Next.js

    ___________
    Indranil Deo
    Team CanvasJS

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

You must be logged in to reply to this topic.