diff --git a/sandboxes/line/area/App.tsx b/sandboxes/line/area/App.tsx new file mode 100644 index 000000000..ce6b4a523 --- /dev/null +++ b/sandboxes/line/area/App.tsx @@ -0,0 +1,57 @@ +import React from 'react'; +import { + Chart as ChartJS, + CategoryScale, + LinearScale, + PointElement, + LineElement, + Title, + Tooltip, + Filler, + Legend, +} from 'chart.js'; +import { Line } from 'react-chartjs-2'; +import faker from 'faker'; + +ChartJS.register( + CategoryScale, + LinearScale, + PointElement, + LineElement, + Title, + Tooltip, + Filler, + Legend +); + +export const options = { + responsive: true, + plugins: { + legend: { + position: 'top' as const, + }, + title: { + display: true, + text: 'Chart.js Line Chart', + }, + }, +}; + +const labels = ['January', 'February', 'March', 'April', 'May', 'June', 'July']; + +export const data = { + labels, + datasets: [ + { + fill: true, + label: 'Dataset 2', + data: labels.map(() => faker.datatype.number({ min: 0, max: 1000 })), + borderColor: 'rgb(53, 162, 235)', + backgroundColor: 'rgba(53, 162, 235, 0.5)', + }, + ], +}; + +export function App() { + return ; +} diff --git a/sandboxes/line/area/index.tsx b/sandboxes/line/area/index.tsx new file mode 100644 index 000000000..4b014413e --- /dev/null +++ b/sandboxes/line/area/index.tsx @@ -0,0 +1,7 @@ +import React from 'react'; +import { createRoot } from 'react-dom/client'; + +import { App } from './App'; + +const rootElement = document.getElementById('root'); +createRoot(rootElement).render(); diff --git a/sandboxes/line/area/package.json b/sandboxes/line/area/package.json new file mode 100644 index 000000000..4c3f18191 --- /dev/null +++ b/sandboxes/line/area/package.json @@ -0,0 +1,17 @@ +{ + "main": "index.tsx", + "dependencies": { + "chart.js": "^3.6.0", + "faker": "5.5.3", + "react": "18.0.0", + "react-chartjs-2": "^4.0.0", + "react-dom": "18.0.0", + "react-scripts": "5.0.0" + }, + "devDependencies": { + "@types/faker": "5.5.3", + "@types/react": "18.0.0", + "@types/react-dom": "18.0.0", + "typescript": "4.5.4" + } +} diff --git a/website/docs/examples/area-chart.mdx b/website/docs/examples/area-chart.mdx new file mode 100644 index 000000000..f20f9211e --- /dev/null +++ b/website/docs/examples/area-chart.mdx @@ -0,0 +1,27 @@ +--- +description: Example of area chart in react-chartjs-2. +tags: + - Area Chart +--- + +import ContextProvider from '../../src/components/ContextProvider'; + +# Area Chart + + + {({ branch, theme }) => ( + + )} + diff --git a/website/docs/examples/docs.js b/website/docs/examples/docs.js index 493a90003..f1ec9ce43 100644 --- a/website/docs/examples/docs.js +++ b/website/docs/examples/docs.js @@ -3,6 +3,7 @@ exports.docs = [ { title: 'Horizontal Bar Chart', slug: '/examples/horizontal-bar-chart' }, { title: 'Stacked Bar Chart', slug: '/examples/stacked-bar-chart' }, { title: 'Grouped Bar Chart', slug: '/examples/grouped-bar-chart' }, + { title: 'Area Chart', slug: '/examples/area-chart' }, { title: 'Line Chart', slug: '/examples/line-chart' }, { title: 'Multiaxis Line Chart', slug: '/examples/multiaxis-line-chart' }, { title: 'Pie Chart', slug: '/examples/pie-chart' },