angular-c3-directive

WebJar for angular-c3-directive

License

License

MIT
Categories

Categories

Angular User Interface Web Frameworks
GroupId

GroupId

org.webjars.bower
ArtifactId

ArtifactId

angular-c3-directive
Last Version

Last Version

0.3.0
Release Date

Release Date

Type

Type

jar
Description

Description

angular-c3-directive
WebJar for angular-c3-directive
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/atavakoli/angular-c3-directive

Download angular-c3-directive

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.bower/angular-c3-directive/ -->
<dependency>
    <groupId>org.webjars.bower</groupId>
    <artifactId>angular-c3-directive</artifactId>
    <version>0.3.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.bower/angular-c3-directive/
implementation 'org.webjars.bower:angular-c3-directive:0.3.0'
// https://jarcasting.com/artifacts/org.webjars.bower/angular-c3-directive/
implementation ("org.webjars.bower:angular-c3-directive:0.3.0")
'org.webjars.bower:angular-c3-directive:jar:0.3.0'
<dependency org="org.webjars.bower" name="angular-c3-directive" rev="0.3.0">
  <artifact name="angular-c3-directive" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.bower', module='angular-c3-directive', version='0.3.0')
)
libraryDependencies += "org.webjars.bower" % "angular-c3-directive" % "0.3.0"
[org.webjars.bower/angular-c3-directive "0.3.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.webjars.bower : angular jar [1.4,1.5)
org.webjars.bower : c3 jar 0.4.10

Project Modules

There are no modules declared in this project.

angular-c3-directive

Bower License

Dead simple AngularJS directive for the C3.js chart library

JSFiddle Demo

Installation

Installation is performed using Bower. The only dependencies are AngularJS and C3.js.

bower install angular-c3-directive

Usage

In your HTML:

<html ng-app="myApp">

  ...

  <script src="angular.js"></script>
  <script src="d3.js"></script> <!-- Required by C3.js -->
  <script src="c3.js"></script>
  <script src="angular-c3.js"></script>

  ...

  <div c3="chart"></div>

  ...

</html>

In your JavaScript, you need to inject c3 as a dependency.

angular.module('myApp', ['c3'])

In your controller, the object passed into the c3 attribute is the same as that passed into c3.generate(), except without the bindto property and without interaction callbacks (see Interaction below).

$scope.chart = {
  data: {
    columns: [
      ['data1', 30, 200, 100, 400, 150, 250],
      ['data2', 50, 20, 10, 40, 15, 25]
    ]
  }
};

The chart is updated whenever the object or any of its properties are modified. If the load API can be used, it will be (unless disabled; see Options below).

The model can also be watched to catch interactions that change it (e.g. clicking legend items to show/hide data).

$scope.$watchCollection('chart.data.hide', function(value, prevValue) {
  console.log('data.hide changed!');
});

Interaction

Interaction with the chart is handled by attributes on the directive, rather than callbacks on the c3 model. This is more consistent with how other Angular directives handle events, such as ng-click.

For example, in your HTML (excluding the comments):

<!--
  c3-data-click
  Corresponds to data.onclick, with the following expressions available:
    - datum: Datum clicked (corresponds to 'd' in data.onclick callback)
    - event: MouseEvent of the click

  c3-legend-click
  Corresponds to legend.item.onclick, with the following expressions available:
    - id:      ID of dataset clicked (corresponds to 1st argument in
               legend.item.onclick callback)
    - event:   MouseEvent of the click
    - default: Function performing default legend item click behavior, may be
               optionally called in your own handler
-->

<div c3="chart" c3-data-click="dataClicked(datum, event)"
                c3-legend-click="legendClicked(id, event, default)">
</div>

And in your controller:

$scope.chart = {
  data: {
    columns: [
      ['data1', 1, 2, 3],
      ['data2', 4, 5, 6]
    ]
  }
};

$scope.dataClicked = function(d, event) {
  console.log(d);       // the data point clicked;

  console.log(event);   // the MouseEvent of the click;
};

$scope.legendClicked = function(id, event, defaultClick) {
  console.log(id);     // the ID of the dataset clicked;

  console.log(event);  // the MouseEvent of the click;

  defaultClick();      // function performing the default legend click action,
                       // which may be optionally called
};

The events currently handled in this way are:

Options

Advanced options can also be passed in via the c3-options attribute. This attribute is optional and specific to the operation of this directive; it does not correspond to any configuration parameters of C3.js.

<div c3="chart" c3-options="options"></div>
$scope.options = {
  /* If true (default), detect changes to data and use the the load() API
   * whenever possible to make updates; if false, regenerate the chart on every
   * change.
   *
   * NOTE: because of the additional processing needed to detect loadable vs
   *       unloadable changes, you may want to set this to false if you have a
   *       high update rate or very large datasets.
   */
  useLoadApi: true
};

Other options to come as needed.

Versions

Version
0.3.0