-
Notifications
You must be signed in to change notification settings - Fork 23
Ionic usage
Richard Natal edited this page Apr 3, 2017
·
6 revisions
(Tested with ionic v2.2.2 and ng2-highcharts v0.6.x)
- install the ionic CLI and typings CLI to global npm:
npm i -g ionic
; - Start a sample project:
ionic start myApp --v2
; - Enter the project directory:
cd myApp
; - Install ng2-highcharts and highcharts:
npm install [email protected] [email protected] --save
;
- Import the following code into src/pages/home/home.ts:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
chartData = {
chart: {
type: 'column'
},
xAxis: {
categories: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
},
series: [
{
name: 'NC',
data: [7057, 6858, 6643, 6570, 6115, 107, 31, 635, 203, 2, 2]
}, {
name: 'OK',
data: [54047, 52484, 50591, 49479, 46677, 33, 156, 947, 408, 6, 2]
}, {
name: 'KO',
data: [11388, 11115, 10742, 10757, 10290, 973, 914, 4054, 732, 34, 2]
}, {
name: 'VALID',
data: [8836, 8509, 8255, 7760, 7621, 973, 914, 4054, 732, 34, 2]
}, {
name: 'CHECK',
data: [115, 162, 150, 187, 172, 973, 914, 4054, 732, 34, 2]
}, {
name: 'COR',
data: [12566, 12116, 11446, 10749, 10439, 973, 914, 4054, 732, 34, 2]
}
]
};
constructor(public navCtrl: NavController) {
}
}
- Add chart to src/pages/home/home.html
<ion-header>
<ion-navbar>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<div [ng2-highcharts]="chartData"></div>
</ion-content>
- Add the
Ng2HighchartsModule
dependency to your project editingapp.module.ts
:
//...
import { Ng2HighchartsModule } from 'ng2-highcharts';
//...
imports: [
IonicModule.forRoot(MyApp),
Ng2HighchartsModule
],
//...
- The hack step. Add the following 2 lines to top of src/app/main.ts so ionic can embed highcharts correctly to your bundle:
import * as HC from 'highcharts';
window['Highcharts'] = HC;
- Run
ionic serve
, open a browser and go tohttp://localhost:8000
.