Chart.js: New Chart extending BAR chart doesn't work

Created on 29 Oct 2019  路  3Comments  路  Source: chartjs/Chart.js

Expected Behavior

In the version 2.8.0, creating new chart extending a bar chart, it works.
See the code:

Chart.defaults.derivedBar = Chart.defaults.bar;
var custom = Chart.controllers.bar.extend({
   draw: function(ease) {
          Chart.controllers.bar.prototype.draw.call(this, ease);
   }
});
Chart.controllers.derivedBar = custom;

var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
    type: 'derivedBar',
    data: {
        labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
        datasets: [{
            label: '# of Votes',
            data: [12, 19, 3, 5, 2, 3]
        }]
    }
});

okController

Current Behavior

In the new vesion 2.9.1, new chart is not rendered and completely empty (without any message into log)

bugController

The problem is ONLY for BAR chart (at least on my tests).

Environment

  • Chart.js version: 2.9.1
  • Browser name and version: FF 70.0
support

Most helpful comment

@benmccann Thank you! It works. A hint, if I may. In the doc, about Controllers, I don't find (but I'm getting old and maybe there is....) something like that:

Chart.defaults.global.datasets.derivedBar = Chart.defaults.global.datasets.bar;

All 3 comments

@stockiNail I'm guessing you also need the dataset defaults, which were introduced in 2.9. There's some info in the docs and you can see it being done in the current bar controller source. The reason for this is to better support mixed charts

@benmccann Thank you! It works. A hint, if I may. In the doc, about Controllers, I don't find (but I'm getting old and maybe there is....) something like that:

Chart.defaults.global.datasets.derivedBar = Chart.defaults.global.datasets.bar;

@benmccann honestly in another issue I asked for that (without feedback) what you suggested.

See issue #6482

Thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings