Skip to content

Commit 9dd9dba

Browse files
authored
Merge pull request #31 from fusioncharts/event-and-chart-api-readme
Event and chart api readme
2 parents be9afb9 + 9394bb9 commit 9dd9dba

File tree

7 files changed

+257
-3
lines changed

7 files changed

+257
-3
lines changed

README.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ FusionChartsModule.fcRoot(FusionCharts, Column2d, FusionTheme);
4545
})
4646
export class AppModule { }
4747
```
48+
NOTE : If you are using angular 2, please refer [Rendering chart in Angular 2](#Rendering-chart-in-Angular-2)
49+
4850

4951
Once the library is imported, you can use its components, directives in your Angular application:
5052

@@ -103,6 +105,131 @@ export class AppComponent {
103105
></fusioncharts>
104106
```
105107

108+
## Listening to events
109+
Fusincharts events can be subscribed from component's output params.
110+
Usage in template :
111+
```xml
112+
<fusioncharts
113+
width="600"
114+
height="350"
115+
type="Column2D"
116+
dataFormat="JSON"
117+
[dataSource]="dataSource"
118+
(dataplotRollOver)="plotRollOver($event)">
119+
</fusioncharts>
120+
```
121+
And in component's code , `$event` will be an object `{ eventObj : {...}, dataObj: {...} }`
122+
For more on this read [here](https://www.fusioncharts.com/dev/api/fusioncharts/fusioncharts-events)
123+
```js
124+
import {Component} from '@angular/core';
125+
126+
@Component({
127+
selector: 'my-app',
128+
templateUrl: './app.component.html'
129+
})
130+
export class AppComponent {
131+
dataSource: Object;
132+
title: string;
133+
134+
constructor() {
135+
this.title = "Angular FusionCharts Sample";
136+
137+
this.dataSource = {
138+
...// same data as above
139+
};
140+
}
141+
142+
143+
144+
plotRollOver($event){
145+
var dataValue = $event.dataObj.dataValue;
146+
console.log(`Value is ${dataValue}`);
147+
}
148+
149+
}
150+
```
151+
Get the list of fusioncharts' [events](https://www.fusioncharts.com/dev/advanced-chart-configurations/events/classifying-events)
152+
153+
154+
## Chart API
155+
Using api of charts involves getting the FusionCharts chart instance from the `initialized` event.
156+
It emits chart object which can be operated upon later.
157+
158+
In template, we add `initialized` event
159+
```xml
160+
<fusioncharts
161+
type="column2d"
162+
width="100%"
163+
height="400"
164+
dataFormat="json"
165+
[dataSource]="dataSource"
166+
(initialized)="initialized($event)">
167+
</fusioncharts>
168+
<button (click)="changeLabel()">Change label</button>
169+
```
170+
171+
And in component's code , we get `$event` as `{ chart : ChartInstance }`
172+
173+
So in order to use the chart instance , we need to store the chart instance.
174+
175+
```typescript
176+
import {Component} from '@angular/core';
177+
178+
@Component({
179+
selector: 'my-app',
180+
templateUrl: './app.component.html'
181+
})
182+
export class AppComponent {
183+
dataSource: Object;
184+
title: string;
185+
chart: any;
186+
constructor() {
187+
this.title = "Angular FusionCharts Sample";
188+
189+
this.dataSource = {
190+
...// same data as above
191+
};
192+
}
193+
194+
initialized($event){
195+
this.chart = $event.chart;
196+
}
197+
198+
changeLabel(){
199+
this.chart.setChartAttribute('caption', 'Changed caption');
200+
}
201+
202+
}
203+
```
204+
205+
## Rendering chart in Angular 2
206+
For angular version 2.x.x , we cannot use `'fusioncharts/core'` as it uses dynamic imports , which is not compatible with older version typescripts used by Angular 2.
207+
To render a chart, we need to use the older way,
208+
209+
```ts
210+
import { BrowserModule } from '@angular/platform-browser';
211+
import { NgModule } from '@angular/core';
212+
213+
import { AppComponent } from './app.component';
214+
215+
// Import angular-fusioncharts
216+
import { FusionChartsModule } from 'angular-fusioncharts';
217+
218+
// Import FusionCharts library and chart modules
219+
import * as FusionCharts from 'fusioncharts'; // Change fusioncharts/core to fusioncharts and use `* as` syntax
220+
import * as Charts from 'fusioncharts/fusioncharts.charts'; // Contains all the charts under FusionCharts XT , Read below for details
221+
222+
import * as FusionTheme from 'fusioncharts/themes/fusioncharts.theme.fusion';
223+
224+
// Pass the fusioncharts library and chart modules
225+
FusionChartsModule.fcRoot(FusionCharts, Charts, FusionTheme);
226+
227+
```
228+
Note: All other code for the component and template remain same as above.
229+
230+
We have used `fusioncharts/fusioncharts.charts` file to use all the charts which come under FusionCharts XT.
231+
To know more about other charts and widgets, read this [link](https://www.fusioncharts.com/dev/getting-started/plain-javascript/install-using-plain-javascript)
232+
106233
## Development
107234

108235
To generate all `*.js`, `*.js.map` and `*.d.ts` files:

dist/README.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ FusionChartsModule.fcRoot(FusionCharts, Column2d, FusionTheme);
4545
})
4646
export class AppModule { }
4747
```
48+
NOTE : If you are using angular 2, please refer [Rendering chart in Angular 2](#Rendering-chart-in-Angular-2)
49+
4850

4951
Once the library is imported, you can use its components, directives in your Angular application:
5052

@@ -103,6 +105,131 @@ export class AppComponent {
103105
></fusioncharts>
104106
```
105107

