Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ng2-charts app not showing charts

I followed the instructions on the ng2-charts demo page to get set up. I'm using angular-cli so I also imported the packages using System.JS. Then I copied the demo code, but it won't display. The canvas is being created but no chart is being drawn. My component and template code are exactly the same as here.

like image 449
Alex Kibler Avatar asked Dec 06 '22 17:12

Alex Kibler


2 Answers

Use <div style="display: block"> around canvas tag

Your final html code should look similar to this

<div style="display: block">
  <canvas
    baseChart
    [chartType]="'line'"
    [datasets]="chartData"
    [labels]="chartLabels"
    [options]="chartOptions"
    [legend]="true"
    (chartClick)="onChartClick($event)">
  </canvas>
</div>
like image 50
Alex Shnyrov Avatar answered Dec 09 '22 15:12

Alex Shnyrov


responsive: true sometimes the problem. When changed to false the will canvas appear.

like image 28
Cengkuru Michael Avatar answered Dec 09 '22 15:12

Cengkuru Michael