diff --git a/web/components/admin/Chart.tsx b/web/components/admin/Chart.tsx index 5708da749..7b6c08669 100644 --- a/web/components/admin/Chart.tsx +++ b/web/components/admin/Chart.tsx @@ -1,6 +1,7 @@ import format from 'date-fns/format'; -import { FC } from 'react'; +import { FC, useRef } from 'react'; +import { DownloadOutlined } from '@ant-design/icons'; import { Chart as ChartJS, CategoryScale, @@ -14,6 +15,7 @@ import { ChartOptions, } from 'chart.js'; import { Line } from 'react-chartjs-2'; +import { Button } from 'antd'; ChartJS.register( CategoryScale, @@ -68,6 +70,16 @@ export const Chart: FC = ({ }) => { const renderData = []; + const chartRef = useRef(null); + const downloadChart = () => { + if (chartRef.current) { + const link = document.createElement('a'); + link.download = 'chart.png'; + link.href = chartRef.current.canvas.toDataURL(); + link.click(); + } + }; + if (data && data.length > 0) { renderData.push({ id: title, @@ -115,10 +127,18 @@ export const Chart: FC = ({ return (
} height="70vh" /> +
); }; diff --git a/web/styles/ant-overrides.scss b/web/styles/ant-overrides.scss index 2f6fb3afd..83b9b4e2c 100644 --- a/web/styles/ant-overrides.scss +++ b/web/styles/ant-overrides.scss @@ -237,3 +237,12 @@ th { .ant-menu-light .ant-menu-item:hover { color: var(--theme-color-palette-12); } + +.line-chart-container{ + position: relative; + .download-btn{ + position:absolute; + top: 0.3rem; + right: 0.35rem; + } +}