Adapter
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");
});
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: am4core.Adapter */Inheritance
Adapter does not extend any other symbol.
Adapter is not extended by any other symbol.
Properties
eventsType
EventDispatcher<{ inserted:object, removed:object}>Event dispatcher.
objectType
TargetHolds an object reference this Adapter is for.
Methods
add(key:Key,
callback: (this:C, value:T[""], target:Target, key:Key) =>T[""],
priority:number,
scope?:C)Returns
voidAdds 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
fillvalue is requested from the Pie series, allowing it to override the default using custom code and any fuzzy logic.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
priorityvalue.The heigher the
priority, the later in the game adapter will be applied.apply(key:Key,
value:T[""])Returns
T[""]Passes the input value through all the callbacks for the defined
key.clear()Returns
voidClears all callbacks from this Adapter.
constructor(c:Target)Returns
AdapterConstructor, sets the object referece this Adapter should be used for.
copyFrom(source:this)Returns
voidCopies all the adapter callbacks from
source.disableKey(key:Key,
amount:number)Returns
voidDisable applying adapters for a certain key.
Optionally, can set how many applies to skip before automatically re-enabling the applying.
enableKey(key:Key)Returns
voidEnable applying adapters for a certain key, if it was disabled before by
disableKey().has(key:Key,
callback: (this:C, value:T[""], target:Target, key:Key) =>T[""],
priority:number,
scope?:C)Returns
booleanChecks whether specific adapter is already set.
isEnabled(key:Key)Returns
booleanReturns if there are any enabled adapters set for the specific
key.keys()Returns
Array<string>Returns all adapter keys which are in this adapter.
remove(key:string,
priority?:number)Returns
voidRemoves adapter callbacks for the specific
key.If
priorityis specified, only callbacks for that priority are removed.
Events
Adapter does not have any events.