|
1 | | -### [Demos and Documentation](http://fusioncharts.github.io/react-fusioncharts-component/) |
| 1 | +#### [Demos and Documentation](https://fusioncharts.github.io/react-fusioncharts-component/) |
2 | 2 |
|
3 | | -## Introduction |
| 3 | +# react-fusionCharts |
4 | 4 |
|
5 | | -FusionCharts Suite XT is a front-end, JavaScript-based, comprehensive collection of 90+ charts and 1000+ maps. This includes basic and complex charts like the column and bar charts, pie and doughnut charts, treemap, heatmap, logarithmic charts, and so on; gauges like the angular gauge, bulb gauge, thermometer gauge, and so on; and maps for all continents, major countries, and all US states. |
| 5 | +A simple and lightweight `React` component which provides bindings for `FusionCharts` JavaScript Charting Library. It easily adds rich and interactive charts to any `React` Projects. |
6 | 6 |
|
7 | | -The **react-fusioncharts** plugin, along with FusionCharts Suite XT, lets you add interactive JavaScript charts and graphs to your web and mobile applications using only a single ReactJS component. |
| 7 | +## Installation |
8 | 8 |
|
9 | | -This article outlines the steps to be executed for rendering charts using the **react-fusioncharts** plugin. |
| 9 | +To install `react-fusioncharts`, run: |
10 | 10 |
|
11 | | -#### Step 1: Install **fusioncharts**, **react**, **react-dom**, and **react-fusioncharts** npm package |
12 | | -Execute the commands below in the terminal to install **fusioncharts**, **react**, **react-dom**, and **react-fusioncharts** node modules. |
| 11 | +```bash |
| 12 | +$ npm install react-fusioncharts --save |
| 13 | +``` |
13 | 14 |
|
14 | | -```sh |
15 | | -npm install react --save |
16 | | -npm install react-dom --save |
17 | | -npm install fusioncharts --save |
18 | | -npm install react-fusioncharts --save |
| 15 | +Also install `fusionCharts`, if it is not already installed: |
19 | 16 |
|
20 | | -# or single line |
21 | | -npm install react react-dom fusioncharts react-fusioncharts --save |
| 17 | +```bash |
| 18 | +$ npm install fusioncharts --save |
22 | 19 | ``` |
23 | 20 |
|
24 | | -#### Step 2: Add the HTML container element for rendering the chart |
25 | | - |
26 | | -In your HTML, find the section where you wish to render the chart place a `<div>` for the FusionCharts to be rendered. |
| 21 | +## Getting Started |
27 | 22 |
|
28 | | -`<div id='chart-container'></div>` |
| 23 | +After installing `react-fusioncharts`, import it in your `React` app: |
29 | 24 |
|
30 | | -#### Step 3: Import react-fusioncharts package from npm |
| 25 | +```javascript |
| 26 | +import React from 'react'; |
| 27 | +import ReactDOM from 'react-dom'; |
| 28 | +import FusionCharts from 'fusioncharts'; |
| 29 | +import Charts from 'fusioncharts/fusioncharts.charts'; |
| 30 | +import ReactFC from 'react-fusioncharts'; |
| 31 | + |
| 32 | +Charts(FusionCharts); |
| 33 | + |
| 34 | +const myDataSource = { |
| 35 | + chart: { |
| 36 | + caption: 'Harry\'s SuperMart', |
| 37 | + subCaption: 'Top 5 stores in last month by revenue', |
| 38 | + numberPrefix: '$', |
| 39 | + }, |
| 40 | + data: [ |
| 41 | + { |
| 42 | + label: 'Bakersfield Central', |
| 43 | + value: '880000', |
| 44 | + }, |
| 45 | + { |
| 46 | + label: 'Garden Groove harbour', |
| 47 | + value: '730000', |
| 48 | + }, |
| 49 | + { |
| 50 | + label: 'Los Angeles Topanga', |
| 51 | + value: '590000', |
| 52 | + }, |
| 53 | + { |
| 54 | + label: 'Compton-Rancho Dom', |
| 55 | + value: '520000', |
| 56 | + }, |
| 57 | + { |
| 58 | + label: 'Daly City Serramonte', |
| 59 | + value: '330000', |
| 60 | + }, |
| 61 | + ], |
| 62 | +}; |
31 | 63 |
|
32 | | -Import **react**, **react-dom**, **fusioncharts**, and **react-fusioncharts** modules, in this order, through npm. In your JavaScript code, define an object that consists of all the configurations and their values, required to render FusionCharts. |
| 64 | +const chartConfigs = { |
| 65 | + type: 'column2d', |
| 66 | + width: 600, |
| 67 | + height: 400, |
| 68 | + dataFormat: 'json', |
| 69 | + dataSource: myDataSource, |
| 70 | +}; |
33 | 71 |
|
| 72 | +ReactDOM.render( |
| 73 | + <ReactFC {...chartConfigs} />, |
| 74 | + document.getElementById('root'), |
| 75 | +); |
34 | 76 | ``` |
| 77 | + |
| 78 | +## Using Licensed Version of FusionCharts |
| 79 | + |
| 80 | +While using licensed version of `FusionCharts`, you need to specify library as follows: |
| 81 | + |
| 82 | +Specify library for all charts: |
| 83 | + |
| 84 | +```javascript |
35 | 85 | import React from 'react'; |
36 | 86 | import ReactDOM from 'react-dom'; |
37 | | -import fusioncharts from 'fusioncharts'; |
38 | | -// Load the charts module |
39 | | -import charts from 'fusioncharts/fusioncharts.charts'; |
40 | | -import react-fusioncharts from 'react-fusioncharts'; |
41 | | -
|
42 | | -// Pass fusioncharts as a dependency of charts |
43 | | -charts(FusionCharts) |
44 | | -
|
45 | | -var chartConfigs = { |
46 | | - type: ..., |
47 | | - renderAt: ..., |
48 | | - className: ..., // ReactJS attribute-name for DOM classes |
49 | | - dataFormat: ..., |
50 | | - dataSource: ... |
51 | | -}; |
52 | | -``` |
| 87 | +import ReactFC from 'react-fusioncharts'; |
| 88 | +// Here import licensed version of FusionCharts |
| 89 | +import FusionCharts from './library_path/fusioncharts'; |
| 90 | +import Charts from './library_path/fusioncharts/fusioncharts.charts'; |
53 | 91 |
|
54 | | -#### Step 4: Pass the configurations required for FusionCharts and render the chart |
55 | | -##### FusionCharts plugin for **react** can be used in two ways: |
56 | | -1. Use the **ReactFC** component directly in **ReactDOM** to render the chart. The configurations are passed as props of the component. |
57 | | -2. Create multiple **ReactFC** component inside your custom defined component to render individual charts. This way you would be able to hold the state in your custom component and will be able to perform various activities using the component’s lifecycle hooks. |
| 92 | +// Provide FusionCharts core and other modules to resolve |
| 93 | +ReactFC.fcRoot(FusionCharts, Charts) |
58 | 94 |
|
59 | | -##### Method 1: |
60 | | -Render the chart in the **React** application for a standalone chart, we can choose to make a component class or directly render the chart with the **ReactFC** component class. The object containing the chart configuration properties are passed to the **FusionCharts** component as props, as shown below: |
| 95 | +........ |
61 | 96 |
|
62 | 97 | ``` |
| 98 | + |
| 99 | +Specify library for a particular chart: |
| 100 | + |
| 101 | +```javascript |
| 102 | +import React from 'react'; |
| 103 | +import ReactDOM from 'react-dom'; |
| 104 | +import ReactFC from 'react-fusioncharts'; |
| 105 | +// Here import licensed version of FusionCharts |
| 106 | +import FusionCharts from './library_path/fusioncharts'; |
| 107 | +import Charts from './library_path/fusioncharts/fusioncharts.charts'; |
| 108 | + |
| 109 | +// Resolve modules |
| 110 | +Charts(FusionCharts) |
| 111 | + |
63 | 112 | ReactDOM.render( |
64 | | - <ReactFC {...chartConfigs} />, |
65 | | - document.getElementById('chart-container') |
| 113 | + <ReactFC |
| 114 | + width="600" |
| 115 | + height="400" |
| 116 | + type="column2d" |
| 117 | + dataSource={ /* Chart data source */ } |
| 118 | + fcLibrary={FusionCharts} // Provide FusionCharts library |
| 119 | + />, |
| 120 | + document.getElementById('root'), |
66 | 121 | ); |
67 | | -``` |
68 | 122 |
|
69 | | -##### Method 2: |
70 | | -Create a custom MyApp component to render the chart as shown below: |
| 123 | +....... |
71 | 124 |
|
72 | 125 | ``` |
73 | | -var MyApp = React.createClass({ |
74 | | - ..., // Rest of the React Component Code |
75 | | - render: function () { |
76 | | - return ( |
77 | | - <ReactFC {...categoryChartConfigs} /> |
78 | | - <ReactFC {...revenueChartConfigs} /> |
79 | | - ); |
80 | | - } |
81 | | -}); |
82 | 126 |
|
83 | | -ReactDOM.render( |
84 | | - <MyApp />, |
85 | | - document.getElementById('chart-container') |
86 | | -); |
| 127 | +## Test |
| 128 | + |
| 129 | +```sh |
| 130 | +$ npm test |
87 | 131 | ``` |
88 | 132 |
|
89 | | -While it is recommended to create an object, with the configuration properties, and passing the values defined, you can also pass the configuration properties separately as shown below: |
| 133 | +## Contributing |
| 134 | + |
| 135 | +* Clone the repository. |
| 136 | +* Install dependencies |
| 137 | +* Run `npm start` to start the dev server. |
| 138 | +* Open `http://localhost:5000/` in your browser. |
90 | 139 |
|
| 140 | +```sh |
| 141 | +$ git clone https://github.com/fusioncharts/react-fusioncharts-component.git |
| 142 | +$ cd react-fusioncharts-component |
| 143 | +$ npm i |
| 144 | +$ npm start |
91 | 145 | ``` |
92 | | -ReactDOM.render( |
93 | | - <ReactFC |
94 | | - type: ..., |
95 | | - renderAt: ..., |
96 | | - className: ..., |
97 | | - dataFormat: ..., |
98 | | - dataSource: ... />, |
99 | | - document.getElementById('chart-container') |
100 | | -); |
| 146 | + |
| 147 | +To build, run: |
| 148 | + |
| 149 | +```sh |
| 150 | +$ npm run build |
101 | 151 | ``` |
102 | 152 |
|
103 | | -Your chart should now render when the page is loaded. |
| 153 | +### [Demos and Documentation](https://fusioncharts.github.io/react-fusioncharts-component/) |
104 | 154 |
|
105 | | -### Licensing |
106 | | -React-FusionCharts is open-source and distributed under the terms of the MIT/X11 License. You will still need to download and include FusionCharts in your page. This project provides no direct functionality. You can [Download an evaluation](http://fusioncharts.com/download/). You will still need to purchase a FusionCharts license to use in a commercial environment (FusionCharts is [free for non-commercial and personal use](http://www.fusioncharts.com/download/free/)) . |
|
0 commit comments