CanvasJS v3.2.15 does not work inside the React TypeScript project.
Following steps were taken to install it:
1. put canvasjs.min.js and canvasjs.react.js into src/assets/ folder
2. Import it into a component as per code below
import React, { FC } from 'react';
import CanvasJSReact from '../../../assets/canvasjs.react.js';
import { TsChartProps } from './types';
import { useStyles } from './styles';
export const TsChart: FC<TsChartProps> = ({ title = '', height, width }) => {
let CanvasJSChart = CanvasJSReact.CanvasJSChart;
const classes = useStyles({ height, width });
const options = {
title: {
text: 'Basic Column Chart in React',
},
data: [
{
type: 'column',
dataPoints: [
{ label: 'Apple', y: 10 },
{ label: 'Orange', y: 15 },
{ label: 'Banana', y: 25 },
{ label: 'Mango', y: 30 },
{ label: 'Grape', y: 28 },
],
},
],
};
return (
<div className={classes.chart}>
<CanvasJSChart options={options} />
</div>
);
};
3. yarn start or npm start get stuck forever.
4. commenting out CanvasJS stuff from component, yarn start and npm start starts up the project just fine.
This is a TypeScript project. Are there instructions available to get CanvasJS working in React TypeScript? Because at the moment it’s totally broken.
Thanks.