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"

1 Answer 1

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);
}  
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks a lot..It worked. Now I am not getting that error
This solution did not work setTimeout(()=>{ this.chart.load({ url: '/api/systemvalues' }); }, 1000);
what about the other one
The other one did not show any error. But the chart is not getting updated dynamically. I have to refresh manually to see the new values on the chart.
note that content of the timeout only executes once after 1 second. After that it will not execute
|

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.