updated and add bar chart example and readme

This commit is contained in:
Sambo Chea 2020-10-15 12:18:07 +07:00
parent 9ae28b62ff
commit 942005f2e9
7 changed files with 122 additions and 9 deletions

View File

@ -1,2 +1,16 @@
# Chart.js Demos # Chart.js Demos
- Line Chart Example
**Install**
Using NPM
```shell
npm install @cubetiq/react-chart-js
```
OR using Yarn
```shell
yarn add @cubetiq/react-chart-js
```
- Line Chart Example
- Bar Chart Example

View File

@ -0,0 +1,14 @@
import React from 'react';
import { ReactChartJs } from '@cubetiq/react-chart-js';
function BarChartExample(props: any) {
const { chartConfig } = props
return (
<ReactChartJs
chartConfig={chartConfig}
/>
);
}
export default BarChartExample;

View File

@ -0,0 +1 @@
export { default as BarChart } from './BarChartExample'

3
src/demos/ChartProps.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
export interface ChartProps {
chartConfig?: object;
}

View File

@ -0,0 +1,77 @@
import React from "react";
import { ChartProps } from "../demos/ChartProps";
import { LineChart } from "../demos/LineChart";
import "./chart.css";
/**
* Primary UI component for user interaction
*/
export const BarChartDemo: React.FC<ChartProps> = ({
chartConfig = {
type: "bar",
options: {
responsive: true,
title: {
display: true,
text: "Monthly Payments",
},
tooltips: {
mode: "index",
intersect: false,
},
hover: {
mode: "nearest",
intersect: true,
},
scales: {
yAxes: [
{
ticks: {
beginAtZero: true,
},
},
],
},
},
data: {
datasets: [
{
label: "Part-time",
data: [5, 10, 30],
fill: false,
borderColor: [
"rgba(255, 99, 132, 1)",
"rgba(54, 162, 235, 1)",
"rgba(255, 206, 86, 1)",
],
backgroundColor: [
"rgba(255, 99, 132, 0.2)",
"rgba(54, 162, 235, 0.2)",
"rgba(255, 206, 86, 0.2)",
],
borderWidth: 1,
},
{
label: "Full-time",
data: [10, 15, 45],
fill: false,
borderColor: [
"rgba(75, 192, 192, 1)",
"rgba(153, 102, 255, 1)",
"rgba(255, 159, 64, 1)",
],
backgroundColor: [
"rgba(75, 192, 192, 0.2)",
"rgba(153, 102, 255, 0.2)",
"rgba(255, 159, 64, 0.2)",
],
borderWidth: 1,
},
],
labels: ["Jan", "Feb", "Mar"],
},
},
...props
}) => {
return <LineChart chartConfig={chartConfig} />;
};

View File

@ -1,7 +1,9 @@
import React from "react"; import React from "react";
import { Story, Meta } from "@storybook/react/types-6-0"; import { Story, Meta } from "@storybook/react/types-6-0";
import { LineChartDemo, ChartProps } from "./LineChartDemo"; import { LineChartDemo } from "./LineChartDemo";
import { BarChartDemo } from "./BarChartDemo";
import { ChartProps } from "../demos/ChartProps";
export default { export default {
title: "Example/Chart", title: "Example/Chart",
@ -9,7 +11,12 @@ export default {
argTypes: {}, argTypes: {},
} as Meta; } as Meta;
const Template: Story<ChartProps> = (args) => <LineChartDemo />; const LineChartDemoTemplate: Story<ChartProps> = (args) => <LineChartDemo />;
export const LineChart = Template.bind({}); const BarChartDemoTemplate: Story<ChartProps> = (args) => <BarChartDemo />;
LineChart.args = {};
export const LineChart = LineChartDemoTemplate.bind({});
LineChart.args = { };
export const BarChart = BarChartDemoTemplate.bind({});
BarChart.args = { };

View File

@ -1,11 +1,8 @@
import React from "react"; import React from "react";
import { ChartProps } from "../demos/ChartProps";
import { LineChart } from "../demos/LineChart"; import { LineChart } from "../demos/LineChart";
import "./chart.css"; import "./chart.css";
export interface ChartProps {
chartConfig?: any;
}
/** /**
* Primary UI component for user interaction * Primary UI component for user interaction
*/ */