Type class
Adapter allows adding ordered callback functions and associating them with a string-based key. An Adapter user can then easily invoke those callbacks to apply custom functions on its input, output or intermediate values.
Custom code and plugins can add their own callbacks to modify and enhance core functionality.
See the description of add()
for an example.
Almost any object in amCharts4 has own adapter, accessible with adapter
property.
Any adapters added to it will be applied to that object only.
### Global Adapters If you want to add an adapter which applies to all instances of the same object type, like, for instance all slices in PieSeries, you can use global adapter.
Global adapter is a system-wide instance, accessible via globalAdapter
.
am4core.globalAdapter.addAll<am4charts.IPieSeriesAdapters, am4charts.PieSeries, "fill">(am4charts.PieSeries. "fill", (value, target, key) => { return am4core.color("#005500"); });
am4core.globalAdapter.addAll(am4charts.PieSeries. "fill", (value, target, key) => { return am4core.color("#005500"); });
{@link https://www.amcharts.com/docs/v4/reference/adapter_module/#globalAdapter_property More info}.
Sources
Adapter can be used (imported) via one of the following packages.
/** * -------------------------------------------------------- * Import from: "core.ts" * Use like: am4core.Adapter * -------------------------------------------------------- */ import * as am4core from "@amcharts/amcharts4/core";
/** * -------------------------------------------------------- * Include via: <script src="core.js"></script> * Access items like: am4.Adapter * -------------------------------------------------------- */
Inheritance
Adapter does not extend any other symbol.
Adapter is not extended by any other symbol.
Properties
events # |
Type Event dispatcher. |
---|---|
object # |
Type Holds an object reference this Adapter is for. |
Methods
add( key: ) |
Returns Adds a callback for a specific key. // Override fill color value and make all slices green chart.series.template.adapter.add("fill", (value, target, key) => { return am4core.color("#005500"); }); // Override fill color value and make all slices green chart.series.template.adapter.add("fill", function(value, target, key) { return am4core.color("#005500"); }); { // ... "series": [{ // ... "adapter": { // Override fill color value and make all slices green "fill": function(value, target, key) { return am4core.color("#005500"); } } }] } The above will call user-defined function (adapter) whenever There can be any number of adapters set on one property key. In this case adapters will be applied in daisy-chain fashion. The first adapter in queue will make its transformation. The next one will have the output of the first adapter as a starting value, etc. The order of the adapters are determined either by the order they were added in, or their The heigher the |
---|---|
apply( key: ) |
Returns Passes the input value through all the callbacks for the defined |
clear() |
Returns Clears all callbacks from this Adapter. |
constructor( c: ) |
Returns Constructor, sets the object referece this Adapter should be used for. |
copyFrom( source: ) |
Returns Copies all the adapter callbacks from |
disableKey( key: ) |
Returns Disable applying adapters for a certain key. Optionally, can set how many applies to skip before automatically re-enabling the applying. |
enableKey( key: ) |
Returns Enable applying adapters for a certain key, if it was disabled before by |
has( key: ) |
Returns Checks whether specific adapter is already set. |
isEnabled( key: ) |
Returns Returns if there are any enabled adapters set for the specific |
keys() |
Returns Returns all adapter keys which are in this adapter. |
remove( key: ) |
Returns Removes adapter callbacks for the specific If @todo Implement |
Events
Adapter does not have any events.
Adapters
Adapter does not have any adapters.