add daychart
This commit is contained in:
41
frontend/src/components/resourcechart/resourcechart.js
Normal file
41
frontend/src/components/resourcechart/resourcechart.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend,
|
||||
} from 'recharts';
|
||||
|
||||
export default function (day, kind) {
|
||||
|
||||
const [data, setData] = React.useState(null);
|
||||
|
||||
const loadData = async () => {
|
||||
let nextData = await fetch(`/API/day?date=${day}&kind=${kind}`);
|
||||
nextData = await nextData.json();
|
||||
for (let i = 0; i < nextData.length; i++) {
|
||||
nextData[i]["time"] = new Date(nextData[i]["time"]);
|
||||
nextData[i]["time"] = nextData[i]["time"].toLocaleTimeString();
|
||||
}
|
||||
setData(nextData)
|
||||
}
|
||||
|
||||
if (data === null) {
|
||||
loadData();
|
||||
}
|
||||
|
||||
return (
|
||||
<LineChart
|
||||
width={900}
|
||||
height={300}
|
||||
data={data}
|
||||
margin={{
|
||||
top: 5, right: 30, left: 20, bottom: 5,
|
||||
}}
|
||||
>
|
||||
<CartesianGrid strokeDasharray="3 3" />
|
||||
<XAxis dataKey="time" interval="2" />
|
||||
<YAxis domain={['datamin', 'datamax']} />
|
||||
<Tooltip />
|
||||
<Legend />
|
||||
<Line type="monotone" dataKey="price" stroke="#8884d8" dot={false} />
|
||||
</LineChart>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user