It's often needed to update the chart on demand. For example, you may wish to update a chart when a certain event happens. As a developer, you are responsible of telling Chartisan when it needs to update the chart. You may, for example, set the chart to update when a refresh button is clicked, or when a websocket event comes in. To update a chart you may use the
update() method on the chartisan instance. This method allows additional information to be passed to it in order to determine how the update needs to be performed.
This destroys the chart, and re-creates it again, fetching the data again or building it again with the new data. Chartisan will already show a loading spinner and wait till it's ready again to be shown. This is very usefull when your new data is completly different from the previous one, for instance, you may be filtering the chart to the given X days, the new chart data may have so many new points or simply remove too many to be considered similar data. If that is not the case and you have similar data, consider using the background update.
Sometimes, your chart data is very similar, there might be some value changes at some points but those cases can avoid re-building the whole chart for simple changes. Background updates allow to update the chart in the background, without any visual indication to the user that the chart is being updated. When the new data is available (it has been fetched, or resolved in the front-end) the chart will update the datasets and data points acordingly. This is done by the selected library. Chartisan tries to animate this change for a much better UX.
Background updates do not destroy the current chart instance, making it more performant as well. Keep in mind that if the new data is very different than the previous it might look odd and it would be better to use a regular update.
Sometimes you wish to update how the HTTP request is performed. For example, you may wish to change the URL where the request will be performed or append some query parameters in order to fetch different data. For example you may want to get the data between two dates and those could be specified in the query parameter of the URL. If you want to allow the user to define those two dates, the request URL would need to change depending on those selected dates. Another common scenario is the fact that you may need to include additional authentication headers to the HTTP request. Therefore, Chartisan allows to modify how the HTTP request is performed by using two properties on the
update() method. The first method allows modifying the URL of the request by setting a new URL to perform the fetch at, simply set the
url property with the new URL. The second property called
options will be directly passed to the
fetch() function as the second parameter. This allows modifying how the request is performed at a deeper level by having total control of how the HTTP request is performed and allows for instance, appending headers or changing the request method.
This should cover almost all your needs when updating charts regarding to how the HTTP request is performed. Keep in mind that if you're using static data without any back-end, those settings will be ignored.