Giter Site home page Giter Site logo

amcharts3-angular2's Introduction

An official directive for amCharts V3 products for Angular 2

Installation

npm install amcharts/amcharts3-angular2 --save

How to use

  1. In your HTML file, load the amCharts library using <script> tags:
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>

  1. In your Angular2 module, import the amCharts directive and place it into the declarations:
import { AmChartsDirective } from "amcharts3-angular2/amcharts.directive";

@NgModule({
  declarations: [ AmChartsDirective ]
})

  1. Use the <amCharts> tag in your template:
@Component({
  template: `<amCharts [id]="id" [options]="chart" [style.width.%]="100" [style.height.%]="100"></amCharts>`
})

  1. Specify the chart config in your component:
export class AppComponent {
  id = "chartdiv";

  chart = {
    "type": "serial",
    "theme": "light",
    "dataProvider": []
    ...
  };
}

  1. If you want to dynamically change the chart config after the chart has been created, you first need to create a copy of the existing config:
// Make a copy of the existing config
this.chart = JSON.parse(JSON.serialize(this.chart));

// Change the config
this.chart.dataProvider = [...];

Alternatively, you can use a function to create a new config:

function makeConfig(dataProvider) {
  return {
    "type": "serial",
    "theme": "light",
    "dataProvider": dataProvider
    ...
  };
}
// Change the config
this.chart = makeConfig([...]);

Why do you need to make a copy of the config? Even if you change the properties of the object, the object itself has not changed, and therefore Angular2 does not update the AmCharts directive.

But if you make a copy of the object, then Angular2 realizes that the object is different, and so it updates the AmCharts directive. This is an issue with Angular2, and there isn't much we can do about it.

amcharts3-angular2's People

Contributors

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