@@ -116,3 +116,161 @@ export default () => {
116
116
return <LineChart { ... config } ref = { getContainer } chartRef = { getChart } />
117
117
}
118
118
```
119
+
120
+ ## Update Data
121
+
122
+ ``` tsx
123
+ import React , { useCallback , useState } from ' react'
124
+ import { LineChart } from ' @opd/g2plot-react'
125
+
126
+ const config = {
127
+ height: 400 ,
128
+ title: {
129
+ visible: true ,
130
+ text: ' LineChart' ,
131
+ },
132
+ description: {
133
+ visible: true ,
134
+ text: ' This is Description' ,
135
+ },
136
+ padding: ' auto' ,
137
+ forceFit: true ,
138
+ xField: ' year' ,
139
+ yField: ' value' ,
140
+ label: {
141
+ visible: true ,
142
+ type: ' point' ,
143
+ },
144
+ point: {
145
+ visible: true ,
146
+ size: 5 ,
147
+ },
148
+ xAxis: {
149
+ tickCount: 10 ,
150
+ },
151
+ }
152
+
153
+ export default () => {
154
+ const getChart = useCallback ((chart ) => {
155
+ console .log (chart )
156
+ }, [])
157
+ const getContainer = useCallback ((container ) => {
158
+ console .log (container )
159
+ }, [])
160
+
161
+ const [data, setData] = useState ([
162
+ { year: ' 1991' , value: 3 },
163
+ { year: ' 1992' , value: 4 },
164
+ { year: ' 1993' , value: 3.5 },
165
+ { year: ' 1994' , value: 5 },
166
+ { year: ' 1995' , value: 4.9 },
167
+ { year: ' 1996' , value: 6 },
168
+ { year: ' 1997' , value: 7 },
169
+ { year: ' 1998' , value: 9 },
170
+ { year: ' 1999' , value: 11 },
171
+ ])
172
+
173
+ const handleBtnClick = useCallback (() => {
174
+ setData ([
175
+ { year: ' 1991' , value: 3 },
176
+ { year: ' 1992' , value: 4 },
177
+ { year: ' 1993' , value: 3.5 },
178
+ { year: ' 1994' , value: 5 },
179
+ { year: ' 1995' , value: 4.9 },
180
+ { year: ' 1996' , value: 6 },
181
+ { year: ' 1997' , value: 7 },
182
+ { year: ' 1998' , value: 9 },
183
+ { year: ' 1999' , value: 11 },
184
+ { year: ' 2000' , value: 14 },
185
+ ])
186
+ }, [])
187
+
188
+ return (
189
+ <div >
190
+ <button onClick = { handleBtnClick } >Update Data</button >
191
+ <LineChart
192
+ { ... config }
193
+ ref = { getContainer }
194
+ chartRef = { getChart }
195
+ data = { data }
196
+ />
197
+ </div >
198
+ )
199
+ }
200
+ ```
201
+
202
+ ## Update Config
203
+
204
+ ``` tsx
205
+ import React , { useCallback , useState } from ' react'
206
+ import { LineChart } from ' @opd/g2plot-react'
207
+
208
+ const config = {
209
+ height: 400 ,
210
+ title: {
211
+ visible: true ,
212
+ text: ' LineChart' ,
213
+ },
214
+ description: {
215
+ visible: true ,
216
+ text: ' This is Description' ,
217
+ },
218
+ padding: ' auto' ,
219
+ forceFit: true ,
220
+ xField: ' year' ,
221
+ yField: ' value' ,
222
+ label: {
223
+ visible: true ,
224
+ type: ' point' ,
225
+ },
226
+ point: {
227
+ visible: true ,
228
+ size: 5 ,
229
+ },
230
+ xAxis: {
231
+ tickCount: 10 ,
232
+ },
233
+ data: [
234
+ { year: ' 1991' , value: 3 },
235
+ { year: ' 1992' , value: 4 },
236
+ { year: ' 1993' , value: 3.5 },
237
+ { year: ' 1994' , value: 5 },
238
+ { year: ' 1995' , value: 4.9 },
239
+ { year: ' 1996' , value: 6 },
240
+ { year: ' 1997' , value: 7 },
241
+ { year: ' 1998' , value: 9 },
242
+ { year: ' 1999' , value: 11 },
243
+ ],
244
+ }
245
+
246
+ export default () => {
247
+ const getChart = useCallback ((chart ) => {
248
+ console .log (chart )
249
+ }, [])
250
+ const getContainer = useCallback ((container ) => {
251
+ console .log (container )
252
+ }, [])
253
+
254
+ const [restConfig, setConfig] = useState ({})
255
+
256
+ const handleBtnClick = useCallback (() => {
257
+ setConfig ({
258
+ point: {
259
+ visible: false ,
260
+ },
261
+ })
262
+ }, [])
263
+
264
+ return (
265
+ <div >
266
+ <button onClick = { handleBtnClick } >Update Config</button >
267
+ <LineChart
268
+ { ... config }
269
+ ref = { getContainer }
270
+ chartRef = { getChart }
271
+ { ... restConfig }
272
+ />
273
+ </div >
274
+ )
275
+ }
276
+ ```
0 commit comments