10
10
See the License for the specific language governing permissions and
11
11
limitations under the License.
12
12
*/
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' ;
25
14
26
15
export interface TimeSlot {
27
16
x : string ;
@@ -34,37 +23,28 @@ export interface ChartProps {
34
23
timeSlots : TimeSlot [ ] ;
35
24
}
36
25
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
+ ) ;
70
50
}
0 commit comments