1

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

1
  • did you try with ng2-highcharts Commented Feb 11, 2018 at 5:12

2 Answers 2

1

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;
}

DEMO

Sign up to request clarification or add additional context in comments.

6 Comments

Works on Angular 5? & What is the best chart library for ionic/angular
Which charting library is better?
with angular you can use ng2-charts or highcharts
marl of the answer helped
i am getting an error in the app module.ts saying that ChartModule.forRoot(require('highcharts'))' cannot find name require
|
1

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]
      }]
    })
  }

}

2 Comments

i tried your solution but im getting this below error ERROR TypeError: Cannot read property 'nativeElement' of undefined
Check this line @ViewChild("container", { read: ElementRef }) container: ElementRef; ,error may be here. Please add you working demo where the error is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.