diff --git a/src/components/chart.tsx b/src/components/chart.tsx new file mode 100644 index 0000000..26d9a46 --- /dev/null +++ b/src/components/chart.tsx @@ -0,0 +1,71 @@ +import React, { useEffect, useState, ReactElement } from 'react' +import { + Chart as ChartJS, + CategoryScale, + LinearScale, + BarElement, + Title, + Tooltip, + Legend +} from 'chart.js' +import styles from '../styles/Home.module.css' +import { Bar } from 'react-chartjs-2' + +ChartJS.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend) + +export default function Chart({ + path, + title +}: { + path: string + title: string +}): ReactElement { + const [chartData, setChartData] = useState(null) + + const options = { + responsive: true, + plugins: { + legend: { + position: 'top' as const + }, + title: { + display: true, + text: title + } + } + } + + useEffect(() => { + async function fetchData() { + const res = await fetch(`http://localhost:8000${path}`) + const data = await res.json() + console.log(data) + + // Assuming the response data is an object with keys as labels and values as data points + const labels = Object.keys(data) + const datasetData = Object.values(data) + + setChartData({ + labels: labels, + datasets: [ + { + label: 'NFTS Published', + data: datasetData + } + ] + }) + } + + fetchData() + }, []) + + if (!chartData) { + return
Loading...
+ } + + return ( +
+ +
+ ) +} diff --git a/src/pages/stats.tsx b/src/pages/stats.tsx index 16e31b7..38edf95 100644 --- a/src/pages/stats.tsx +++ b/src/pages/stats.tsx @@ -1,60 +1,31 @@ -import React, { useEffect, useState } from 'react' -import { - Chart as ChartJS, - CategoryScale, - LinearScale, - BarElement, - Title, - Tooltip, - Legend -} from 'chart.js' -import { Bar } from 'react-chartjs-2' - -ChartJS.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend) - -export const options = { - responsive: true, - plugins: { - legend: { - position: 'top' as const - }, - title: { - display: true, - text: 'Chart.js Bar Chart' - } - } -} +import React from 'react' +import Head from 'next/head' +import styles from '../styles/Home.module.css' +import LogoAsset from '../images/logo.svg' +import Chart from '../components/chart' export default function Stats() { - const [chartData, setChartData] = useState(null) + return ( +
+ + Ocean Protocol Stats + + + +
+ - useEffect(() => { - async function fetchData() { - const res = await fetch('http://localhost:8000/stats/core/publishedNFT') - const data = await res.json() - console.log(data) - - // Assuming the response data is an object with keys as labels and values as data points - const labels = Object.keys(data) - const datasetData = Object.values(data) - - setChartData({ - labels: labels, - datasets: [ - { - label: 'NFTS Published', - data: datasetData - } - ] - }) - } - - fetchData() - }, []) - - if (!chartData) { - return
Loading...
- } - - return +

Ocean Protocol Stats

+

Stats for usage of Ocean Protocol.

+
{' '} +
+
+ +
+
+
+ ) } diff --git a/src/styles/Home.module.css b/src/styles/Home.module.css index d5f7d29..e5d5b10 100644 --- a/src/styles/Home.module.css +++ b/src/styles/Home.module.css @@ -214,3 +214,12 @@ font-family: var(--font-family-base); font-weight: var(--font-weight-base); } + +.chart { + width: 100%; + height: 300px; + margin: 0 auto; + padding: 0; + border: 0; + display: block; +}