0

I am generating chart using c3. I am accessing Rest API in the c3 chart to load the JSON data. I referred this example http://c3js.org/samples/data_load.html I am trying to load the chart dynamically using load function which gives me

Runtime Error this.chart.load is not a function

private chart: any;
this.chart = c3.generate({
    data: {
        url: '/api/systemvalues',
        type: 'line'
    }
});
setTimeout(function () {
    this.chart.load({
        url: '/api/systemvalues'
    });
}, 1000);

These are the versions used:

 @angular/core": "2.4.10", 
 "c3": "^0.4.11", 
 "d3": "^3.5.17", 
 "typescript": "2.2.2"
user93
  • 1,866
  • 5
  • 26
  • 45
user2301
  • 1,857
  • 6
  • 32
  • 63

1 Answers1

2

call the setTimeout using ()=> instead function(){

private chart: any;
this.chart = c3.generate({
    data: {
        url: '/api/systemvalues',
        type: 'line'
    }
});
setTimeout(()=>{
    this.chart.load({
        url: '/api/systemvalues'
    });
}, 1000);

OR

assign this to variable and use that variable inside a constructor and call the setTimeout function

private chart: any;
this.chart = c3.generate({
    data: {
        url: '/api/systemvalues',
        type: 'line'
    }
});
constructor(){
  var vm = this;

  setTimeout(function () {
    vm.chart.load({
        url: '/api/systemvalues'
    });
  }, 1000);
}  
Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80