Platform
Resources
Pricing
Sign in
Contact us
Veli
Workspace
Fork
Published
By
Veli
Edited
Mar 4, 2020
Fork of
Electricity Usage, 2019
1
Insert cell
Insert cell
Insert cell
Insert cell
data
=
d3
.
csvParse
(
await
FileAttachment
(
"cmpco2019@2.csv"
)
.
text
(
)
,
parseData
)
Insert cell
parseData
=
d
=>
(
{
date
:
parseDate
(
`${
d
[
"DateTime"
]
}`
)
,
usage
:
+
d
[
"Value"
]
}
)
Insert cell
parseDate
=
d3
.
timeParse
(
"%_m/%_d/%Y %H:%M"
)
Insert cell
dateExtent
=
d3
.
extent
(
data
,
d
=>
d
.
date
)
Insert cell
x
=
d3
.
scaleBand
(
d3
.
range
(
24
)
,
[
margin
.
left
,
width
-
margin
.
right
]
)
.
round
(
true
)
Insert cell
y
=
d3
.
scaleBand
(
d3
.
timeDays
(
...
dateExtent
)
,
[
margin
.
top
,
height
-
margin
.
bottom
]
)
.
round
(
true
)
Insert cell
color
=
{
let
[
min
,
max
]
=
d3
.
extent
(
data
,
d
=>
d
.
usage
)
;
if
(
min
<
0
)
{
max
=
Math
.
max
(
-
min
,
max
)
;
return
d3
.
scaleDiverging
(
[
-
max
,
0
,
max
]
,
t
=>
d3
.
interpolateRdBu
(
1
-
t
)
)
;
}
return
d3
.
scaleSequential
(
[
0
,
max
]
,
d3
.
interpolateReds
)
;
}
Insert cell
xAxis
=
g
=>
g
.
attr
(
"transform"
,
`translate(0,${
margin
.
top
})`
)
.
call
(
d3
.
axisTop
(
x
)
.
tickFormat
(
formatHour
)
)
.
call
(
g
=>
g
.
select
(
".domain"
)
.
remove
(
)
)
Insert cell
yAxis
=
g
=>
g
.
attr
(
"transform"
,
`translate(${
margin
.
left
},0)`
)
.
call
(
d3
.
axisLeft
(
y
)
.
tickFormat
(
formatDay
)
)
.
call
(
g
=>
g
.
select
(
".domain"
)
.
remove
(
)
)
Insert cell
formatUsage
=
d3
.
format
(
".2f"
)
Insert cell
formatDate
=
d3
.
timeFormat
(
"%B %-d, %-I %p"
)
Insert cell
formatDay
=
{
const
formatMonth
=
d3
.
timeFormat
(
"%b %-d"
)
;
const
formatDate
=
d3
.
timeFormat
(
"%-d"
)
;
return
d
=>
(
d
.
getDate
(
)
===
1
?
formatMonth
:
formatDate
)
(
d
)
;
}
Insert cell
formatHour
=
{
return
d
=>
d
===
0
?
"12 AM"
:
d
===
12
?
"12 PM"
:
(
d
%
12
)
+
""
;
}
Insert cell
width
=
954
Insert cell
height
=
margin
.
top
+
margin
.
bottom
+
(
d3
.
timeDay
.
count
(
...
dateExtent
)
+
1
)
*
10
Insert cell
margin
=
(
{
top
:
70
,
right
:
0
,
bottom
:
0
,
left
:
40
}
)
Insert cell
d3
=
require
(
"d3@5"
)
Insert cell
import
{
legend
}
from
"@d3/color-legend"
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Compare fork
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
chart
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
data
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
parseData
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
parseDate
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
dateExtent
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
x
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
y
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
color
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
xAxis
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
yAxis
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
formatUsage
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
formatDate
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
formatDay
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
formatHour
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
width
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
height
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
margin
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
d3
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML