Coder Social home page Coder Social logo

dronesitter / angular-nvd3 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from krispo/angular-nvd3

0.0 1.0 0.0 3.75 MB

An AngularJS directive for NVD3 reusable charting library (based on D3). Easily customize your charts via JSON API.

Home Page: http://krispo.github.io/angular-nvd3

License: MIT License

JavaScript 97.55% CSS 2.45%

angular-nvd3's Introduction

Angular-nvD3

This thing is designed to make it easier to work with nvd3.js re-usable charting library. This directive allows you to easily customize your charts via JSON API.

The key feature is that the original hierarchical structure of nvd3 models is completely preserved in directive JSON structure. This means that while you creating a complex chart that containing multiple elementary chart models (such as line, bar, axis, ...), you can in turn customize the properties of each internal elementary models as well as the global charting properties the way you want. This can be done as usual, but it becomes quite easily to customize while applying JSON approach to.

Try it online.

How to use

Install

Install it via bower:

$ bower install angular-nvd3

An angular.js, D3.js and nvd3.js would be installed as a dependency automatically. If it won't for some reason, install it manually:

$ bower install angular
$ bower install d3
$ bower install nvd3

I advise you to use a newer nvd3 assembly rather than the last one installed via bower. A more recent and fixed assembly nv.d3.js and nv.d3.css you can find in the lib directory of this project. Also you can make your own assembly according to nvd3 docs.

Add dependencies to the <head> section of your main html:

<meta charset="utf-8">  <!-- it's important for d3.js -->
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/d3/d3.js"></script>
<script src="bower_components/nvd3/nv.d3.js"></script> <!-- or use another assembly -->
<script src="bower_components/angular-nvd3/dist/angular-nvd3.js"></script>
<link rel="stylesheet" href="bower_components/nvd3/nv.d3.css">

If you don't use bower, you can manually download and unpack directive (zip, tar.gz).

Basic usage

Inject nvd3 directive into angular module, set up some chart options and push some data to the controller:

angular.module('myApp', ['nvd3'])
       .controller('myCtrl', function('$scope'){
           $scope.options = { /* JSON data */ };
           $scope.data = { /* JSON data */ }
        })

and in html again you can use it like:

<div ng-app='myApp'>
    <div ng-controller='myCtrl'>
        <nvd3 options='options' data='data'></nvd3>
    </div>
</div>

The chart would be displayed on the page.

Example

Let's create a simple Discrete Bar Chart.

Configure options:

$scope.options = {
    chart: {
        type: 'discreteBarChart',
        height: 450,
        margin : {
            top: 20,
            right: 20,
            bottom: 60,
            left: 55
        },
        x: function(d){ return d.label; },
        y: function(d){ return d.value; },
        showValues: true,
        valueFormat: function(d){
            return d3.format(',.4f')(d);
        },
        transitionDuration: 500,
        xAxis: {
            axisLabel: 'X Axis'
        },
        yAxis: {
            axisLabel: 'Y Axis',
            axisLabelDistance: 30
        }
    }
};

Push some data:

$scope.data = [{
    key: "Cumulative Return",
    values: [
        { "label" : "A" , "value" : -29.765957771107 },
        { "label" : "B" , "value" : 0 },
        { "label" : "C" , "value" : 32.807804682612 },
        { "label" : "D" , "value" : 196.45946739256 },
        { "label" : "E" , "value" : 0.19434030906893 },
        { "label" : "F" , "value" : -98.079782601442 },
        { "label" : "G" , "value" : -13.925743130903 },
        { "label" : "H" , "value" : -5.1387322875705 }
    ]
}];

See the result.

Read more docs.

Contribute

Test it using command:

$npm test

Then build using grunt (node.js must be installed):

$grunt

Release Notes

0.1.0 (current)

  • added update method to global api, pull request
  • fixed bug for multiChart
  • added getScope method to global api. (give an access to internal directive scope, for example, we can get chart object like: $scope.api.getScope().chart)
  • fixed multiple chart rendering under initializing (fixed multiple callback calls)

0.0.9 (stable)

...

License

Licensed under the terms of the MIT License

angular-nvd3's People

Contributors

bclinkinbeard avatar demetriusnunes avatar dsine-de avatar krispo avatar oori avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.