1
1
import React from "react"
2
- import { Box , Center , useToken } from "@chakra-ui/react"
2
+ import { Box , Center , useBreakpointValue , useToken } from "@chakra-ui/react"
3
3
import {
4
4
BarChart ,
5
5
Bar ,
6
6
Cell ,
7
7
XAxis ,
8
- YAxis ,
9
8
Text ,
10
9
LabelList ,
11
10
ResponsiveContainer ,
@@ -21,6 +20,12 @@ interface ITickProps {
21
20
payload : { value : number | string }
22
21
}
23
22
23
+ type Data = Array < {
24
+ name : string
25
+ amount : number
26
+ color : string
27
+ } >
28
+
24
29
const CustomTick : React . FC < ITickProps > = ( { x, y, payload } ) => {
25
30
const textColor = useToken ( "colors" , "text" )
26
31
@@ -47,77 +52,137 @@ const EnergyConsumptionChart: React.FC = () => {
47
52
48
53
const textColor = useToken ( "colors" , "text" )
49
54
50
- const data = [
51
- {
52
- name : "Global data centers" ,
53
- amount : 190 ,
54
- color : "#C1B6F5" ,
55
- } ,
56
- {
57
- name : "Bitcoin" ,
58
- amount : 149 ,
59
- color : "#C1B6F5" ,
60
- } ,
61
- {
62
- name : "Gold mining" ,
63
- amount : 131 ,
64
- color : "#C1B6F5" ,
65
- } ,
66
- {
67
- name : "Gaming in USA" ,
68
- amount : 34 ,
69
- color : "#C1B6F5" ,
70
- } ,
71
- {
72
- name : "PoW Ethereum" ,
73
- amount : 21 ,
74
- color : "#C1B6F5" ,
75
- } ,
76
- {
77
- name : "Google" ,
78
- amount : 19 ,
79
- color : "#C1B6F5" ,
80
- } ,
81
- {
82
- name : "Netflix" ,
83
- amount : 0.457 ,
84
- color : "#C1B6F5" ,
85
- } ,
86
- {
87
- name : "PayPal" ,
88
- amount : 0.26 ,
89
- color : "#C1B6F5" ,
90
- } ,
91
- {
92
- name : "Airbnb" ,
93
- amount : 0.02 ,
94
- color : "#C1B6F5" ,
95
- } ,
96
- {
97
- name : "PoS Ethereum" ,
98
- amount : 0.0026 ,
99
- color : "#C1B6F5" ,
100
- } ,
101
- ]
55
+ const data = useBreakpointValue < Data > ( {
56
+ base : [
57
+ {
58
+ name : t ( "energy-consumption-chart-global-data-centers-label" ) ,
59
+ amount : 190 ,
60
+ color : "#FF0000" ,
61
+ } ,
62
+ {
63
+ name : t ( "energy-consumption-chart-btc-pow-label" ) ,
64
+ amount : 149 ,
65
+ color : "#F2A900" ,
66
+ } ,
67
+ {
68
+ name : t ( "energy-consumption-chart-gaming-us-label" ) ,
69
+ amount : 34 ,
70
+ color : "#71BB8A" ,
71
+ } ,
72
+ {
73
+ name : t ( "energy-consumption-chart-eth-pow-label" ) ,
74
+ amount : 21 ,
75
+ color : "#C1B6F5" ,
76
+ } ,
77
+ {
78
+ name : t ( "energy-consumption-chart-eth-pos-label" ) ,
79
+ amount : 0.0026 ,
80
+ color : "#C1B6F5" ,
81
+ } ,
82
+ ] ,
83
+ sm : [
84
+ {
85
+ name : t ( "energy-consumption-chart-global-data-centers-label" ) ,
86
+ amount : 190 ,
87
+ color : "#FF0000" ,
88
+ } ,
89
+ {
90
+ name : t ( "energy-consumption-chart-btc-pow-label" ) ,
91
+ amount : 149 ,
92
+ color : "#D7B14A" ,
93
+ } ,
94
+ {
95
+ name : t ( "energy-consumption-gold-mining-cbeci-label" ) ,
96
+ amount : 131 ,
97
+ color : "#F2A900" ,
98
+ } ,
99
+ {
100
+ name : t ( "energy-consumption-chart-eth-pow-label" ) ,
101
+ amount : 21 ,
102
+ color : "#C1B6F5" ,
103
+ } ,
104
+ {
105
+ name : t ( "energy-consumption-chart-netflix-label" ) ,
106
+ amount : 0.457 ,
107
+ color : "#E50914" ,
108
+ } ,
109
+ {
110
+ name : t ( "energy-consumption-chart-eth-pos-label" ) ,
111
+ amount : 0.0026 ,
112
+ color : "#C1B6F5" ,
113
+ } ,
114
+ ] ,
115
+ md : [
116
+ {
117
+ name : t ( "energy-consumption-chart-global-data-centers-label" ) ,
118
+ amount : 190 ,
119
+ color : "#FF0000" ,
120
+ } ,
121
+ {
122
+ name : t ( "energy-consumption-chart-btc-pow-label" ) ,
123
+ amount : 149 ,
124
+ color : "#D7B14A" ,
125
+ } ,
126
+ {
127
+ name : t ( "energy-consumption-gold-mining-cbeci-label" ) ,
128
+ amount : 131 ,
129
+ color : "#D7B14A" ,
130
+ } ,
131
+ {
132
+ name : t ( "energy-consumption-chart-gaming-us-label" ) ,
133
+ amount : 34 ,
134
+ color : "#71BB8A" ,
135
+ } ,
136
+ {
137
+ name : t ( "energy-consumption-chart-eth-pow-label" ) ,
138
+ amount : 21 ,
139
+ color : "#C1B6F5" ,
140
+ } ,
141
+ {
142
+ name : "Google" ,
143
+ amount : 19 ,
144
+ color : "#E50914" ,
145
+ } ,
146
+ {
147
+ name : t ( "energy-consumption-chart-netflix-label" ) ,
148
+ amount : 0.457 ,
149
+ color : "#E50914" ,
150
+ } ,
151
+ {
152
+ name : t ( "energy-consumption-chart-paypal-label" ) ,
153
+ amount : 0.26 ,
154
+ color : "#C1B6F5" ,
155
+ } ,
156
+ {
157
+ name : "AirBnB" ,
158
+ amount : 0.02 ,
159
+ color : "#E50914" ,
160
+ } ,
161
+ {
162
+ name : t ( "energy-consumption-chart-eth-pos-label" ) ,
163
+ amount : 0.0026 ,
164
+ color : "#C1B6F5" ,
165
+ } ,
166
+ ] ,
167
+ } )
102
168
103
169
return (
104
170
< Center w = "full" >
105
171
< Box maxW = "500px" w = "full" >
106
- < ResponsiveContainer height = { 550 } >
172
+ < ResponsiveContainer height = { 500 } >
107
173
< BarChart
108
- margin = { { top : 30 , right : 40 , bottom : 30 , left : 20 } }
174
+ margin = { { top : 30 , right : 30 , bottom : 30 , left : 30 } }
175
+ barGap = { 15 }
176
+ barSize = { 38 }
109
177
data = { data }
110
- barGap = { 20 }
111
- barSize = { 30 }
112
- layout = { "vertical" }
113
178
>
114
- < XAxis type = { "number" } orientation = { "bottom" } />
115
- < YAxis
116
- type = { "category" }
117
- orientation = { "left" }
118
- dataKey = { "name" }
119
- tick = { { fontSize : 14 } }
120
- width = { 120 }
179
+ < XAxis
180
+ dataKey = "name"
181
+ tickLine = { false }
182
+ axisLine = { false }
183
+ // @ts -ignore
184
+ tick = { < CustomTick /> }
185
+ interval = { 0 }
121
186
/>
122
187
< Legend
123
188
content = {
@@ -133,7 +198,7 @@ const EnergyConsumptionChart: React.FC = () => {
133
198
isAnimationActive = { false }
134
199
>
135
200
< LabelList
136
- position = "right "
201
+ position = "top "
137
202
fill = { textColor }
138
203
fontSize = { 14 }
139
204
offset = { 10 }
0 commit comments