|
| 1 | +import React, { useEffect } from "react"; |
| 2 | +import type { Meta, StoryObj } from "@storybook/react"; |
| 3 | +import {GkDoughnutChart} from 'gk-chart'; |
| 4 | + |
| 5 | +import styled from "styled-components"; |
| 6 | + |
| 7 | +const DoughnutChartContainer = styled.div` |
| 8 | + width: 100%; |
| 9 | + height: 300px; |
| 10 | +` |
| 11 | + |
| 12 | +const doughnutChartData = { |
| 13 | + "config": { |
| 14 | + "title": "Doughnut Chart", |
| 15 | + "chartType": "doughnut-chart", |
| 16 | + "printEnable": true |
| 17 | + }, |
| 18 | + "data": [{ |
| 19 | + "chartColor": "#29c3be", |
| 20 | + "datapoints": [{ |
| 21 | + "label": "Jan", |
| 22 | + "y": 200, |
| 23 | + "color": "#37509a" |
| 24 | + }, { |
| 25 | + "label": "Feb", |
| 26 | + "y": 90, |
| 27 | + "color": "#940f00" |
| 28 | + }, { |
| 29 | + "label": "Mar", |
| 30 | + "y": 45, |
| 31 | + "color": "#14d9a1" |
| 32 | + }, { |
| 33 | + "label": "Apr", |
| 34 | + "y": 70, |
| 35 | + "color": "#d3c403" |
| 36 | + }, { |
| 37 | + "label": "May", |
| 38 | + "y": 95, |
| 39 | + "color": "#ec40d5" |
| 40 | + } |
| 41 | + ] |
| 42 | + }] |
| 43 | +}; |
| 44 | + |
| 45 | +export const DoughnutChart = () => { |
| 46 | + |
| 47 | + useEffect(() => { |
| 48 | + GkDoughnutChart({ |
| 49 | + id: "doughnutChartId", |
| 50 | + data: doughnutChartData |
| 51 | + }) |
| 52 | + }, []); |
| 53 | + |
| 54 | + return ( |
| 55 | + <> |
| 56 | + <DoughnutChartContainer id="doughnutChartId" /> |
| 57 | + </> |
| 58 | + ); |
| 59 | +} |
| 60 | + |
| 61 | + |
| 62 | +const meta: Meta = { |
| 63 | + title: "Components/DoughnutChart", |
| 64 | + component: DoughnutChart, |
| 65 | + tags: ["autodocs"], |
| 66 | + decorators: [ |
| 67 | + (Story) => ( |
| 68 | + <div style={{ margin: '1em', padding: '2em', background: '#f8f7f7' }}> |
| 69 | + <Story /> |
| 70 | + </div> |
| 71 | + ), |
| 72 | + ], |
| 73 | +}; |
| 74 | + |
| 75 | + |
| 76 | +export default meta; |
| 77 | +type Story = StoryObj<typeof meta>; |
| 78 | + |
| 79 | +const doughnutChartExample: string = ` |
| 80 | +import React, { useEffect } from "react"; |
| 81 | +import {GkPieChart} from 'gk-chart'; |
| 82 | +
|
| 83 | +const doughnutChartData = { |
| 84 | + "config": { |
| 85 | + "title": "Doughnut Chart", |
| 86 | + "chartType": "doughnut-chart", |
| 87 | + "printEnable": true |
| 88 | + }, |
| 89 | + "data": [{ |
| 90 | + "chartColor": "#29c3be", |
| 91 | + "datapoints": [{ |
| 92 | + "label": "Jan", |
| 93 | + "y": 200, |
| 94 | + "color": "teal" |
| 95 | + }, { |
| 96 | + "label": "Feb", |
| 97 | + "y": 90, |
| 98 | + "color": "#b84335" |
| 99 | + }, { |
| 100 | + "label": "Mar", |
| 101 | + "y": 45, |
| 102 | + "color": "#fbbc05" |
| 103 | + }, { |
| 104 | + "label": "Apr", |
| 105 | + "y": 70, |
| 106 | + "color": "gray" |
| 107 | + }, { |
| 108 | + "label": "May", |
| 109 | + "y": 95, |
| 110 | + "color": "purple" |
| 111 | + }] |
| 112 | + }] |
| 113 | +}; |
| 114 | +
|
| 115 | +export const PieChart = () => { |
| 116 | +
|
| 117 | + useEffect(() => { |
| 118 | + GkPieChart({ |
| 119 | + id: "pieChartId", |
| 120 | + data: pieChartData |
| 121 | + }) |
| 122 | + }, []); |
| 123 | +
|
| 124 | + return ( |
| 125 | + <> |
| 126 | + <div id="pieChartId" style={{width: "100%", height: "500px"}}></div> |
| 127 | + </> |
| 128 | + ); |
| 129 | +} |
| 130 | +` |
| 131 | + |
| 132 | +DoughnutChart.parameters = { |
| 133 | + docs: { |
| 134 | + source: { |
| 135 | + code: doughnutChartExample, |
| 136 | + }, |
| 137 | + }, |
| 138 | +}; |
| 139 | + |
0 commit comments