5

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.

Alex Kibler
  • 4,674
  • 9
  • 44
  • 74
  • http://stackoverflow.com/questions/37849490/ng2-chart-doesnt-display-as-expected-even-more-the-console-doesnt-show-any-err?rq=1 – yurzui Jun 28 '16 at 19:33
  • do you have a solution I have added ng2 charts : Can't bind to 'datasets' since it isn't a known property of 'base-chart'. – EL missaoui habib Oct 13 '16 at 22:33

4 Answers4

11

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>
Alex Shnyrov
  • 548
  • 5
  • 12
6

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

Cengkuru Michael
  • 4,590
  • 1
  • 33
  • 33
  • you saved me some time man, never thought this would cause my issue. Thanks a lot! Do you know if theirs another way to fix this, while keeping responsive true? – Rob Angelier Feb 06 '20 at 14:32
1

In case, you're fetching data from API, try this

@ViewChild(BaseChartDirective) chart?: BaseChartDirective;

getChartData(){
  // do something
  this.chart?.chart?.update()
}
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 10 '23 at 13:46
0

Adding for future seekers

In my case, it was the chart type. I was using horizontalbar. It worked when i changed it to bar or horizontalBar.

Alexander Santos
  • 1,458
  • 11
  • 22