You need to set up your development before you can do anything. Install Node.js® and npm if they are not already on your machine.
Install the Angular CLI globally.
npm install -g @angular/cli
ng new my-zoomchartsApp
Go to project directory
cd my-zoomchartsApp
Using the Angular CLI, generate a new component named zoomcharts.
ng generate component zoomcharts
Install ZoomCharts library via npm
npm install --save @dvsl/zoomcharts
The ZoomchartsComponent class
import { Component, OnInit, AfterViewInit } from '@angular/core';
import * as zc from '@dvsl/zoomcharts';
import { WindowRef } from './../WindowRef';
@Component({
selector: 'app-zoomcharts',
template: `
`
})
export class ZoomchartsComponent implements AfterViewInit {
// for optimal operation: ref to zc instance
private zc: any = zc;
constructor(private winRef: WindowRef) {
// Add license key
winRef.nativeWindow.ZoomChartsLicense = '';
winRef.nativeWindow.ZoomChartsLicenseKey = '';
}
ngAfterViewInit() {
const PieChart = this.zc.PieChart;
const t = new PieChart({
container: document.getElementById('chartPieChart'),
area: { height: 350 },
data: {
preloaded: {
subvalues: [
{
id: 'foo', value: 100, subvalues: [
{ id: 'foo-1', value: 50, style: { expandable: false } },
{ id: 'foo-2', value: 50, style: { expandable: false } }
]
},
{ id: 'bar', value: 50, style: { expandable: false } },
{ id: 'baz', value: 30, style: { expandable: false } }
]
}
}
});
}
}
//Add { "glob": "**/*", "input": "../node_modules/@dvsl/zoomcharts/lib/assets", "output": "./assets/" }
"apps": [
{
...
"assets": [
"assets",
"favicon.ico",
{ "glob": "**/*", "input": "../node_modules/@dvsl/zoomcharts/lib/assets", "output": "./assets/" }
],
...
}
],
To display the ZoomchartsComponent, you must add it to the template of the shell AppComponent.
<app-zoomcharts></app-zoomcharts>
Generate class WindowRef
ng generate class WindowRef
import { Injectable } from '@angular/core';
function _window(): any {
return window;
}
@Injectable()
export class WindowRef {
get nativeWindow(): any {
return _window();
}
}
Register WindowRef as provider
import { WindowRef } from './WindowRef';
...
@NgModule({
...
providers: [ WindowRef ]
})
export class AppModule{}
...
import { WindowRef } from './../WindowRef';
...
constructor(private winRef: WindowRef) {
// Add license key
winRef.nativeWindow.ZoomChartsLicense = '';
winRef.nativeWindow.ZoomChartsLicenseKey = '';
}
...
ng serve --open
To save your time you can import already pre-built ZoomCharts components into your project from the link below. To do so you will need to import the component into your project and configure it accordingly.
https://github.com/zoomcharts/zoomcharts-angular-component-integration-example
Check out integration example on Github.