9
9
[ npm-download ] :https://img.shields.io/npm/dm/@coreui/react-chartjs.svg?style=flat-square
10
10
11
11
#####install:
12
+
12
13
``` bash
13
- npm install @coreui/react-chartjs
14
+ npm install @coreui/react-chartjs@next
15
+
16
+ # or
17
+
18
+ yarn add @coreui/react-chartjs@next
14
19
```
15
20
16
- #####import:
21
+ #####import:
22
+
17
23
``` jsx
18
- import {CChart }from ' @coreui/react-chartjs' ;
24
+ import {CChart }from ' @coreui/react-chartjs'
19
25
```
20
- or
26
+
27
+ or
28
+
21
29
``` js
22
30
import {
23
31
CChart ,
@@ -31,79 +39,145 @@ import {
31
39
}from ' @coreui/react-chartjs'
32
40
```
33
41
34
- #####props:
35
- - ` innerRef ` object | func | string
36
- - ` datasets ` array
37
- - ` labels ` array | string
38
- - ` options ` object
39
- - ` plugins ` array
40
- - ` type ` string:` bar ` |` horizontalBar ` |` line ` |` doughnut ` |` radar ` |` pie ` |` polarArea `
42
+ #####props:
43
+
44
+ ``` js
45
+
46
+ /**
47
+ * A string of all className you want applied to the base component.
48
+ */
49
+ className?: string
50
+ /**
51
+ * Enables custom html based tooltips instead of standard tooltips.
52
+ *
53
+ *@default true
54
+ */
55
+ customTooltips?: boolean
56
+ /**
57
+ * The data object that is passed into the Chart.js chart (more info).
58
+ */
59
+ data: Chart .ChartData | ((canvas : HTMLCanvasElement )=> Chart .ChartData )
60
+ /**
61
+ * A fallback for when the canvas cannot be rendered. Can be used for accessible chart descriptions.
62
+ *
63
+ *{@link https://www.chartjs.org/docs/latest/general/accessibility.html More Info}
64
+ */
65
+ fallbackContent?: React .ReactNode
66
+ /**
67
+ * Proxy for Chart.js getDatasetAtEvent. Calls with dataset and triggering event.
68
+ */
69
+ getDatasetAtEvent?: (dataset : Array < {}> ,event : React .MouseEvent < HTMLCanvasElement > )=> void
70
+ /**
71
+ * Proxy for Chart.js getElementAtEvent. Calls with single element array and triggering event.
72
+ */
73
+ getElementAtEvent?: (element : [{}],event : React .MouseEvent < HTMLCanvasElement > )=> void
74
+ /**
75
+ * Proxy for Chart.js getElementsAtEvent. Calls with element array and triggering event.
76
+ */
77
+ getElementsAtEvent?: (elements : Array < {}> ,event : React .MouseEvent < HTMLCanvasElement > )=> void
78
+ /**
79
+ * Height attribute applied to the rendered canvas.
80
+ *
81
+ *@default 150
82
+ */
83
+ height?: number
84
+ /**
85
+ * ID attribute applied to the rendered canvas.
86
+ */
87
+ id?: string
88
+ /**
89
+ * The options object that is passed into the Chart.js chart.
90
+ *
91
+ *{@link https://www.chartjs.org/docs/latest/general/options.html More Info}
92
+ */
93
+ options?: Chart .ChartOptions
94
+ /**
95
+ * The plugins array that is passed into the Chart.js chart (more info)
96
+ *
97
+ *{@link https://www.chartjs.org/docs/latest/developers/plugins.html More Info}
98
+ */
99
+ plugins?: Chart .PluginServiceRegistrationOptions []
100
+ /**
101
+ * If true, will tear down and redraw chart on all updates.
102
+ *
103
+ *@default false
104
+ */
105
+ redraw?: boolean
106
+ /**
107
+ * Chart.js chart type.
108
+ *
109
+ *@type {'line' | 'bar' | 'horizontalBar' | 'radar' | 'doughnut' | 'polarArea' | 'bubble' | 'pie' | 'scatter'}
110
+ */
111
+ type: Chart .ChartType
112
+ /**
113
+ * Width attribute applied to the rendered canvas.
114
+ *
115
+ *@default 300
116
+ */
117
+ width?: number
118
+ /**
119
+ * Put the chart into the wrapper div element.
120
+ *
121
+ *@default true
122
+ */
123
+ wrapper?: boolean
124
+ ```
41
125
42
126
#####usage:
127
+
43
128
``` jsx
44
129
...
45
130
class CoreUICharts extends Component {
46
131
...
47
132
render () {
48
133
return (
49
134
< CChart
50
- type= " radar"
51
- datasets= {[
52
- {
53
- label: ' 2019' ,
54
- backgroundColor: ' rgba(179,181,198,0.2)' ,
55
- borderColor: ' rgba(179,181,198,1)' ,
56
- pointBackgroundColor: ' rgba(179,181,198,1)' ,
57
- pointBorderColor: ' #fff' ,
58
- pointHoverBackgroundColor: ' #fff' ,
59
- pointHoverBorderColor: ' rgba(179,181,198,1)' ,
60
- tooltipLabelColor: ' rgba(179,181,198,1)' ,
61
- data: [65 ,59 ,90 ,81 ,56 ,55 ,40 ]
62
- },
63
- {
64
- label: ' 2020' ,
65
- backgroundColor: ' rgba(255,99,132,0.2)' ,
66
- borderColor: ' rgba(255,99,132,1)' ,
67
- pointBackgroundColor: ' rgba(255,99,132,1)' ,
68
- pointBorderColor: ' #fff' ,
69
- pointHoverBackgroundColor: ' #fff' ,
70
- pointHoverBorderColor: ' rgba(255,99,132,1)' ,
71
- tooltipLabelColor: ' rgba(255,99,132,1)' ,
72
- data: [28 ,48 ,40 ,19 ,96 ,27 ,100 ]
73
- }
74
- ]}
135
+ type= ' line'
136
+ data= {{
137
+ labels: [' January' ,' February' ,' March' ,' April' ,' May' ,' June' ,' July' ],
138
+ datasets: [
139
+ {
140
+ label: ' 2019' ,
141
+ backgroundColor: ' rgba(179,181,198,0.2)' ,
142
+ borderColor: ' rgba(179,181,198,1)' ,
143
+ pointBackgroundColor: ' rgba(179,181,198,1)' ,
144
+ pointBorderColor: ' #fff' ,
145
+ pointHoverBackgroundColor: ' #fff' ,
146
+ pointHoverBorderColor: ' rgba(179,181,198,1)' ,
147
+ tooltipLabelColor: ' rgba(179,181,198,1)' ,
148
+ data: [65 ,59 ,90 ,81 ,56 ,55 ,40 ]
149
+ },
150
+ {
151
+ label: ' 2020' ,
152
+ backgroundColor: ' rgba(255,99,132,0.2)' ,
153
+ borderColor: ' rgba(255,99,132,1)' ,
154
+ pointBackgroundColor: ' rgba(255,99,132,1)' ,
155
+ pointBorderColor: ' #fff' ,
156
+ pointHoverBackgroundColor: ' #fff' ,
157
+ pointHoverBorderColor: ' rgba(255,99,132,1)' ,
158
+ tooltipLabelColor: ' rgba(255,99,132,1)' ,
159
+ data: [28 ,48 ,40 ,19 ,96 ,27 ,100 ]
160
+ }
161
+ ],
162
+ }}
75
163
options= {{
76
164
aspectRatio: 1.5 ,
77
165
tooltips: {
78
166
enabled: true
79
167
}
80
168
}}
81
- labels= {[
82
- ' Eating' ,' Drinking' ,' Sleeping' ,' Designing' ,
83
- ' Coding' ,' Cycling' ,' Running'
84
- ]}
85
169
/ >
86
170
)
87
171
}
88
172
...
89
173
` ` `
90
174
91
- ---
92
-
93
- - bootstrapped with [nwb](https://github.com/insin/nwb) toolkit
94
-
95
175
#####` npm run` scripts
96
176
97
- ` package .json ` is configured with` " scripts" ` we can use with` npm run` while developing the project.
177
+ ` package .json ` is configured with` " scripts" ` we can use with` npm run` or ` yarn ` while developing the project.
98
178
99
- Command | Description |
100
- --- | ---
101
- ` npm start` | start a development server for the demo app
102
- ` npm test` | run tests
103
- ` npm run test: coverage` | run tests and produce a code coverage report in` coverage/ `
104
- ` npm run test: watch` | start a test server and re-run tests on every change
105
- ` npm run build` | prepare for publishing to npm
106
- ` npm run clean` | delete built resources
179
+ | Command | Description |
180
+ | ------------------------------- | ------------------------------ |
181
+ |` npm run build` or` yarn build` | build production ready version |
182
+ |` npm run lint` or` yarn lint` | run eslint |
107
183
108
- #### see also:
109
- - [Developing React Components and Libraries with nwb](https://github.com/insin/nwb/blob/master/docs/guides/ReactComponents.md#developing-react-components-and-libraries-with-nwb)