-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot-multi.test.js
More file actions
59 lines (52 loc) · 1.14 KB
/
plot-multi.test.js
File metadata and controls
59 lines (52 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { readDataSync } from 'indian-ocean';
import * as Plot from '@observablehq/plot';
import * as aq from 'arquero';
import plot from '../src/plot.js';
const events = readDataSync('./test/data/purchase_data.csv');
const dataset = aq
.from(events)
.derive({ date: aq.escape(d => new Date(d.date.split('T')[0])) })
.groupby('date', 'brand')
.rollup({ value: d => aq.op.sum(d.price_in_usd), count: aq.op.count() })
.orderby('date', 'brand')
.objects();
// data.forEach(d => {
// d.date = utcFormat('%a')(d.date);
// })
const chart = data =>{
return Plot.plot({
marks: [
Plot.line(data, {
x: 'date',
y: 'value',
stroke: 'brand',
strokeWidth: 2,
curve: 'linear'
})
],
width: 554,
height: 130,
x: { ticks: 3 },
marginLeft: 50,
color: {
legend: true,
width: 554,
columns: '120px'
}
});
}
await plot(chart, [dataset], {
outPath: 'test/tmp/line-plot.png',
view: true,
title: 'Line chart'
});
await plot(chart, [dataset], {
outPath: 'test/tmp/line-plot.png',
view: true,
title: 'Line chart 2'
});
await plot(chart, [dataset], {
outPath: 'test/tmp/line-plot.png',
view: true,
title: 'Line chart3'
});