Skip to content

Commit 1372a63

Browse files
committed
Merge branch 'release/4.0.2'
2 parents 7fb6e35 + fa133da commit 1372a63

File tree

3 files changed

+143
-27
lines changed

3 files changed

+143
-27
lines changed

README.md

+97-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# AngularJS Charts Plugin
1+
# angularjs-fusioncharts
22

33
Simple and effective AngularJS charts plugin for FusionCharts.
44

@@ -177,6 +177,102 @@ In `index.html`
177177
```
178178
Load it in browser , Chart should get displayed
179179

180+
### Listening to events
181+
182+
Fusincharts events can be subscribed by attaching scope functions to event attributes.
183+
All the events attributes start with `fcevent-`
184+
followed by the event name in lowercase
185+
186+
Usage in template :
187+
188+
```xml
189+
<fusioncharts
190+
width="400"
191+
height="400"
192+
type="column2d"
193+
datasource="{{myDataSource}}"
194+
fcevent-dataplotrollover="rollover(event, args)">
195+
</fusioncharts>
196+
```
197+
In the given above template, `rollover` is the scope function that needs to be defined in the controller's code.
198+
199+
For more on this read [here](https://www.fusioncharts.com/dev/api/fusioncharts/fusioncharts-events)
200+
201+
```
202+
var app = angular.module('myApp', ['ng-fusioncharts']);
203+
204+
app.controller('MyController', function($scope){
205+
$scope.myDataSource = {
206+
"chart": {
207+
"caption": "Countries With Most Oil Reserves [2017-18]",
208+
"subCaption": "In MMbbl = One Million barrels",
209+
"xAxisName": "Country",
210+
"yAxisName": "Reserves (MMbbl)",
211+
"numberSuffix": "K",
212+
"theme": "fusion"
213+
},
214+
"data": [
215+
{ "label": "Venezuela", "value": "290" },
216+
{ "label": "Saudi", "value": "260" },
217+
{ "label": "Canada", "value": "180" },
218+
{ "label": "Iran", "value": "140" },
219+
{ "label": "Russia", "value": "115" },
220+
{ "label": "UAE", "value": "100" },
221+
{ "label": "US", "value": "30" },
222+
{ "label": "China", "value": "30" }
223+
]
224+
};
225+
226+
$scope.rollover = function(event, name){
227+
console.log(event, name);
228+
}
229+
});
230+
```
231+
232+
Get the list of fusioncharts' [events](https://www.fusioncharts.com/dev/advanced-chart-configurations/events/classifying-events)
233+
234+
### Chart API
235+
236+
FusionCharts chart instance is made available from the ```initialized``` event. It provides the chart instance as a parameter which can be used to call FusionCharts methods.
237+
238+
In template, we add ```initialized``` event
239+
240+
```xml
241+
<fusioncharts
242+
width="400"
243+
height="400"
244+
type="column2d"
245+
datasource="{{myDataSource}}"
246+
initialized="onInitialized(chart)">
247+
</fusioncharts>
248+
<button ng-click="changeCaption()">Change Chart Caption</button>
249+
```
250+
251+
In order to use the chart instance, we need to store it.
252+
253+
```
254+
var app = angular.module('myApp', ['ng-fusioncharts']);
255+
256+
app.controller('MyController', function($scope){
257+
var chart;
258+
$scope.datasource = {
259+
...// same data as above
260+
};
261+
262+
$scope.onInitialized = function(chartObj){
263+
chart = chartObj;
264+
}
265+
266+
$scope.changeCaption = function(){
267+
chart.setChartAttribute('caption', 'Caption changed');
268+
}
269+
});
270+
```
271+
In the given above example, clicking the button changes the caption text to ```Caption changed```
272+
273+
Get the list of fusioncharts' [methods](https://www.fusioncharts.com/dev/api/fusioncharts/fusioncharts-methods)
274+
275+
180276
### Tutorial
181277

182278
Following tutorials will help you get started:

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angularjs-fusioncharts",
3-
"version": "4.0.0",
3+
"version": "4.0.2",
44
"description": "Angular plugin for FusionCharts",
55
"main": "dist/angular-fusioncharts.js",
66
"repository": {

src/angular-fusioncharts.js

+45-25
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,45 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
2222
(function() {
23-
var fc = angular.module('ng-fusioncharts', []);
23+
var fc = angular.module('ng-fusioncharts', []),
24+
scope = {
25+
width: '@',
26+
height: '@',
27+
data: '@',
28+
dataset: '@',
29+
categories: '@',
30+
chart: '@',
31+
linkeddata: '@',
32+
trendlines: '@',
33+
vtrendlines: '@',
34+
annotations: '@',
35+
colorrange: '@',
36+
lineset: '@',
37+
axis: '@',
38+
connectors: '@',
39+
pointers: '@',
40+
value: '@',
41+
processes: '@',
42+
tasks: '@',
43+
rows: '@',
44+
columns: '@',
45+
map: '@',
46+
markers: '@',
47+
initialized:'&'
48+
},
49+
fcEvents = ['beforelinkeditemopen','linkeditemopened','beforelinkeditemclose','linkeditemclosed','printreadystatechange','dataloadrequestcompleted','dataloaderror','dataloadcancelled','dataloadrequestcancelled','dataupdated','dataupdatecancelled','dataloadrequested','beforedataupdate','realtimeupdatecomplete','chartcleared','slicingend','slicingstart','entityrollout','entityrollover','entityclick','connectorrollover','connectorrollout','connectorclick','markerrollover','markerrollout','markerclick','pagenavigated','rotationend','rotationstart','centerlabelrollover','centerlabelrollout','centerlabelclick','centerlabelchanged','chartclick','chartmousemove','chartrollover','chartrollout','backgroundloaded','backgroundloaderror','legenditemclicked','legenditemrollover','legenditemrollout','logorollover','logorollout','logoclick','logoloaded','logoloaderror','beforeexport','exported','exportcancelled','beforeprint','printcomplete','printcancelled','datalabelclick','datalabelrollover','datalabelrollout','scrollstart','scrollend','onscroll','zoomreset','zoomedout','zoomedin','zoomed','zoommodechanged','pinned','datarestored','beforedatasubmit','datasubmiterror','datasubmitted','datasubmitcancelled','chartupdated','nodeadded','nodeupdated','nodedeleted','connectoradded','connectorupdated','connectordeleted','labeladded','labeldeleted','selectionremoved','selectionstart','selectionend','labelclick','labelrollover','labelrollout','labeldragstart','labeldragend','dataplotdragstart','dataplotdragend','processclick','processrollover','processrollout','categoryclick','categoryrollover','categoryrollout','milestoneclick','milestonerollover','milestonerollout','charttypechanged','overlaybuttonclick','loaded','rendered','drawcomplete','rendercomplete','datainvalid','dataxmlinvalid','dataloaded','nodatatodisplay','legendpointerdragstart','legendpointerdragstop','legendrangeupdated','alertcomplete','realtimeupdateerror','dataplotrollover','dataplotrollout','dataplotclick','linkclicked','beforerender','rendercancelled','beforeresize','resized','resizecancelled','beforedispose','disposed','disposecancelled','linkedchartinvoked','beforedrilldown','drilldown','beforedrillup','drillup','drilldowncancelled','drillupcancelled'],
50+
currIndex,
51+
eventName,
52+
eventsLen = fcEvents.length;
53+
for (currIndex = 0; currIndex < eventsLen; currIndex++){
54+
eventName = 'fcevent' + fcEvents[currIndex][0].toUpperCase() + fcEvents[currIndex].slice(1);
55+
scope[eventName] = '&';
56+
}
2457

2558

2659
fc.directive('fusioncharts', ['$http', function($http) {
2760
return {
28-
scope: {
29-
width: '@',
30-
height: '@',
31-
data: '@',
32-
dataset: '@',
33-
categories: '@',
34-
chart: '@',
35-
linkeddata: '@',
36-
trendlines: '@',
37-
vtrendlines: '@',
38-
annotations: '@',
39-
colorrange: '@',
40-
lineset: '@',
41-
axis: '@',
42-
connectors: '@',
43-
pointers: '@',
44-
value: '@',
45-
processes: '@',
46-
tasks: '@',
47-
rows: '@',
48-
columns: '@',
49-
map: '@',
50-
markers: '@'
51-
},
61+
scope: scope,
5262
link: function(scope, element, attrs) {
5363
var observeConf = {
5464
// non-data componenet observers
@@ -361,6 +371,16 @@
361371
chart.dispose();
362372
}
363373
chart = new FusionCharts(chartConfigObject);
374+
scope.initialized && scope.initialized({ chart: chart });
375+
for(currIndex = 0; currIndex < eventsLen ; currIndex++){
376+
eventName = 'fcevent' + fcEvents[currIndex][0].toUpperCase() + fcEvents[currIndex].slice(1);
377+
// assign all events on chart instance
378+
(function(eventName){
379+
chart.addEventListener(fcEvents[currIndex], function(event, args){
380+
scope[eventName] && scope[eventName]({ event:event, args: args });
381+
});
382+
})(eventName);
383+
}
364384
/* @todo validate the ready function whether it can be replaced in a better way */
365385
angular.element(document).ready(function(){
366386
element.ready(function(){

0 commit comments

Comments
 (0)