Skip to content

Commit 708945b

Browse files
authored
Merge pull request #174 from webaccess/charts
pie chart component done
2 parents 0bebb23 + 4f90bb3 commit 708945b

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

webapp/package-lock.json

+55
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webapp/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
"@types/react-dom": "^16.9.8",
1818
"autosuggest-highlight": "^3.1.1",
1919
"axios": "^0.19.2",
20+
"chart.js": "^2.9.3",
21+
"chart.piecelabel.js": "^0.15.0",
22+
"chartjs-plugin-datalabels": "^0.7.0",
2023
"clsx": "^1.1.0",
2124
"cors": "^2.8.5",
2225
"date-fns": "^2.8.1",
@@ -26,6 +29,7 @@
2629
"moment": "^2.27.0",
2730
"react": "^16.12.0",
2831
"react-autosuggest": "^9.4.3",
32+
"react-chartjs-2": "^2.10.0",
2933
"react-data-table-component": "^6.3.1",
3034
"react-dom": "^16.12.0",
3135
"react-router-dom": "^5.1.2",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React from "react";
2+
import { Pie } from "react-chartjs-2";
3+
import "chartjs-plugin-datalabels";
4+
5+
const Piechart = (props) => (
6+
<Pie
7+
data={{
8+
labels: props.labels ? props.labels : [],
9+
datasets: props.datasets ? props.datasets : [],
10+
}}
11+
options={{
12+
plugins: {
13+
datalabels: {
14+
display: true,
15+
color: "white",
16+
font: {
17+
weight: "bold",
18+
size: 16,
19+
},
20+
},
21+
},
22+
tooltips: {
23+
enabled: false,
24+
},
25+
legend: {
26+
labels: {
27+
fontSize: 19,
28+
},
29+
},
30+
}}
31+
responsive="true"
32+
maintainAspectRatio="true"
33+
{...props}
34+
/>
35+
);
36+
37+
export default Piechart;
38+
39+
/**
40+
* usage:
41+
* example:
42+
* import Piechart from "../UI/Piechart/Piechart";
43+
* <Piechart
44+
labels={["A", "B", "C"]}
45+
datasets={[
46+
{
47+
data: [20, 30, 60],
48+
backgroundColor: ["red", "blue", "green"],
49+
fontSize: "20px",
50+
},
51+
]}
52+
/>
53+
*/

0 commit comments

Comments
 (0)