|
| 1 | +<p align="center"> |
| 2 | + <a href="https://coreui.io/"> |
| 3 | + <img |
| 4 | + src="https://coreui.io/images/brand/coreui-signet.svg" |
| 5 | + alt="CoreUI logo" |
| 6 | + width="200" |
| 7 | + /> |
| 8 | + </a> |
| 9 | +</p> |
| 10 | + |
| 11 | +<h3 align="center">CoreUI React.js wrapper for Chart.js</h3> |
| 12 | + |
| 13 | +<p align="center"> |
| 14 | + <a href="https://coreui.io/react/docs/components/chart/"><strong>Explore @coreui/react-chartjs docs & examples »</strong></a> |
| 15 | + <br> |
| 16 | + <br> |
| 17 | + <a href="https://github.com/coreui/coreui-react/issues/new?template=bug_report.md">Report bug</a> |
| 18 | + · |
| 19 | + <a href="https://github.com/coreui/coreui-react/issues/new?template=feature_request.md">Request feature</a> |
| 20 | + · |
| 21 | + <a href="https://blog.coreui.io/">Blog</a> |
| 22 | +</p> |
| 23 | + |
| 24 | +## Status |
| 25 | + |
| 26 | +[![npm package][npm-badge]][npm] |
| 27 | +[![NPM downloads][npm-download]][npm] |
| 28 | + |
| 29 | +[npm-badge]: https://img.shields.io/npm/v/@coreui/react-chartjs/latest?style=flat-square |
| 30 | +[npm]: https://www.npmjs.com/package/@coreui/react-chartjs |
| 31 | +[npm-download]: https://img.shields.io/npm/dm/@coreui/react-chartjs.svg?style=flat-square |
| 32 | + |
| 33 | +##### install: |
| 34 | + |
| 35 | +```bash |
| 36 | +npm install @coreui/react-chartjs |
| 37 | + |
| 38 | +# or |
| 39 | + |
| 40 | +yarn add @coreui/react-chartjs |
| 41 | +``` |
| 42 | + |
| 43 | +##### import: |
| 44 | + |
| 45 | +```jsx |
| 46 | +import { CChart } from '@coreui/react-chartjs' |
| 47 | +``` |
| 48 | + |
| 49 | +or |
| 50 | + |
| 51 | +```js |
| 52 | +import { |
| 53 | + CChart, |
| 54 | + CChartBar, |
| 55 | + CChartHorizontalBar, |
| 56 | + CChartLine, |
| 57 | + CChartDoughnut, |
| 58 | + CChartRadar, |
| 59 | + CChartPie, |
| 60 | + CChartPolarArea, |
| 61 | +} from '@coreui/react-chartjs' |
| 62 | +``` |
| 63 | + |
| 64 | +##### props: |
| 65 | + |
| 66 | +```js |
| 67 | + |
| 68 | +/** |
| 69 | +* A string of all className you want applied to the base component. |
| 70 | + */ |
| 71 | +className?: string |
| 72 | +/** |
| 73 | + * Enables custom html based tooltips instead of standard tooltips. |
| 74 | + * |
| 75 | + * @default true |
| 76 | + */ |
| 77 | +customTooltips?: boolean |
| 78 | +/** |
| 79 | + * The data object that is passed into the Chart.js chart (more info). |
| 80 | + */ |
| 81 | +data: ChartData | ((canvas: HTMLCanvasElement) => ChartData) |
| 82 | +/** |
| 83 | + * A fallback for when the canvas cannot be rendered. Can be used for accessible chart descriptions. |
| 84 | + * |
| 85 | + * {@link https://www.chartjs.org/docs/latest/general/accessibility.html More Info} |
| 86 | + */ |
| 87 | +fallbackContent?: React.ReactNode |
| 88 | +/** |
| 89 | + * Proxy for Chart.js getDatasetAtEvent. Calls with dataset and triggering event. |
| 90 | + */ |
| 91 | +getDatasetAtEvent?: ( |
| 92 | + dataset: InteractionItem[], |
| 93 | + event: React.MouseEvent<HTMLCanvasElement>, |
| 94 | +) => void |
| 95 | +/** |
| 96 | + * Proxy for Chart.js getElementAtEvent. Calls with single element array and triggering event. |
| 97 | + */ |
| 98 | +getElementAtEvent?: ( |
| 99 | + element: InteractionItem[], |
| 100 | + event: React.MouseEvent<HTMLCanvasElement>, |
| 101 | +) => void |
| 102 | +/** |
| 103 | + * Proxy for Chart.js getElementsAtEvent. Calls with element array and triggering event. |
| 104 | + */ |
| 105 | +getElementsAtEvent?: ( |
| 106 | + elements: InteractionItem[], |
| 107 | + event: React.MouseEvent<HTMLCanvasElement>, |
| 108 | +) => void |
| 109 | +/** |
| 110 | + * Height attribute applied to the rendered canvas. |
| 111 | + * |
| 112 | + * @default 150 |
| 113 | + */ |
| 114 | +height?: number |
| 115 | +/** |
| 116 | + * ID attribute applied to the rendered canvas. |
| 117 | + */ |
| 118 | +id?: string |
| 119 | +/** |
| 120 | + * The options object that is passed into the Chart.js chart. |
| 121 | + * |
| 122 | + * {@link https://www.chartjs.org/docs/latest/general/options.html More Info} |
| 123 | + */ |
| 124 | +options?: ChartOptions |
| 125 | +/** |
| 126 | + * The plugins array that is passed into the Chart.js chart (more info) |
| 127 | + * |
| 128 | + * {@link https://www.chartjs.org/docs/latest/developers/plugins.html More Info} |
| 129 | + */ |
| 130 | +plugins?: Plugin[] |
| 131 | +/** |
| 132 | + * If true, will tear down and redraw chart on all updates. |
| 133 | + * |
| 134 | + * @default false |
| 135 | + */ |
| 136 | +redraw?: boolean |
| 137 | +/** |
| 138 | + * Chart.js chart type. |
| 139 | + * |
| 140 | + * @type {'line' | 'bar' | 'radar' | 'doughnut' | 'polarArea' | 'bubble' | 'pie' | 'scatter'} |
| 141 | + */ |
| 142 | +type: ChartType |
| 143 | +/** |
| 144 | + * Width attribute applied to the rendered canvas. |
| 145 | + * |
| 146 | + * @default 300 |
| 147 | + */ |
| 148 | +width?: number |
| 149 | +/** |
| 150 | + * Put the chart into the wrapper div element. |
| 151 | + * |
| 152 | + * @default true |
| 153 | + */ |
| 154 | +wrapper?: boolean |
| 155 | +``` |
| 156 | + |
| 157 | +##### usage: |
| 158 | + |
| 159 | +```jsx |
| 160 | +... |
| 161 | +class CoreUICharts extends Component { |
| 162 | +... |
| 163 | +render() { |
| 164 | + return ( |
| 165 | + <CChart |
| 166 | + type='line' |
| 167 | + data={{ |
| 168 | + labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'], |
| 169 | + datasets: [ |
| 170 | + { |
| 171 | + label: '2019', |
| 172 | + backgroundColor: 'rgba(179,181,198,0.2)', |
| 173 | + borderColor: 'rgba(179,181,198,1)', |
| 174 | + pointBackgroundColor: 'rgba(179,181,198,1)', |
| 175 | + pointBorderColor: '#fff', |
| 176 | + pointHoverBackgroundColor: '#fff', |
| 177 | + pointHoverBorderColor: 'rgba(179,181,198,1)', |
| 178 | + tooltipLabelColor: 'rgba(179,181,198,1)', |
| 179 | + data: [65, 59, 90, 81, 56, 55, 40] |
| 180 | + }, |
| 181 | + { |
| 182 | + label: '2020', |
| 183 | + backgroundColor: 'rgba(255,99,132,0.2)', |
| 184 | + borderColor: 'rgba(255,99,132,1)', |
| 185 | + pointBackgroundColor: 'rgba(255,99,132,1)', |
| 186 | + pointBorderColor: '#fff', |
| 187 | + pointHoverBackgroundColor: '#fff', |
| 188 | + pointHoverBorderColor: 'rgba(255,99,132,1)', |
| 189 | + tooltipLabelColor: 'rgba(255,99,132,1)', |
| 190 | + data: [28, 48, 40, 19, 96, 27, 100] |
| 191 | + } |
| 192 | + ], |
| 193 | + }} |
| 194 | + options={{ |
| 195 | + aspectRatio: 1.5, |
| 196 | + tooltips: { |
| 197 | + enabled: true |
| 198 | + } |
| 199 | + }} |
| 200 | + /> |
| 201 | + ) |
| 202 | +} |
| 203 | +... |
| 204 | +``` |
0 commit comments