Skip to content

Commit 85bb607

Browse files
committed
feat: price changes
1 parent 245626a commit 85bb607

File tree

2 files changed

+29
-49
lines changed

2 files changed

+29
-49
lines changed

frontend/src/components/Chart.tsx

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,7 @@
1010
See the License for the specific language governing permissions and
1111
limitations under the License.
1212
*/
13-
import {
14-
ScatterChart,
15-
Scatter,
16-
XAxis,
17-
YAxis,
18-
ZAxis,
19-
CartesianGrid,
20-
Tooltip,
21-
Legend,
22-
ResponsiveContainer,
23-
} from 'recharts';
24-
import { useEffect, useState, SyntheticEvent } from 'react';
13+
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts';
2514

2615
export interface TimeSlot {
2716
x: string;
@@ -34,37 +23,28 @@ export interface ChartProps {
3423
timeSlots: TimeSlot[];
3524
}
3625

37-
const values = [{diesel: 1700, e10: 1750, e5: 1800, x: '19:00'} as TimeSlot, {diesel: 1710, e10: 1760, e5: 1810, x: '19:30'} as TimeSlot]
38-
39-
export default function Chart(props: ChartProps) {
40-
const [avgTimeSlots, setAvgTimeSlots] = useState([] as TimeSlot[])
41-
if(props.timeSlots.length !== avgTimeSlots.length) {
42-
setAvgTimeSlots(props.timeSlots);
43-
}
44-
//console.log(avgTimeSlots);
45-
//console.log(avgTimeSlots.filter(value => value.e5 > 10).map(value => value.e5));
46-
console.log(props.timeSlots);
47-
return ( props.timeSlots.length > 0 ?
48-
<ResponsiveContainer width="100%" height={300}>
49-
<ScatterChart
50-
margin={{
51-
top: 20,
52-
right: 20,
53-
bottom: 20,
54-
left: 20,
55-
}}
56-
>
57-
<CartesianGrid />
58-
<XAxis type="category" dataKey="x" name="time" />
59-
<YAxis type="number" dataKey="e5" name="price" />
60-
<ZAxis type="number" range={[100]} />
61-
<Tooltip cursor={{ strokeDasharray: '3 3' }} />
62-
<Legend />
63-
<Scatter name="E5" data={avgTimeSlots.filter(value => value.e5 > 10).map(value => value.e5)} fill="#8884d8" line shape="cross" />
64-
<Scatter name="E10" data={avgTimeSlots.filter(value => value.e10 > 10).map(value => value.e10)} fill="#82ca9d" line shape="diamond" />
65-
<Scatter name="Diesel" data={avgTimeSlots.filter(value => value.diesel > 10).map(value => value.diesel)} fill="#ff8042" line shape="triangle" />
66-
</ScatterChart>
67-
</ResponsiveContainer>
68-
: <div></div>
69-
);
26+
export default function Chart(props: ChartProps) {
27+
//console.log(props.timeSlots);
28+
return (
29+
<ResponsiveContainer width="100%" height={300}>
30+
<BarChart
31+
margin={{
32+
top: 20,
33+
right: 20,
34+
bottom: 20,
35+
left: 20,
36+
}}
37+
data={props.timeSlots}
38+
>
39+
<CartesianGrid strokeDasharray="3 3" />
40+
<XAxis dataKey="x" />
41+
<YAxis />
42+
<Tooltip />
43+
<Legend />
44+
<Bar dataKey="e5" fill="#8884d8" />
45+
<Bar dataKey="e10" fill="#82ca9d" />
46+
<Bar dataKey="diesel" fill="#82caff" />
47+
</BarChart>
48+
</ResponsiveContainer>
49+
);
7050
}

frontend/src/components/Main.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,12 @@ export default function Main() {
226226
fetch(`/postcode/countytimeslots/${myPostcode}`, requestOptions2).then(myResult1 => myResult1.json() as Promise<TimeSlotResponse[]>).then(myJson1 => {
227227
const timeSlots = [] as TimeSlot[];
228228
timeSlots.push(...myJson1.filter(myValue => myValue.AvgDiesel > 10).map(myValue => {
229-
const dieselTimeSlot = {x: '', diesel: 0, e10: 0, e5: 0} as TimeSlot;
229+
const dieselTimeSlot = {x: '00.00', diesel: 0, e10: 0, e5: 0} as TimeSlot;
230230
const myDate = new Date(myValue.StartDate);
231231
dieselTimeSlot.x = ''+myDate.getHours()+':'+myDate.getMinutes();
232-
dieselTimeSlot.diesel = myValue.AvgDiesel;
233-
dieselTimeSlot.e10 = myValue.AvgE10;
234-
dieselTimeSlot.e5 = myValue.AvgE5;
232+
dieselTimeSlot.diesel = myValue.AvgDiesel/1000;
233+
dieselTimeSlot.e10 = myValue.AvgE10/1000;
234+
dieselTimeSlot.e5 = myValue.AvgE5/1000;
235235
return dieselTimeSlot;
236236
}));
237237
setAvgTimeSlots(timeSlots);

0 commit comments

Comments
 (0)