question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to extend an existing controller

See original GitHub issue

Expected Behavior

I had some problems to extend an existing controller with Chart.js 3.0. Then I have tested the sample into documentation https://www.chartjs.org/docs/master/developers/charts#extending-existing-chart-types, changing a little as following:

Chart.defaults.myline = Chart.defaults.line;
class Custom extends Chart.controllers.line {
    draw() {
        // Call super method first
        super.draw(arguments);
    }
};
Chart.controllers.myline = Custom;
console.log(Chart.controllers);

I was expecting to have a line chart.

Current Behavior

The issue on console is Error: "myline" is not a chart type.. Then I printed the content of Chart.controllers, expecting to find Chart.controllers.myline but was missing.

Additional question

I was using into version 2.9.3 Chart.controllers.line.extend. Can I still use it to extend an existing controller, in version 3.0.0?

Steps to Reproduce

https://codepen.io/stockinail/pen/RwrazGR

Environment

  • Chart.js version: dist/master
  • Browser name and version: FF 77.0.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:17 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
benmccanncommented, Jun 12, 2020

I’m not sure if .extend is still around, but I wouldn’t recommend it. Using an ES6 class with extend is much more natural.

You don’t have to do Chart.controllers.myline = Custom; unless you’ve done a script import, but I’d recommend using npm instead.

Here’s an example chart that uses Chart.js 3: https://github.com/chartjs/chartjs-chart-financial

1reaction
etimbergcommented, Jun 12, 2020

I think this is due to

import * as controllers from './controllers';
...
Chart.controllers = controllers;

I think #7435 would resolve this though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's the recommended way to extend AngularJS controllers?
Perhaps you don't extend a controller but it is possible to extend a controller or make a single controller a mixin of multiple...
Read more >
Fiori Elements: Controller Extension not loaded
I have a Fiori Elements ListReport/ObjectPage app and want to extend the controller of the ObjectPage. Hence I added this to the manifest....
Read more >
Extend on-premises Active Directory to an existing Amazon ...
The following steps guide you through an Active Directory deployment with AWS Launch Wizard after you have launched it from the console for...
Read more >
Extending a Controller in AngularJS - Tushar Ghate
A good way to minimize code duplication is to create a base controller and extend it's behavior in other controllers.
Read more >
lightning component extend existing Apex class
Error while creating component for lightning component quick action [Unable to find action 'getAccount' on the controller of c:Clone]" Please ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found