Home Forums Report Bugs By default the height of the chart is 400 in react Reply To: By default the height of the chart is 400 in react

#60170

@scompliance,

To ensure that the chart adjusts to the updated height, you can use a key prop on the CanvasJSChart component. When the height state changes, updating the key prop will force React to treat the component as a new one, which will apply the updated height. Please find the updated code-snippet below.

return (
  <div>
    <CanvasJSChart
      options={options}
      containerProps={{ width: "100%", height }}
      key={height}  // This forces re-mount when the height changes
    />
  </div>
);

Another option is to directly update the chart’s height using the set methodchart.set("height", 100). Please refer to this Codesandbox link for updated code.


Vishwas R
Team CanvasJS