Chartjs-Dynamically set chart type with Angular Chart?

2👍

So after a great deal of frustration trying to figure out why the scoped variable wasn’t mutating the DOM how I’d wanted, I returned to the AngularChartJS documentation and found really rather a simple solution.

If you set the class of the canvas to chart chart-base, it’s possible to set the chart type by simply providing the canvas with a chart-type attribute and setting it to whatever the scoped variable is called. In my case, this was the markup I ended up with to reach the outcome that I needed where, of course, chart_type is the variable held in the controller.

<canvas class="chart chart-base" chart-type="chart_type" chart-data="data" chart-labels="labels" chart-series="series" chart-options="options" chart-dataset-override="datasetOverride" chart-click="onClick"></canvas>

Leave a comment