Reputation: 159
Hi im trying to display the static data using the High charts and i am getting error 13 and i placed this
<div id="container" style="display: block;" ></div>
in html file and below is the data i am using to display chart
import * as HighCharts from 'highcharts';
ionViewDidLoad(){
var myChart = HighCharts.chart('container', {
chart: {
type: 'bar'
},
title: {
text: 'Fruit Consumption'
},
xAxis: {
categories: ['Apples', 'Bananas', 'Oranges']
},
yAxis: {
title: {
text: 'Fruit eaten'
}
},
series: [{
name: 'Jane',
data: [1, 0, 4]
}, {
name: 'John',
data: [5, 7, 3]
}]
});
}
Is there any better charting library for ionic for displaying the charts other that chart.js
Upvotes: 1
Views: 325
Reputation: 10075
Check official highcharts#typescript
stackblitz demo
import { Component, ViewChild, ElementRef } from '@angular/core';
import { NavController } from 'ionic-angular';
import Highcharts from 'highcharts';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage{
@ViewChild("container", { read: ElementRef }) container: ElementRef;
constructor(public navCtrl: NavController) {
}
ionViewDidLoad() {
Highcharts.chart(this.container.nativeElement, {
chart: {
type: 'bar'
},
title: {
text: 'Fruit Consumption'
},
xAxis: {
categories: ['Apples', 'Bananas', 'Oranges']
},
yAxis: {
title: {
text: 'Fruit eaten'
}
},
series: [{
name: 'Jane',
data: [1, 0, 4]
}, {
name: 'John',
data: [5, 7, 3]
}]
})
}
}
Upvotes: 1
Reputation: 222522
There is a package with angular2 named angular2-highcharts
import { ChartModule } from 'angular2-highcharts';
and options as,
class AppComponent {
constructor() {
this.options = {
chart: {
type: 'bar'
},
title: {
text: 'Fruit Consumption'
},
xAxis: {
categories: ['Apples', 'Bananas', 'Oranges']
},
yAxis: {
title: {
text: 'Fruit eaten'
}
},
series: [{
name: 'Jane',
data: [1, 0, 4]
}, {
name: 'John',
data: [5, 7, 3]
}]
};
}
options: Object;
}
Upvotes: 1