As explained in the general walk-through, hooks allow to customize how you chart looks like, but hooks allows for much more than that. When Chartisan creates a new chart, hooks are able to append or modify data that is passed to the selected library. This means you technically have the potential use the selected library at its best. This normally means modifying some interal chart configuration like datasets, labels, legends, etc. However, it also used for chart customization. Chartisan is smart enough to create the internal configuration of the selected library based on the datasets and labels sent by the server or set on the
data property. However, you are free to extend or modify it before it's passed to the selected library. This is a dangerous feature, since you can break the chart if the options passed are not correctly formatted but it's also a way to have a non-limiting abstraction on the top of it. Hook order is important, as the chart configuration is piped from one to another in the creation order.
Chartisan provides built-in hooks that allow creating new hooks or use some of the pre-built hooks available for your chosen library. Keep in mind this is not a limitation, but a way to avoid manually creating new hooks in case some pre-built one is already available. Creating a hooks instance can be done by calling it's constructor as follows.
This creates a raw instance containing no hooks at all. You can, from there, append custom hooks or use some pre-built ones.
To append a new hook, you can use the
custom() method. This method accepts a function that is given some hook parameters. This includes the current chart configuration, the raw server data and a merge function. This function must always return the new chart configuration.
It's very common that you just want to add or modify some of the configuration of the chart, needing to use the merge function. This is so common that Chartisan provides another method for simple cases that merges your options to the chart without boilerplate.
options() method can simplify your chart configuration by a lot. It's recommended to use it instead of the
custom() method when possible.
There are cases where you may want to re-use some previously created hooks among your application. There are situations where you may want to merge two or more hook instances into a single one to be used by the chart. You can use the
merge() method to append previously created hooks into the current instance.
You can use this method to abstract some common hooks found in your application and re-use them at your need.
The following represents the API of the selected library. Please make sure you selected the library you want to use on the preferences menu.
This is the documentation generated by typescript. Feel free to explore it on the repository of the selected library.