• Stars
    star
    328
  • Rank 128,352 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Angular2 component for nvd3

ng2-nvd3

Build Status NPM Version

Angular component for nvd3 (uses d3 v3!). 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 (v3.5.17) and nvd3 as dependencies.

Basic usage

Simple bar chart

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

Simple discrete bar chart:

Module
import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent }  from './app.component';
import { NvD3Module } from 'ng2-nvd3';

// d3 and nvd3 should be included somewhere
import 'd3';
import 'nvd3';

@NgModule({
    imports:      [ BrowserModule, NvD3Module ],
    declarations: [ AppComponent ],
    bootstrap:    [ AppComponent ]
})
export class AppModule { }
Component
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
declare let d3: any;

@Component({
  selector: 'main',
  template: `
    <div>
      <nvd3 [options]="options" [data]="data"></nvd3>
    </div>
  `,
  // include original styles
  styleUrls: [
    '../../node_modules/nvd3/build/nv.d3.css'
  ],
  encapsulation: ViewEncapsulation.None
})

export class AppComponent 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
          }
        ]
      }
    ];
  }

}

Tests

npm test

Thanks

Special thanks to Tobias Walle and MaibornWolff team for the huge updates #51 !

Change Log

2.0.0 (master)

Fixed aot issue #104

2.0.0-rc3

  • Angular 4

1.1.3

  • 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

More Repositories

1

awesome-haskell

A collection of awesome Haskell links, frameworks, libraries and software. Inspired by awesome projects line.
Haskell
3,070
star
2

angular-nvd3

AngularJS directive for NVD3 reusable charting library (based on D3). Easily customize your charts via JSON API.
JavaScript
1,292
star
3

json-tree

AngularJS directive for displaying and editing JSON tree
JavaScript
143
star
4

yarrow

svg animated arrow pointer and tooltip
JavaScript
48
star
5

git-edit

Edit HTML web pages in browser and commit the changes to Github immediately.
JavaScript
44
star
6

simplifr

Simplifies JSON into a flat single-level path-value structure.
JavaScript
34
star
7

svg-path-utils

Some utils for SVG's path data, like inverse path data calculation ...
JavaScript
27
star
8

redux-json-tree

Editable JSON tree React component for deeply nested data.
JavaScript
21
star
9

git-proxy

A simple lightweight proxy server for maintaining web applications. It provides a secure token-base Github OAuth and a private storage for application sensitive data.
Ruby
11
star
10

play-angular-demos

Growing collection of demos of using Playframework with AngularJS. Combining multiple AngularJS projects into one app.
JavaScript
4
star
11

yandex-metrika

Scala client wrapper for Yandex.Metrika API
Scala
3
star
12

chart-grid-control

Simple and convenient tool for handling Time Series data based on ZedGraph .NET library. It can be integrated as a standalone User Control into your project.
Visual Basic
3
star
13

git-connect

Javascript plugin for providing token-base Github OAuth via proxy with cookie storage.
JavaScript
3
star
14

redux-standalone-component

Simple standalone React component in combination with Redux
JavaScript
1
star
15

yandex-direct-simulator

Scala
1
star
16

yandex-direct

Scala client wrapper for Yandex.Direct API
Scala
1
star