108+
## Listening to events
109+
Fusincharts events can be subscribed from component's output params.
110+
Usage in template :
111+
```xml
112+
<fusioncharts
113+
width="600"
114+
height="350"
115+
type="Column2D"
116+
dataFormat="JSON"
117+
[dataSource]="dataSource"
118+
(dataplotRollOver)="plotRollOver($event)">
119+
</fusioncharts>
120+
```
121+
And in component's code , `$event` will be an object `{ eventObj : {...}, dataObj: {...} }`
122+
For more on this read [here](https://www.fusioncharts.com/dev/api/fusioncharts/fusioncharts-events)
123+
```js
124+
import {Component} from '@angular/core';
125+
126+
@Component({
127+
selector: 'my-app',
128+
templateUrl: './app.component.html'
129+
})
130+
export class AppComponent {
131+
dataSource: Object;
132+
title: string;
133+
134+
constructor() {
135+
this.title = "Angular FusionCharts Sample";
136+
137+
this.dataSource = {
138+
...// same data as above
139+
};
140+
}
141+
142+
143+
144+
plotRollOver($event){
145+
var dataValue = $event.dataObj.dataValue;
146+
console.log(`Value is ${dataValue}`);
147+
}
148+
149+
}
150+
```
151+
Get the list of fusioncharts' [events](https://www.fusioncharts.com/dev/advanced-chart-configurations/events/classifying-events)
152+
153+
154+
## Chart API
155+
Using api of charts involves getting the FusionCharts chart instance from the `initialized` event.
156+
It emits chart object which can be operated upon later.
157+
158+
In template, we add `initialized` event
159+
```xml
160+
<fusioncharts
161+
type="column2d"
162+
width="100%"
163+
height="400"
164+
dataFormat="json"
165+
[dataSource]="dataSource"
166+
(initialized)="initialized($event)">
167+
</fusioncharts>
168+
<button (click)="changeLabel()">Change label</button>
169+
```
170+
171+
And in component's code , we get `$event` as `{ chart : ChartInstance }`
172+
173+
So in order to use the chart instance , we need to store the chart instance.
174+
175+
```typescript
176+
import {Component} from '@angular/core';
177+
178+
@Component({
179+
selector: 'my-app',
180+
templateUrl: './app.component.html'
181+
})
182+
export class AppComponent {
183+
dataSource: Object;
184+
title: string;
185+
chart: any;
186+
constructor() {
187+
this.title = "Angular FusionCharts Sample";
188+
189+
this.dataSource = {
190+
...// same data as above
191+
};
192+
}
193+
194+
initialized($event){
195+
this.chart = $event.chart;
196+
}
197+
198+
changeLabel(){
199+
this.chart.setChartAttribute('caption', 'Changed caption');
200+
}
201+
202+
}
203+
```
204+
205+
## Rendering chart in Angular 2
206+
For angular version 2.x.x , we cannot use `'fusioncharts/core'` as it uses dynamic imports , which is not compatible with older version typescripts used by Angular 2.
207+
To render a chart, we need to use the older way,
208+
209+
```ts
210+
import { BrowserModule } from '@angular/platform-browser';
211+
import { NgModule } from '@angular/core';
212+
213+
import { AppComponent } from './app.component';
214+
215+
// Import angular-fusioncharts
216+
import { FusionChartsModule } from 'angular-fusioncharts';
217+
218+
// Import FusionCharts library and chart modules
219+
import * as FusionCharts from 'fusioncharts'; // Change fusioncharts/core to fusioncharts and use `* as` syntax
220+
import * as Charts from 'fusioncharts/fusioncharts.charts'; // Contains all the charts under FusionCharts XT , Read below for details
221+
222+
import * as FusionTheme from 'fusioncharts/themes/fusioncharts.theme.fusion';
223+
224+
// Pass the fusioncharts library and chart modules
225+
FusionChartsModule.fcRoot(FusionCharts, Charts, FusionTheme);
226+
227+
```
228+
Note: All other code for the component and template remain same as above.
229+
230+
We have used `fusioncharts/fusioncharts.charts` file to use all the charts which come under FusionCharts XT.
231+
To know more about other charts and widgets, read this [link](https://www.fusioncharts.com/dev/getting-started/plain-javascript/install-using-plain-javascript)
232+
106233
## Development
107234

108235
To generate all `*.js`, `*.js.map` and `*.d.ts` files:

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!doctype html><html><head><meta charset="utf-8"><title>Angular FusionCharts</title><base href=""><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" type="image/x-icon" href="favicon.ico"><link href="styles.1f9a0e540f566da2a999.bundle.css" rel="stylesheet"/></head><body><app>Loading...</app><script type="text/javascript" src="inline.4aaeefe2e707a9f83704.bundle.js"></script><script type="text/javascript" src="polyfills.adb2df9f86a0c3842e67.bundle.js"></script><script type="text/javascript" src="vendor.2df7664b6e101d4bc927.bundle.js"></script><script type="text/javascript" src="main.22a9ff84c0cfa1e984b0.bundle.js"></script></body></html>
1+
<!doctype html><html><head><meta charset="utf-8"><title>Angular FusionCharts</title><base href=""><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" type="image/x-icon" href="favicon.ico"><link href="styles.1f9a0e540f566da2a999.bundle.css" rel="stylesheet"/></head><body><app>Loading...</app><script type="text/javascript" src="inline.dc826832abca8165cd8d.bundle.js"></script><script type="text/javascript" src="polyfills.adb2df9f86a0c3842e67.bundle.js"></script><script type="text/javascript" src="vendor.cb107f6b1d0fa1a26933.bundle.js"></script><script type="text/javascript" src="main.f7fbff3ff8e6d736a37e.bundle.js"></script></body></html>

docs/inline.4aaeefe2e707a9f83704.bundle.js renamed to docs/inline.dc826832abca8165cd8d.bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/vendor.2df7664b6e101d4bc927.bundle.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/vendor.cb107f6b1d0fa1a26933.bundle.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)