Chart.js v2 not rendering in Angular 2
See original GitHub issueI was able to render charts with v1.0.2 in Angular 2, but with v2.0.0 it doesn’t render anything in the screen and doesn’t log anything on the console.
I’m using the example provided in v2 docs:
constructor(el: ElementRef) {}
ngAfterViewInit() {
var ctx = this.el.nativeElement.firstChild.getContext("2d");
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3]
}]
},
options:{
scales:{
yAxes:[{
ticks:{
beginAtZero:true
}
}]
}
}
});
}
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Chart.js chart doesn't render when using Angular 2 [duplicate]
I am attempting to use Chart.js 2.0 in an Angular2 application that is written in typescript. To start with I've just been trying...
Read more >chart.js not getting rendered inside ng-template in angular ...
It seems like that because you are using trying to plot the chart in a sub template it is not available known in...
Read more >Line Chart - Chart.js
Line Chart. A line chart is a way of plotting data points on a line. Often, it is used to show trend data,...
Read more >Chart.js
At the same time, canvas rendering disallows CSS styling, so you will have to use built-in options for that, or create a custom...
Read more >Updating Charts - Chart.js
Adding and removing data is supported by changing the data array. To add data, just add data into the data array as seen...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@hertz1 this issue seems to be that the
<chart>
component has no size. V2 generally sizes to fit the parent. I added a container div around the canvas that is 100% width and height. Updated the part that gets the canvas context.The result is: https://plnkr.co/edit/RbhYj4uEeSC8MSZZHBe3?p=preview
@hertz1 works for me, take a look here:
https://github.com/evoila/angular2-chartjs2