Morris.js
9.75 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
import React, { PureComponent } from 'react';
import {
Row,
Col,
Breadcrumb,
BreadcrumbItem,
} from 'reactstrap';
import $ from 'jquery';
/* eslint-disable */
import 'imports-loader?jQuery=jquery,this=>window!webpack-raphael/raphael';
import 'imports-loader?jQuery=jquery,this=>window!govpredict-morris/morris';
/* eslint-enable */
import Widget from '../../../components/Widget';
const Morris = window.Morris;
class MorrisCharts extends PureComponent {
componentDidMount() {
this.initMorrisLineChart();
this.initMorrisAreaChart();
this.initMorrisBarChart();
this.initMorrisBar2Chart();
this.initMorrisDonutChart();
this.initMorrisStackedChart();
}
initMorrisLineChart() {
$(this.morrisLineChart).html('');
Morris.Line({
element: this.morrisLineChart,
resize: true,
data: [
{ y: '2006', a: 100, b: 90 },
{ y: '2007', a: 75, b: 65 },
{ y: '2008', a: 50, b: 40 },
{ y: '2009', a: 75, b: 65 },
{ y: '2010', a: 50, b: 40 },
{ y: '2011', a: 75, b: 65 },
{ y: '2012', a: 100, b: 90 },
],
xkey: 'y',
ykeys: ['a', 'b'],
labels: ['Series A', 'Series B'],
lineColors: ['#8fe5d4', '#ffebb2'],
});
}
initMorrisAreaChart() {
$(this.morrisAreaChart).html('');
Morris.Area({
element: this.morrisAreaChart,
resize: true,
data: [
{ y: '2006', a: 100, b: 90 },
{ y: '2007', a: 75, b: 65 },
{ y: '2008', a: 50, b: 40 },
{ y: '2009', a: 75, b: 65 },
{ y: '2010', a: 50, b: 40 },
{ y: '2011', a: 75, b: 65 },
{ y: '2012', a: 100, b: 90 },
],
xkey: 'y',
ykeys: ['a', 'b'],
labels: ['Users A', 'Series B'],
lineColors: ['#8fe5d4', '#ffd7de'],
lineWidth: 0,
});
}
initMorrisBarChart() {
$(this.morrisBarChart).html('');
Morris.Bar({
element: this.morrisBarChart,
resize: true,
grid: false,
data: [
{ y: 4, x: 'Linux' },
{ y: 12, x: 'MacOS' },
{ y: 29, x: 'Windows' },
],
xkey: 'x',
ykeys: ['y'],
labels: ['OS Users, %'],
barColors: ['#b7b3ff'],
gridTextColor: '#c1ccd3',
});
}
initMorrisBar2Chart() {
$(this.morrisBar2Chart).html('');
Morris.Bar({
element: this.morrisBar2Chart,
resize: true,
grid: false,
data: [
{ y: '2014', a: 50, b: 90 },
{ y: '2015', a: 65, b: 75 },
{ y: '2016', a: 50, b: 50 },
{ y: '2017', a: 75, b: 60 },
{ y: '2018', a: 80, b: 65 },
{ y: '2019', a: 90, b: 70 },
{ y: '2020', a: 100, b: 75 },
{ y: '2021', a: 115, b: 75 },
{ y: '2022', a: 120, b: 85 },
{ y: '2023', a: 145, b: 85 },
{ y: '2024', a: 160, b: 95 },
],
xkey: 'y',
ykeys: ['a', 'b'],
labels: ['Total Income', 'Total Outcome'],
hideHover: 'auto',
barColors: ['#8fe5d4', '#f59f9f'],
gridTextColor: '#d6dee5',
});
}
initMorrisDonutChart() {
$(this.morrisDonutChart).html('');
Morris.Donut({
element: this.morrisDonutChart,
resize: true,
data: [
{ label: 'Download Sales', value: 12 },
{ label: 'In-Store Sales', value: 30 },
{ label: 'Mail-Order Sales', value: 20 },
],
colors: ['#ffd7de', '#ffebb2', '#e2e1ff'],
});
}
initMorrisStackedChart() {
$(this.morrisStackedChart).html('');
Morris.Bar({
element: this.morrisStackedChart,
stacked: true,
resize: true,
data: [
{ y: '2012', a: 3, b: 7, c: 90, d: 0 },
{ y: '2013', a: 2, b: 7, c: 75, d: 14 },
{ y: '2014', a: 3, b: 15, c: 65, d: 4 },
{ y: '2015', a: 3, b: 17, c: 56, d: 20 },
{ y: '2016', a: 5, b: 16, c: 49, d: 30 },
{ y: '2017', a: 4, b: 20, c: 40, d: 36 },
{ y: '2018', a: 5, b: 20, c: 40, d: 35 },
],
xkey: 'y',
ykeys: ['a', 'b', 'c', 'd'],
barColors: ['#a7beff', '#e2e1ff', '#fff8e3', '#ffd7de'],
labels: ['Linux', 'MacOS', 'Windows', 'Other'],
hoverCallback(index, options, content, row) {
const keys = Object.keys(row).splice(1).sort();
let tooltip = `
<div class="card" style="width: 11rem;"><div class="card-body">
<h5 class="card-title">${row.y} OS Shares</h5>
<h6 class="card-subtitle mb-2 text-muted">Statistics for most popular Operation Systems Usage</h6>`;
const rows = [];
keys.forEach((value, id) => {
rows.push(
(`<tr>
<td>${options.labels[id]}: </td>
<td>${row[value]}%</td>
</tr>`).trim(),
);
});
tooltip += '<table class="table"><tbody>';
tooltip += rows.join('');
tooltip += '</tbody></table></div></div>';
return tooltip;
},
hideHover: 'auto',
});
}
render() {
return (
<div>
<Breadcrumb>
<BreadcrumbItem>YOU ARE HERE</BreadcrumbItem>
<BreadcrumbItem>Charts</BreadcrumbItem>
<BreadcrumbItem active>Morris</BreadcrumbItem>
</Breadcrumb>
<h1 className="page-title">Visual - <span className="fw-semi-bold">Charts</span></h1>
<Row>
<Col lg={6} xs={12}>
<Widget
title={<h5> Morris <span className="fw-semi-bold">Line Chart</span></h5>}
close collapse
>
<div>
<p className="fs-mini text-muted">
Good-looking charts shouldn't be difficult.
The public API is terribly simple. It's just one function: <code>Morris.Line(options)</code>,
where options is an object containing some of the following configuration options.
</p>
<div className="text-center" ref={(r) => { this.morrisLineChart = r; }} style={{ height: '343px' }} />
</div>
</Widget>
</Col>
<Col lg={6} xs={12}>
<Widget
title={<h5> Morris <span className="fw-semi-bold">Area Chart</span></h5>}
close collapse
>
<div>
<p className="fs-mini text-muted">
Good-looking charts shouldn't be difficult.
The public API is terribly simple. It's just one function: <code>Morris.Line(options)</code>,
where options is an object containing some of the following configuration options.
</p>
<div className="text-center" ref={(r) => { this.morrisAreaChart = r; }} style={{ height: '343px' }} />
</div>
</Widget>
</Col>
<Col lg={5} xs={12}>
<Widget
title={<h5> Morris <span className="fw-semi-bold">Bar Chart</span></h5>}
close collapse
>
<div>
<div className="text-center" ref={(r) => { this.morrisBarChart = r; }} style={{ height: '260px' }} />
<p className="fs-mini text-muted">
Bar charts are also commonly referred to as a column charts. If you was trying to compare
the height of something then intuitvely you would represent this by using columns. This
really couldn't be easier. Create a Bar chart using <code>Morris.Bar(options)</code>,
with only few options.
</p>
</div>
</Widget>
</Col>
<Col lg={3} xs={12}>
<Widget
title={<h5> Morris <span className="fw-semi-bold">Donut Chart</span></h5>}
close collapse
>
<div>
<div className="text-center" ref={(r) => { this.morrisDonutChart = r; }} style={{ height: '180px' }} />
<p className="fs-mini text-muted">
Donuts a great for representing some parted information like traffice sources, disk partitions,
etc. This really couldn't be easier. Create a Donut chart using <code>Morris.Bar(options)</code>,
with only few options.
</p>
</div>
</Widget>
</Col>
<Col lg={4} xs={12}>
<Widget
title={<h5> Morris <span className="fw-semi-bold">Bar Chart 2</span></h5>}
close collapse
>
<div>
<div className="text-center" ref={(r) => { this.morrisBar2Chart = r; }} style={{ height: '180px' }} />
<p className="fs-mini text-muted">
This is generally a good chart to choose for all comparison based analysis but if you were to
display a data set with negative values a column would be the best to represent this. This
really couldn't be easier. Create a Bar chart using <code>Morris.Bar(options)</code>,
with only few options.
</p>
</div>
</Widget>
</Col>
<Col xs={12}>
<Widget
title={<h5> Morris <span className="fw-semi-bold">Stacked Bar Chart</span></h5>}
close collapse
>
<div>
<div className="text-center" ref={(r) => { this.morrisStackedChart = r; }} style={{ height: '200px' }} />
<p className="fs-mini text-muted">
Stacked charts are excellent to track some dynamics within declared categories. An example of this
can be seen above. To create a Stacked Bar chart use <code>Morris.Bar(options)</code> and
set <code>stacked</code>, option to true.
</p>
</div>
</Widget>
</Col>
</Row>
</div>
);
}
}
export default MorrisCharts;