Feat : xử lý chart bar

quy_fe
Quy_FE 3 months ago
parent 4131312cff
commit 1704b78058
  1. 4
      src/_components/boxChart/BoxDoughnutChar.js
  2. 30
      src/_components/chart/RDoughnutChart.js
  3. 14
      src/_screens/home/education-department/index.js

@ -5,7 +5,7 @@ import './boxChart.scss'
export default function BoxDoughnutChart({data = [], title, propsContainer}) { export default function BoxDoughnutChart({data = [], title, propsContainer}) {
const [current, target] = data const [current, target] = data
const chartData = (current / target === 1 || current > target) ? [current] : [current, target - current]; // const chartData = (current / target === 1 || current > target) ? [current] : [current, target - current];
const renderStats = () => { const renderStats = () => {
return ( return (
@ -21,7 +21,7 @@ export default function BoxDoughnutChart({data = [], title, propsContainer}) {
<p className='box-chart-subtitle'>{title}</p> <p className='box-chart-subtitle'>{title}</p>
<div className='d-flex flex-1'> <div className='d-flex flex-1'>
<div className='doughnut-chart-content flex-1'> <div className='doughnut-chart-content flex-1'>
<RDoughnutChart data={chartData} /> <RDoughnutChart data={data} />
</div> </div>
<div className='origin-vertical justify-content-center align-item-center flex-1'> <div className='origin-vertical justify-content-center align-item-center flex-1'>
{renderStats()} {renderStats()}

@ -10,36 +10,44 @@ export default function RDoughnutChart({data = [], ...other}) {
return null return null
} }
// data = data.map((item, index) => { const total = data[1] === 0 ? 1 : data[0] + data[1];
// if (index === 1 && item === 0) { const percentageData = [
// return 1 (data[0] / total) * 100,
// } (data[1] / total) * 100,
// return item ];
// })
// console.log('data',data); const adjustedData = (percentageData[0] === 0 && percentageData[1] === 0) || percentageData[1] === percentageData[0] ? [0, 1] : percentageData;
return <Chart return <Chart
type='doughnut' type='doughnut'
data={{ data={{
labels: [], labels: ['Số tham gia',"Tổng số"],
datasets: [ datasets: [
{ {
label: '', label: '',
data, data: adjustedData,
backgroundColor: [ backgroundColor: [
PRIMARY_COLOR, '#01AEF0' PRIMARY_COLOR, '#01AEF0'
], ],
borderWidth: 0 borderWidth: 0
}, },
], ],
hoverOffset: 4
}} }}
options={{ options={{
responsive: true, responsive: true,
maintainAspectRatio: false, maintainAspectRatio: false,
plugins: { plugins: {
tooltip: { tooltip: {
enabled: false callbacks: {
} label: function (tooltipItem) {
const label = tooltipItem.label || '';
const value = data[tooltipItem.dataIndex];
return `${label}: ${value}`;
},
},
},
legend: false,
} }
}} }}
{...other} {...other}

@ -95,17 +95,17 @@ export default function EducationDepartmentHome() {
}); });
} }
useEffect(() => { useEffect(async () => {
getDataOrganization() await getDataOrganization()
getDataStatisticCircle() await getDataStatisticCircle()
}, []) }, [])
useEffect(() => { useEffect(async () => {
getDataStudentChart() await getDataStudentChart()
}, [dateStudentChart]) }, [dateStudentChart])
useEffect(() => { useEffect(async () => {
getDataTeacherChart() await getDataTeacherChart()
}, [dateTeacherChart]) }, [dateTeacherChart])
const getDataTeacher = async () => { const getDataTeacher = async () => {

Loading…
Cancel
Save