I'm kinda new to React and I was trying to make a graph using Recharts, but I lost myself in a problem where the lines of the graph doesnt appear.
I use this code
const [ graphData, setgraphData ] = useState([])
const createMockData = () => {
let data = [];
let value = 50;
for (var i = 0; i <= 5 ; i++){
let date = new Date();
date.setHours(0,0,0,0);
date.setDate(i);
value += Math.round((Math.random() < 0.5 ? 1 : 0) * Math.random() * 10);
data.push({x: date, y: value});
}
//console.log(data);
setgraphData(data);
}
useEffect(() => {
createMockData();
});
To create a mockup data and this to present it
<LineChart width={500} height={200} data={graphData}>
<Line type="monotone" dataKey={graphData.x} stroke="var(--mainColor)" />
<XAxis dataKey={graphData.y} />
<Tooltip />
</LineChart>
And I dont know what I'm doing wrong. When I use a normal array it works fine, but I need the graph to be like 100 values.
Thank you
Via Active questions tagged javascript - Stack Overflow https://ift.tt/lGtBC26
Comments
Post a Comment