Ng2-charts: TypeError: t.controllers[o.type] is not a constructor

Created on 24 Jun 2016  路  5Comments  路  Source: valor-software/ng2-charts

Most helpful comment

For anybody coming from Google who might have done what I did... If you are declaring the chart type directly in the HTML template I had to wrap it in double quotes.

<canvas baseChart class="chart"
                [datasets]="priceDataset"
                [chartType]='"line"'></canvas>

Note the "line" part. 馃榿

All 5 comments

you are using chart.js 2, use proper chart (type) names (lower cased)
see http://www.chartjs.org/docs/

For anybody coming from Google who might have done what I did... If you are declaring the chart type directly in the HTML template I had to wrap it in double quotes.

<canvas baseChart class="chart"
                [datasets]="priceDataset"
                [chartType]='"line"'></canvas>

Note the "line" part. 馃榿

@nabilfreeman
The reason you need the quotes around "line" is because you are binding the attribute, which will tell Angular to expect a javascript variable or object of some sort. Without the quotes it is trying to find a variable NAMED line, not the string "line". By putting the quotes around it, you are supplying Angular with an actual javascript string.

If you are using a static value for an attribute then another option is to not bind it, but just write out the attribute and its value as standard HTML markup:

<canvas baseChart class="chart" [datasets]="priceDataset" chartType="line"></canvas>

@elbootio thank you for the explanation! this makes things very clear 馃槃

In my case I needed to update Chart.js from 2.0.2 to latest version (2.7.2). Else wasn't able to use 'horizontalBar' type.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shenriksen4 picture shenriksen4  路  3Comments

raychenfj picture raychenfj  路  3Comments

hggeorgiev picture hggeorgiev  路  4Comments

egervari picture egervari  路  4Comments

sarn3792 picture sarn3792  路  4Comments