-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from palladiumkenya/addCharts
Add charts
- Loading branch information
Showing
9 changed files
with
420 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,7 @@ const Home = (props) =>{ | |
await userManager.getUser().then((user) =>{ | ||
if (user){ | ||
|
||
if (["[email protected]", "[email protected]"].includes(user.profile.email.toLowerCase())){ | ||
if (["[email protected]"].includes(user.profile.email.toLowerCase())){ | ||
setuserEmailAllowed(true) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React, { Component, useEffect, useState } from "react"; | ||
import { Button, Spinner } from "reactstrap"; | ||
import {FaEdit } from 'react-icons/fa'; | ||
import Swal from 'sweetalert2' | ||
import { Link } from 'react-router-dom'; | ||
|
||
import { Chart as ChartJS, ArcElement, Tooltip, Legend } from "chart.js"; | ||
import { Pie } from "react-chartjs-2"; | ||
|
||
import { API_URL, EMAIL_URL, BASE_URL } from "../../constants"; | ||
|
||
import axios from "axios"; | ||
import { useParams } from 'react-router-dom' | ||
|
||
|
||
ChartJS.register(ArcElement, Tooltip, Legend); | ||
|
||
|
||
|
||
const EmrTypeChart = () => { | ||
// State to hold the fetched data | ||
const [chartData, setChartData] = useState(null); | ||
|
||
const options = { | ||
responsive: true, | ||
plugins: { | ||
legend: { | ||
position: 'top', | ||
}, | ||
title: { | ||
display: true, | ||
text: 'Facilities Distributed by Emr Type', | ||
}, | ||
}, | ||
}; | ||
|
||
// Function to fetch data from the API | ||
const fetchData = async () => { | ||
try { | ||
const response = await fetch(API_URL + '/fetchEmrTypesCount'); | ||
const data = await response.json(); | ||
|
||
// Process the data as needed | ||
// For example, extract labels and data for the chart | ||
const labels = Object.keys(data[0]); | ||
const values = Object.values(data[0]); | ||
|
||
// Update the state with the chart data | ||
setChartData({ | ||
labels: Object.keys(data[0]), | ||
datasets: [ | ||
{ | ||
label: 'No. of Facilities', | ||
data: Object.values(data[0]), | ||
backgroundColor: [ | ||
'rgba(255, 99, 132, 0.2)', | ||
'rgba(54, 162, 235, 0.2)', | ||
], | ||
borderColor: [ | ||
'rgba(255, 99, 132, 1)', | ||
'rgba(54, 162, 235, 1)', | ||
], | ||
borderWidth: 1, | ||
}, | ||
], | ||
}); | ||
} catch (error) { | ||
console.error('Error fetching data:', error); | ||
} | ||
}; | ||
|
||
// useEffect to fetch data on component mount | ||
useEffect(() => { | ||
fetchData(); | ||
}, []); | ||
|
||
// Render the chart | ||
return ( | ||
<div> | ||
{chartData && <Pie data={chartData} options={options}/>} | ||
</div> | ||
); | ||
|
||
} | ||
|
||
export default EmrTypeChart; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import React, { Component, useEffect, useState } from "react"; | ||
import { Button, Spinner } from "reactstrap"; | ||
import {FaEdit } from 'react-icons/fa'; | ||
import Swal from 'sweetalert2' | ||
import { Link } from 'react-router-dom'; | ||
|
||
import { | ||
Chart as ChartJS, | ||
CategoryScale, | ||
LinearScale, | ||
BarElement, | ||
Title, | ||
Tooltip, | ||
Legend, | ||
} from 'chart.js'; | ||
import { Pie, Bar } from "react-chartjs-2"; | ||
|
||
import { API_URL, EMAIL_URL, BASE_URL } from "../../constants"; | ||
|
||
import axios from "axios"; | ||
import { useParams } from 'react-router-dom' | ||
|
||
|
||
ChartJS.register( | ||
CategoryScale, | ||
LinearScale, | ||
BarElement, | ||
Title, | ||
Tooltip, | ||
Legend | ||
); | ||
|
||
|
||
|
||
|
||
const FacilityByCountyChart = () => { | ||
// State to hold the fetched data | ||
const [chartData, setChartData] = useState(null); | ||
|
||
const options = { | ||
responsive: true, | ||
plugins: { | ||
legend: { | ||
position: 'top', | ||
}, | ||
title: { | ||
display: true, | ||
text: 'Facilities Distributed by County', | ||
}, | ||
}, | ||
}; | ||
|
||
|
||
// Function to fetch data from the API | ||
const fetchData = async () => { | ||
try { | ||
const response = await fetch(API_URL + '/fetchByCountiesCount'); | ||
const data = await response.json(); | ||
|
||
// Process the data as needed | ||
|
||
const dataLabels = data.map(item => item['county__name']); | ||
const dataValues = data.map(item => item['count']); | ||
|
||
// Update the state with the chart data | ||
setChartData({ | ||
labels: dataLabels, | ||
datasets: [ | ||
{ | ||
label: 'No. of Facilities', | ||
data: dataValues, | ||
backgroundColor: [ | ||
'rgba(255, 99, 132, 0.2)', | ||
'rgba(54, 162, 235, 0.2)', | ||
], | ||
borderColor: [ | ||
'rgba(255, 99, 132, 1)', | ||
'rgba(54, 162, 235, 1)', | ||
], | ||
borderWidth: 1, | ||
}, | ||
], | ||
}); | ||
} catch (error) { | ||
console.error('Error fetching data:', error); | ||
} | ||
}; | ||
|
||
// useEffect to fetch data on component mount | ||
useEffect(() => { | ||
fetchData(); | ||
}, []); | ||
|
||
// Render the chart | ||
return ( | ||
<div> | ||
{chartData && <Bar data={chartData} options={options} />} | ||
</div> | ||
); | ||
|
||
} | ||
|
||
export default FacilityByCountyChart; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import React, { Component, useEffect, useState } from "react"; | ||
import { Button, Spinner } from "reactstrap"; | ||
import {FaEdit } from 'react-icons/fa'; | ||
import Swal from 'sweetalert2' | ||
import { Link } from 'react-router-dom'; | ||
|
||
import { Chart as ChartJS, ArcElement, Tooltip, Legend } from "chart.js"; | ||
import { Pie } from "react-chartjs-2"; | ||
|
||
import { API_URL, EMAIL_URL, BASE_URL } from "../../constants"; | ||
|
||
import axios from "axios"; | ||
import { useParams } from 'react-router-dom' | ||
|
||
|
||
ChartJS.register(ArcElement, Tooltip, Legend); | ||
|
||
|
||
|
||
const ImplementationTypeChart = () => { | ||
// State to hold the fetched data | ||
const [chartData, setChartData] = useState(null); | ||
|
||
const options = { | ||
responsive: true, | ||
plugins: { | ||
legend: { | ||
position: 'top', | ||
}, | ||
title: { | ||
display: true, | ||
text: 'Facilities Distributed Under Each Implementation Type', | ||
}, | ||
}, | ||
}; | ||
|
||
// Function to fetch data from the API | ||
const fetchData = async () => { | ||
try { | ||
const response = await fetch(API_URL + '/fetchImplementationTypesCount'); | ||
const data = await response.json(); | ||
|
||
// Process the data as needed | ||
|
||
// Update the state with the chart data | ||
setChartData({ | ||
labels: Object.keys(data[0]), | ||
datasets: [ | ||
{ | ||
label: 'No. of Facilities', | ||
data: Object.values(data[0]), | ||
backgroundColor: [ | ||
'rgba(255, 99, 132, 0.2)', | ||
'rgba(54, 162, 235, 0.2)', | ||
'rgba(255, 206, 86, 0.2)', | ||
'rgba(75, 192, 192, 0.2)', | ||
'rgba(153, 102, 255, 0.2)', | ||
'rgba(255, 159, 64, 0.2)', | ||
], | ||
borderColor: [ | ||
'rgba(255, 99, 132, 1)', | ||
'rgba(54, 162, 235, 1)', | ||
'rgba(255, 206, 86, 1)', | ||
'rgba(75, 192, 192, 1)', | ||
'rgba(153, 102, 255, 1)', | ||
'rgba(255, 159, 64, 1)', | ||
], | ||
borderWidth: 1, | ||
}, | ||
], | ||
}); | ||
} catch (error) { | ||
console.error('Error fetching data:', error); | ||
} | ||
}; | ||
|
||
// useEffect to fetch data on component mount | ||
useEffect(() => { | ||
fetchData(); | ||
}, []); | ||
|
||
// Render the chart | ||
return ( | ||
<div> | ||
{chartData && <Pie data={chartData} options={options}/>} | ||
</div> | ||
); | ||
|
||
} | ||
|
||
export default ImplementationTypeChart; |
Oops, something went wrong.