feat: add pie chart component and integrate it into the dashboard
This commit is contained in:
parent
b7e029546f
commit
bd92f9a09f
66
app/components/ui/chart.tsx
Normal file
66
app/components/ui/chart.tsx
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import {
|
||||||
|
Chart as ChartJS,
|
||||||
|
ArcElement,
|
||||||
|
Tooltip,
|
||||||
|
Legend,
|
||||||
|
type ChartOptions,
|
||||||
|
} from 'chart.js'
|
||||||
|
import { Pie } from 'react-chartjs-2'
|
||||||
|
ChartJS.register(ArcElement, Tooltip, Legend)
|
||||||
|
|
||||||
|
export const ChartPie = () => {
|
||||||
|
const data = {
|
||||||
|
labels: [
|
||||||
|
'Pidana',
|
||||||
|
'Perdata',
|
||||||
|
'Perceraian',
|
||||||
|
'Surat Bisnis',
|
||||||
|
'Surat Tanah',
|
||||||
|
'Lainnya',
|
||||||
|
],
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
data: [33.7, 13, 22.8, 9.3, 9.3, 21.2],
|
||||||
|
backgroundColor: [
|
||||||
|
'#FFB300',
|
||||||
|
'#4CAF50',
|
||||||
|
'#3F51B5',
|
||||||
|
'#F44336',
|
||||||
|
'#2196F3',
|
||||||
|
'#FF9800',
|
||||||
|
],
|
||||||
|
hoverOffset: 4,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const options: ChartOptions<'pie'> = {
|
||||||
|
maintainAspectRatio: true,
|
||||||
|
responsive: false,
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
position: 'right',
|
||||||
|
labels: {
|
||||||
|
usePointStyle: true,
|
||||||
|
pointStyle: 'circle',
|
||||||
|
padding: 20,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
layout: {
|
||||||
|
padding: 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="h-[300px] w-full items-center justify-center rounded-lg bg-white p-5 text-center">
|
||||||
|
<h2 className="text-xl font-bold">Top 5 Konten</h2>
|
||||||
|
<Pie
|
||||||
|
height={225}
|
||||||
|
width={450}
|
||||||
|
data={data}
|
||||||
|
options={options}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@ -1,26 +1,11 @@
|
|||||||
import { CardReport } from '~/components/ui/card-report'
|
import { CardReport } from '~/components/ui/card-report'
|
||||||
|
import { ChartPie } from '~/components/ui/chart'
|
||||||
|
|
||||||
import { HISTORY, REPORT } from './data'
|
import { HISTORY, REPORT } from './data'
|
||||||
export const DashboardPage = () => {
|
export const DashboardPage = () => {
|
||||||
return (
|
return (
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<div className="container mx-auto">
|
<div className="mt-5 grid grid-cols-1 grid-rows-1 gap-6 sm:grid-cols-3">
|
||||||
<section className="mb-5 flex items-center justify-between">
|
|
||||||
<h1 className="text-xl font-bold">Dashboard</h1>
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<span>Tanggal:</span>
|
|
||||||
<input
|
|
||||||
type="date"
|
|
||||||
className="rounded border p-2"
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
type="date"
|
|
||||||
className="rounded border p-2"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<div className="mb-5 grid grid-cols-3 gap-4">
|
|
||||||
{REPORT.map(({ title, amount, icon }, index) => (
|
{REPORT.map(({ title, amount, icon }, index) => (
|
||||||
<CardReport
|
<CardReport
|
||||||
key={index}
|
key={index}
|
||||||
@ -31,8 +16,7 @@ export const DashboardPage = () => {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-3 gap-x-4 gap-y-4">
|
<div className="mt-5 grid grid-cols-1 gap-6 sm:grid-cols-3 sm:grid-rows-2">
|
||||||
<div className="grid gap-y-4">
|
|
||||||
{HISTORY.map(({ title, amount, icon, counter }, index) => (
|
{HISTORY.map(({ title, amount, icon, counter }, index) => (
|
||||||
<CardReport
|
<CardReport
|
||||||
key={index}
|
key={index}
|
||||||
@ -42,23 +26,25 @@ export const DashboardPage = () => {
|
|||||||
counter={counter}
|
counter={counter}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
<div className="max-h-[300px] sm:col-span-2 sm:col-start-2 sm:row-span-2 sm:row-start-1">
|
||||||
<div className="col-span-2">
|
<ChartPie />
|
||||||
<img
|
|
||||||
src="/images/dummy-chart-2.svg"
|
|
||||||
alt=""
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-5 flex justify-between gap-5">
|
<div className="my-5 grid grid-cols-1 grid-rows-2 gap-6 sm:grid-cols-5 sm:grid-rows-1">
|
||||||
<div className="w-[600px] shadow-sm">
|
<div className="sm:col-span-3">
|
||||||
|
<div className="h-30 w-full">
|
||||||
|
<div className="shadow-sm">
|
||||||
<img
|
<img
|
||||||
src="/images/dummy-chart-1.svg"
|
src="/images/dummy-chart-1.svg"
|
||||||
alt=""
|
alt=""
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-[480px] shadow-sm">
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="sm:col-span-2 sm:col-start-4">
|
||||||
|
<div className="h-30 w-full">
|
||||||
|
<div className="shadow-sm">
|
||||||
<img
|
<img
|
||||||
src="/images/dummy-chart-3.svg"
|
src="/images/dummy-chart-3.svg"
|
||||||
alt=""
|
alt=""
|
||||||
@ -67,5 +53,6 @@ export const DashboardPage = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user