Skip to content

Commit

Permalink
feat : add orgnisms/monthlyProfit/index.js (#83)
Browse files Browse the repository at this point in the history
월별 수익 API 추가
  • Loading branch information
JungYeonHwi committed Oct 17, 2023
1 parent 1a9ee31 commit a5593b2
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions components/organisms/monthlyProfit/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React from 'react';
import { useEffect, useState } from "react";

import {
Chart as ChartJS,
RadialLinearScale,
PointElement,
LineElement,
Filler,
Tooltip,
Legend,
} from 'chart.js';
import { Radar } from 'react-chartjs-2';

import useGetMonthlyProfit from '@hooks/useMonthlyProfit';

ChartJS.register(
RadialLinearScale,
PointElement,
LineElement,
Filler,
Tooltip,
Legend
);

const MonthlyProfit = (props) => {

const storeId = props.id;

const [data, setData] = useState("");
const getMonthlyProfit = useGetMonthlyProfit(storeId);

useEffect(() => {
setData(getMonthlyProfit);
},[getMonthlyProfit]);

const labels = data && data.map((dataPoint) => dataPoint.time);
const profitData = data && data.map((dataPoint) => dataPoint.profit);

const options = {
responsive: true,
plugins: {
legend: {
position: 'bottom',
},
title: {
display: true,
text: '월별 수입 통계',
},
},
};

const chartData = {
labels: labels,
datasets: [
{
label: '월별 수입 통계',
data: profitData,
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderColor: 'rgba(255, 99, 132, 1)',
borderWidth: 1,
},
],
}

return (
<Radar data={chartData} width={30} height={30} options={{ maintainAspectRatio: false }} />
)
}

export default MonthlyProfit

0 comments on commit a5593b2

Please sign in to comment.