Giter Site home page Giter Site logo

ng2-nvd3's Introduction

ng2-nvd3

Build Status NPM Version

Angular2 component for nvd3. It has similar technique as angular-nvd3 for angular 1, but designed for angular 2 and without extra features (like extended mode) you won't need.

Demos

Online demos:

  1. web page
  2. plnkr

Install

npm install ng2-nvd3

it requires angular2, d3 and nvd3 as dependencies. Tested with the current @angular version ^2.0.0-rc.4.

Basic usage

Simple bar chart

Note: d3 and nvd3 should be also included in your project bundle.

Simple discrete bar chart:

import {Component, OnInit} from '@angular/core';
import {nvD3} from 'ng2-nvd3'
declare let d3: any;

@Component({
  selector: 'main',
  directives: [nvD3],
  template: `
    <div>
      <nvd3 [options]="options" [data]="data"></nvd3>
    </div>
  `
})

export class Main implements OnInit{
  options;
  data;
  ngOnInit(){
    this.options = {
      chart: {
        type: 'discreteBarChart',
        height: 450,
        margin : {
          top: 20,
          right: 20,
          bottom: 50,
          left: 55
        },
        x: function(d){return d.label;},
        y: function(d){return d.value;},
        showValues: true,
        valueFormat: function(d){
          return d3.format(',.4f')(d);
        },
        duration: 500,
        xAxis: {
          axisLabel: 'X Axis'
        },
        yAxis: {
          axisLabel: 'Y Axis',
          axisLabelDistance: -10
        }
      }
    }
    this.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
          }
        ]
      }
    ];
  }

}

Usage directive api

No need to use api as in angular 1 case. We can get access to directive instance from parent component via @ViewChild:

import {Component, OnInit, AfterViewInit, ViewChild} from '@angular/core';
import {nvD3} from 'ng2-nvd3';

@Component({
  selector: 'main',
  directives: [nvD3],
  template: `<div><nvd3 [options]="options" [data]="data"></nvd3></div>`
})
export class Main {
  options;
  data;

  @ViewChild(nvD3)
  nvD3: nvD3;

  ngOnInit(){
    this.options = {...};
    this.data = [...];
  }

  ngAfterViewInit() {
    // this.nvD3 - directive instance
    // for example, to update the chart
    this.nvD3.chart.update()
  } 
}

Tests

npm test

Change Log

1.1.3 (master)

  • Angular2 - v2.0.0-rc4

1.1.2

  • Angular2 - v2.0.0-rc3

1.1.1

  • Angular2 - v2.0.0-rc2

1.1.0

  • Angular2 - v2.0.0-rc1

1.0.7

  • Angular2 - v2.0.0-beta.3

License

MIT

ng2-nvd3's People

Contributors

clov3r avatar krispo avatar lxrd-aj avatar

Watchers

 avatar  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.