Accepted answer

the fix

  • destroy the old chart (to remove event listeners and clear the canvas)
  • make a deep copy of the config object
  • change the type of the copy
  • pass the copy instead of the original object.

here is a working jsfiddle example

example overview:

var temp = jquery.extend(true, {}, config);
temp.type = 'bar'; // the new chart type
mychart = new chart(ctx, temp);

note: using version 2.0.1 of chart.js

why this works

chart.js modifies the config object you pass in. because of that you can not just change 'config.type'. you could go into the modified object and change everything to the type you want, but it is much easier to just save the original config object.


in chartjs 3, :

var options = // your options.
var data = { }; // deep copy of the data
var ctx = document.getelementbyid('mychart_id').getcontext('2d');


/// modify ctx or data if you need to.

mychart = new chart(ctx, {
        type: chart_type,
        data: data

chart.options = options;


in chart.js 3.8.0 you con do it like this:

let chart = new chart(ctx, {
  type: "line",
  data: {
    // ...
  options: {
    // ...

chart.config.type = "bar";

you can also change data and options this way

chart.js docs on updating:


the alternate solution can be as simple as creating both the charts in separate div elements. then as per your condition just make one visible and hide other in the javascript. this should serve the purpose you may have for changing the chart type for your requirement.


in chartjs, the chart type can also be changed easily like chart data. following example might be helpful

        my_chart.type = 'bar';


no need to destroy and re-create, you just have to change the type from the chart's config variable then update the chart.

var chartcfg = {
    type: 'pie',
    data: data

var mychart = new chart(ctx, chartcfg );

function changetobar() {
    chartcfg.type = "bar";


just to follow up that this is now fixed in v.2.1.3, as followed through by

document.getelementbyid('changetoline').onclick = function() {
  mychart = new chart(ctx, {
    type: 'line',
    data: chartdata

confirmed fixed in latest version. check out and press the button under the chart to change it from a bar to a line chart.

Related Query

More Query from same tag