@@ -184,6 +184,133 @@ ReactDOM.render(
184184);
185185```
186186
187+ ## Working with Events
188+
189+ To attach event callbacks to a FusionCharts component, follow the pattern below.
190+
191+ Write the callback:
192+
193+ As a separate function:
194+
195+ ``` javascript
196+ var chartEventCallback = function (eventObj , dataObj ) {
197+ [Code goes here]
198+ }
199+ ```
200+
201+ Or, as a component class method:
202+ ``` javascript
203+ chartEventCallback (eventObj , dataObj ) {
204+ [Code goes here]
205+ }
206+ ```
207+
208+ Attach the callback to an event through the React-FC component:
209+ ``` javascript
210+ < ReactFC {... chartConfigs} fcEvent- EVENTNAME = {this .chartEventCallback } / >
211+ ```
212+ Where, EVENTNAME is to be replaced by the event you want to track.
213+
214+ ##### Consider the example below that tracks hover events on a data plot.
215+
216+ ``` javascript
217+ import React , { Component } from ' react' ;
218+ import ReactDOM from ' react-dom' ;
219+ import FusionCharts from ' fusioncharts/core' ;
220+ import Column2D from ' fusioncharts/viz/column2d' ;
221+ import ReactFC from ' react-fusioncharts' ;
222+ import FusionTheme from ' fusioncharts/themes/es/fusioncharts.theme.fusion' ;
223+
224+ ReactFC .fcRoot (FusionCharts, Column2D, FusionTheme);
225+
226+ const myDataSource = {
227+ " chart" : {
228+ " caption" : " Countries With Most Oil Reserves [2017-18]" ,
229+ " subCaption" : " In MMbbl = One Million barrels" ,
230+ " xAxisName" : " Country" ,
231+ " yAxisName" : " Reserves (MMbbl)" ,
232+ " numberSuffix" : " K" ,
233+ " theme" : " fusion"
234+ },
235+ " data" : [
236+ {
237+ " label" : " Venezuela" ,
238+ " value" : " 290"
239+ },
240+ {
241+ " label" : " Saudi" ,
242+ " value" : " 260"
243+ },
244+ {
245+ " label" : " Canada" ,
246+ " value" : " 180"
247+ },
248+ {
249+ " label" : " Iran" ,
250+ " value" : " 140"
251+ },
252+ {
253+ " label" : " Russia" ,
254+ " value" : " 115"
255+ },
256+ {
257+ " label" : " UAE" ,
258+ " value" : " 100"
259+ },
260+ {
261+ " label" : " US" ,
262+ " value" : " 30"
263+ },
264+ {
265+ " label" : " China" ,
266+ " value" : " 30"
267+ }
268+ ]
269+ };
270+
271+ const chartConfigs = {
272+ type: ' column2d' ,
273+ width: 600 ,
274+ height: 400 ,
275+ dataFormat: ' json' ,
276+ dataSource: myDataSource,
277+ };
278+
279+ class Chart extends Component {
280+ constructor (props ) {
281+ super (props);
282+
283+ this .state = {
284+ actualValue: ' Hover on the plot to see the value along with the label' ,
285+ };
286+
287+ this .showPlotValue = this .showPlotValue .bind (this );
288+ }
289+
290+ // Event callback handler for 'dataplotRollOver'.
291+ // Shows the value of the hovered plot on the page.
292+ showPlotValue (eventObj , dataObj ) {
293+ this .setState ({
294+ actualValue: ` You’re are currently hovering over ${ dataObj .categoryLabel } whose value is ${ dataObj .displayValue } ` ,
295+ });
296+ }
297+
298+ render () {
299+ return (
300+ < div>
301+ < ReactFC {... chartConfigs} fcEvent- dataplotRollOver= {this .showPlotValue } / >
302+ < p style= {{ padding: ' 10px' , background: ' #f5f2f0' }}> {this .state .actualValue }< / p>
303+ < / div>
304+ );
305+ }
306+ }
307+
308+ ReactDOM .render (
309+ < Chart / > ,
310+ document .getElementById (' root' ),
311+ );
312+ ```
313+
187314
188315## Test
189316
0 commit comments