Sorry I’m new to reactjs. I’m making a chart using Morrish.js
i am using Morris.js for my reactjs project.
However, when building, it gives an error like this
ERROR in ./src/component/chart/sprint_chart.tsx
Module not found: Error: Can't resolve 'morris.js' in '/Users/cuongnm1/Documents/IH/insighthub/webapp/src/component/chart'
@ ./src/component/chart/sprint_chart.tsx 3:0-36 8:4-15
@ ./src/component/chart/broad_chart.tsx
@ ./src/index.tsx
@ multi ./src/index.tsx
This is my code
import React, {useEffect} from 'react';
import 'morris.js/morris.css';
import * as Morris from 'morris.js';
const CustomChart: React.FC = () => {
useEffect(() => {
// Khởi tạo Morris.js chỉ sau khi component đã được mount
Morris.Area({
element: 'area-chart',
data: [
{y: '2014', a: 150, b: 150},
{y: '2015', a: 135, b: 120},
{y: '2015', a: 135, b: 140},
{y: '2016', a: 120, b: 125},
{y: '2017', a: 105, b: 110},
{y: '2018', a: 90, b: 105},
{y: '2019', a: 75, b: 60},
{y: '2020', a: 60, b: 45},
{y: '2021', a: 45, b: 35},
{y: '2022', a: 30, b: 25},
{y: '2023', a: 15, b: 10},
{y: '2024', a: 0, b: 10},
],
xkey: 'y',
ykeys: ['a', 'b'],
labels: ['Total Income', 'Total Outcome'],
hideHover: 'auto',
behaveLikeLine: true,
resize: true,
pointFillColors: ['#1B7837', '#800026'],
lineColors: ['#5AAE61', '#800026'],
fillOpacity: 0.2,
});
}, []); // Chỉ chạy một lần sau khi component mount
return (
<div>
<h3 className='text-primary text-center'>Sprint Chart</h3>
<div className='row'>
<div className='col-sm-6 text-center'>
<label className='label label-success'>Area Chart</label>
<div id='area-chart' style={{minHeight: '450px'}}/>
</div>
</div>
</div>
);
};
export default CustomChart;
also when pointing to ‘morris.js’ in the import. it will also give error
is not a module.
ESLint: Unable to resolve path to module 'morris.js'.(import/no-unresolved)
I tried creating a morris.js.d.ts file and adding this code. but still not
declare module 'morris.js';