|
1 | | -# React-Native-FusionCharts |
| 1 | +#### [Demos and Documentation](https://fusioncharts.github.io/react-native-fusioncharts/) |
2 | 2 |
|
3 | | -React Native component for FusionCharts Javascript Charting Library. |
| 3 | +# react-native-fusioncharts |
| 4 | + |
| 5 | +A `React Native` component which provides bindings for `FusionCharts` JavaScript Charting Library. It easily adds rich and interactive charts to any `React Native` Projects. |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +To install `react-native-fusioncharts`, run: |
| 10 | + |
| 11 | +```bash |
| 12 | +$ npm install --save react-native-fusioncharts |
| 13 | +``` |
| 14 | + |
| 15 | +After installing `react-native-fusioncharts`, follow the steps below: |
| 16 | + |
| 17 | +### For Android |
| 18 | + |
| 19 | +* Create `assets` folder in `android/app/src/main` directory if it doesn't exist. |
| 20 | +* Copy `FusionCharts` library in the `assets` folder (in most cases copy `node_modules/fusioncharts` folder). |
| 21 | +* Create a file named `fuioncharts.html` in this `assets` folder with the required `FusionCharts` module files. Find the sample html file [here](https://github.com/fusioncharts/react-native-fusioncharts/blob/master/templates/fuioncharts-tpl-android.html). |
| 22 | +* Set `libraryPath` property to the `FusionCharts` component as follows: |
| 23 | + |
| 24 | +```html |
| 25 | +<FusionCharts |
| 26 | + ...... |
| 27 | + |
| 28 | + libraryPath={{ uri: 'file:///android_asset/fusioncharts.html' }} |
| 29 | + /> |
| 30 | +``` |
| 31 | + |
| 32 | +### For iOS |
| 33 | + |
| 34 | +* Create `assets` folder in your project root if it doesn't exist. |
| 35 | +* Copy `FusionCharts` library in this `assets` folder (requires only when the licensed version of `FusionCharts` is used). |
| 36 | +* Create a file named `fuioncharts-tpl.html` in this `assets` folder with the required `FusionCharts` module files. Find the sample html file [here](https://github.com/fusioncharts/react-native-fusioncharts/blob/master/templates/fuioncharts-tpl-ios.html). |
| 37 | +* Add a `build:assets` script in Application's `package.json` file as follows: |
| 38 | + |
| 39 | +`package.json` file: |
| 40 | + |
| 41 | +```javascript |
| 42 | + ...... |
| 43 | + |
| 44 | + "scripts": { |
| 45 | + ...... |
| 46 | + |
| 47 | + "build:assets": "fc-build-assets --fc-template ./assets/fusioncharts-tpl.html --fc-library ./assets/fusioncharts" |
| 48 | + }, |
| 49 | + |
| 50 | + ...... |
| 51 | +``` |
| 52 | + |
| 53 | +The `--fc-library ./assets/fusioncharts` option is only required when you copied `FusionCharts` library in your `assets` folder. |
| 54 | + |
| 55 | +**Notes:** `fc-build-assets` is an utility binary provided to package the `FusionCharts` libraries from the template `.html` file as needed by the React Native iOS build process. |
| 56 | + |
| 57 | +* Set `libraryPath` property to the `FusionCharts` component as follows: |
| 58 | + |
| 59 | +```html |
| 60 | +<FusionCharts |
| 61 | + ...... |
| 62 | + |
| 63 | + libraryPath={require('./assets/fusioncharts.html')} |
| 64 | + /> |
| 65 | +``` |
| 66 | + |
| 67 | +* Run the following command before running the app: |
| 68 | + |
| 69 | +```bash |
| 70 | +$ npm run build:assets |
| 71 | +``` |
| 72 | + |
| 73 | +## Getting Started |
| 74 | + |
| 75 | +Include the `react-native-fusioncharts` library as follows: |
| 76 | + |
| 77 | +The `App.js` file: |
| 78 | + |
| 79 | +```javascript |
| 80 | +import React, { Component } from 'react'; |
| 81 | +import { AppRegistry, StyleSheet, Text, View, Platform } from 'react-native'; |
| 82 | +import FusionCharts from 'react-native-fusioncharts'; |
| 83 | + |
| 84 | +export default class App extends Component { |
| 85 | + constructor(props) { |
| 86 | + super(props); |
| 87 | + |
| 88 | + this.state = { |
| 89 | + type: 'column2d', |
| 90 | + width: '100%', |
| 91 | + height: '100%', |
| 92 | + dataFormat: 'json', |
| 93 | + dataSource: { |
| 94 | + "chart": { |
| 95 | + "caption": "Harry's SuperMart", |
| 96 | + "subCaption": "Top 5 stores in last month by revenue", |
| 97 | + "numberprefix": "$", |
| 98 | + "theme": "fint" |
| 99 | + }, |
| 100 | + "data": [ |
| 101 | + { |
| 102 | + "label": "Bakersfield Central", |
| 103 | + "value": "880000" |
| 104 | + }, |
| 105 | + { |
| 106 | + "label": "Garden Groove harbour", |
| 107 | + "value": "730000" |
| 108 | + }, |
| 109 | + { |
| 110 | + "label": "Los Angeles Topanga", |
| 111 | + "value": "590000" |
| 112 | + }, |
| 113 | + { |
| 114 | + "label": "Compton-Rancho Dom", |
| 115 | + "value": "520000" |
| 116 | + }, |
| 117 | + { |
| 118 | + "label": "Daly City Serramonte", |
| 119 | + "value": "330000" |
| 120 | + } |
| 121 | + ] |
| 122 | + } |
| 123 | + }; |
| 124 | + |
| 125 | + this.libraryPath = Platform.select({ |
| 126 | + // Specify fusioncharts.html file location |
| 127 | + ios: require('./assets/fusioncharts.html'), |
| 128 | + android: { uri: 'file:///android_asset/fusioncharts.html' }, |
| 129 | + }); |
| 130 | + } |
| 131 | + |
| 132 | + render() { |
| 133 | + return ( |
| 134 | + <View style={styles.container}> |
| 135 | + <Text style={styles.heading}> |
| 136 | + FusionCharts Integration with React Native |
| 137 | + </Text> |
| 138 | + <View style={styles.chartContainer}> |
| 139 | + <FusionCharts |
| 140 | + type={this.state.type} |
| 141 | + width={this.state.width} |
| 142 | + height={this.state.height} |
| 143 | + dataFormat={this.state.dataFormat} |
| 144 | + dataSource={this.state.dataSource} |
| 145 | + libraryPath={this.libraryPath} // set the libraryPath property |
| 146 | + /> |
| 147 | + </View> |
| 148 | + </View> |
| 149 | + ); |
| 150 | + } |
| 151 | +} |
| 152 | + |
| 153 | +const styles = StyleSheet.create({ |
| 154 | + container: { |
| 155 | + flex: 1, |
| 156 | + padding: 10 |
| 157 | + }, |
| 158 | + heading: { |
| 159 | + fontSize: 20, |
| 160 | + textAlign: 'center', |
| 161 | + marginBottom: 10 |
| 162 | + }, |
| 163 | + chartContainer: { |
| 164 | + height: 200 |
| 165 | + } |
| 166 | +}); |
| 167 | + |
| 168 | +// skip this line if using Create React Native App |
| 169 | +AppRegistry.registerComponent('ReactNativeFusionCharts', () => App); |
| 170 | +``` |
| 171 | + |
| 172 | +## Unit Test |
| 173 | + |
| 174 | +```sh |
| 175 | +$ npm test |
| 176 | +``` |
| 177 | + |
| 178 | +## Contributing |
| 179 | + |
| 180 | +* Clone the repository. |
| 181 | +* Install dependencies |
| 182 | +* Run `npm start` to start React Native Packager server. |
| 183 | +* Run on Android or iOS emulator. |
| 184 | + |
| 185 | +```sh |
| 186 | +$ git clone https://github.com/fusioncharts/react-native-fusioncharts.git |
| 187 | +$ cd react-native-fusioncharts |
| 188 | +$ npm i |
| 189 | +$ npm start |
| 190 | +$ emulator @<name_of_android_emulator> |
| 191 | +$ npm run android [to run on Android platform] |
| 192 | +$ npm run ios [to run on iOS platform] |
| 193 | +``` |
| 194 | + |
| 195 | +To run release version of Android app, run: |
| 196 | +```sh |
| 197 | +$ npm run android:release |
| 198 | +``` |
| 199 | + |
| 200 | +To run release version of iOS app, run: |
| 201 | +```sh |
| 202 | +$ npm run ios:release |
| 203 | +``` |
| 204 | + |
| 205 | +To generate a signed release Android APK, run: |
| 206 | +```sh |
| 207 | +$ npm run build:android |
| 208 | +``` |
| 209 | + |
| 210 | +To generate release iOS app, run: |
| 211 | +```sh |
| 212 | +$ npm run build:ios |
| 213 | +``` |
| 214 | + |
| 215 | +### [Demos and Documentation](https://fusioncharts.github.io/react-native-fusioncharts/) |
0 commit comments