Skip to content

Commit 809a5dd

Browse files
committed
Add Dashboard GroupedBarChart
1 parent e4ac09b commit 809a5dd

File tree

2 files changed

+116
-14
lines changed
  • client/src/views/Dashboard

2 files changed

+116
-14
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
import {
5+
BarChart,
6+
Bar,
7+
XAxis,
8+
YAxis,
9+
Tooltip,
10+
Legend,
11+
ResponsiveContainer,
12+
LabelList,
13+
} from 'recharts';
14+
15+
function CustomizedLabel(props) {
16+
const { x, y, width, value } = props;
17+
return (
18+
<text
19+
x={x + width / 2}
20+
y={y}
21+
dy={-8}
22+
fontSize="12"
23+
>
24+
{value}
25+
</text>
26+
);
27+
}
28+
29+
export default function GroupedBarChart(props) {
30+
const {
31+
data,
32+
} = props;
33+
34+
35+
if (data.values.length <= 0) {
36+
return (
37+
<div>Nothing to show</div>
38+
);
39+
}
40+
41+
return (
42+
<ResponsiveContainer
43+
height={250}
44+
width="100%"
45+
>
46+
<BarChart
47+
data={data.values}
48+
margin={{ top: 50 }}
49+
>
50+
<XAxis dataKey="date" />
51+
<YAxis />
52+
<Tooltip />
53+
<Legend align="center" />
54+
{data.columns.map(column => (
55+
<Bar
56+
dataKey={column}
57+
key={column}
58+
fill={data.colors[column]}
59+
label={<CustomizedLabel />}
60+
/>
61+
))}
62+
</BarChart>
63+
</ResponsiveContainer>
64+
);
65+
}
66+
67+
GroupedBarChart.propTypes = {
68+
data: PropTypes.object.isRequired,
69+
};

client/src/views/Dashboard/SummaryContainer/TrendSummary/index.js

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
import GroupedBarChart from '#rscz/GroupedBarChart';
1616
import Legend from '#rscz/Legend';
1717

18+
import GroupedBarChartRecharts from '../../GroupedBarChart';
19+
1820
import styles from './styles.scss';
1921

2022
const propTypes = {
@@ -279,11 +281,11 @@ class TrendSummary extends React.PureComponent {
279281
values,
280282
columns: [
281283
'Total Closed',
282-
'Closed On',
284+
'Closed On Time',
283285
],
284286
colors: {
285287
'Total Closed': '#44df96',
286-
'Closed On': '#c25be2',
288+
'Closed On Time': '#c25be2',
287289
},
288290
});
289291
});
@@ -330,7 +332,12 @@ class TrendSummary extends React.PureComponent {
330332
<div className={_cs(styles.trend, className)}>
331333
<div className={_cs(styles.item)}>
332334
<h3> RC Supply Trend </h3>
333-
<GroupedBarChart
335+
{rcData.values.length > 0 && (
336+
<GroupedBarChartRecharts
337+
data={rcData}
338+
/>
339+
)}
340+
{/* <GroupedBarChart
334341
data={rcData}
335342
groupSelector={groupSelector}
336343
lineDataSelector={rcLineSelector}
@@ -342,11 +349,16 @@ class TrendSummary extends React.PureComponent {
342349
keySelector={legendKeySelector}
343350
labelSelector={legendLabelSelector}
344351
colorSelector={legendColorSelector}
345-
/>
352+
/> */}
346353
</div>
347354
<div className={_cs(styles.item)}>
348355
<h3> Child Monitoring Trend </h3>
349-
<GroupedBarChart
356+
{childMonitoringData.values.length > 0 && (
357+
<GroupedBarChartRecharts
358+
data={childMonitoringData}
359+
/>
360+
)}
361+
{/* <GroupedBarChart
350362
data={childMonitoringData}
351363
groupSelector={groupSelector}
352364
lineDataSelector={childMonitoringLineSelector}
@@ -358,11 +370,16 @@ class TrendSummary extends React.PureComponent {
358370
keySelector={legendKeySelector}
359371
labelSelector={legendLabelSelector}
360372
colorSelector={legendColorSelector}
361-
/>
373+
/> */}
362374
</div>
363375
<div className={_cs(styles.item)}>
364376
<h3> Health Nutrition Trend </h3>
365-
<GroupedBarChart
377+
{healthData.values.length > 0 && (
378+
<GroupedBarChartRecharts
379+
data={healthData}
380+
/>
381+
)}
382+
{/* <GroupedBarChart
366383
data={healthData}
367384
groupSelector={groupSelector}
368385
showValue
@@ -373,11 +390,16 @@ class TrendSummary extends React.PureComponent {
373390
keySelector={legendKeySelector}
374391
labelSelector={legendLabelSelector}
375392
colorSelector={legendColorSelector}
376-
/>
393+
/> */}
377394
</div>
378395
<div className={_cs(styles.item)}>
379396
<h3> Correspondence Trend </h3>
380-
<GroupedBarChart
397+
{correspondenceData.values.length > 0 && (
398+
<GroupedBarChartRecharts
399+
data={correspondenceData}
400+
/>
401+
)}
402+
{/* <GroupedBarChart
381403
data={correspondenceData}
382404
groupSelector={groupSelector}
383405
showValue
@@ -388,11 +410,16 @@ class TrendSummary extends React.PureComponent {
388410
keySelector={legendKeySelector}
389411
labelSelector={legendLabelSelector}
390412
colorSelector={legendColorSelector}
391-
/>
413+
/> */}
392414
</div>
393415
<div className={_cs(styles.item)}>
394416
<h3> Education Trend </h3>
395-
<GroupedBarChart
417+
{educationData.values.length > 0 && (
418+
<GroupedBarChartRecharts
419+
data={educationData}
420+
/>
421+
)}
422+
{/* <GroupedBarChart
396423
data={educationData}
397424
groupSelector={groupSelector}
398425
showValue
@@ -403,11 +430,17 @@ class TrendSummary extends React.PureComponent {
403430
keySelector={legendKeySelector}
404431
labelSelector={legendLabelSelector}
405432
colorSelector={legendColorSelector}
406-
/>
433+
/> */}
407434
</div>
408435
<div className={_cs(styles.item)}>
409436
<h3> SOI Trend </h3>
410-
<GroupedBarChart
437+
{soiData.values.length > 0 && (
438+
<GroupedBarChartRecharts
439+
data={soiData}
440+
/>
441+
)}
442+
{console.log('soiData---', soiData)}
443+
{/* <GroupedBarChart
411444
data={soiData}
412445
groupSelector={groupSelector}
413446
showValue
@@ -418,7 +451,7 @@ class TrendSummary extends React.PureComponent {
418451
keySelector={legendKeySelector}
419452
labelSelector={legendLabelSelector}
420453
colorSelector={legendColorSelector}
421-
/>
454+
/> */}
422455
</div>
423456
</div>
424457
);

0 commit comments

Comments
 (0)