[Chartjs]-What is the order in which the hooks (plugins) of Chart.js are executed?

13👍

I found the internal documentation of each of the hooks in the code (see Below for a prettified version). Not quite the order, but it can help figuring it out.

Note that some hooks have the same name but they differ in the parameters (you can check those directly in the code:

  • beforeInit: Called before initializing chart.
  • afterInit: Called after chart has been initialized and before the first update.
  • beforeUpdate: Called before updating chart. If any plugin returns false, the update is cancelled (and thus subsequent render(s)) until another update is triggered.
  • afterUpdate: Called after chart has been updated and before rendering. Note that this hook will not be called if the chart update has been previously cancelled.
  • beforeDatasetsUpdate: Called before updating the chart datasets. If any plugin returns false, the datasets update is cancelled until another update is triggered. @since version 2.1.5
  • afterDatasetsUpdate: Called after the chart datasets have been updated. Note that this hook will not be called if the datasets update has been previously cancelled.
  • beforeDatasetUpdate: Called before updating the chart dataset at the given args.index. If any plugin returns false, the datasets update is cancelled until another update is triggered.
  • afterDatasetUpdate: Called after the chart datasets at the given args.index has been updated. Note that this hook will not be called if the datasets update has been previously cancelled.
  • beforeLayout: Called before laying out chart. If any plugin returns false, the layout update is cancelled until another update is triggered.
  • afterLayout: Called after the chart has been layed out. Note that this hook will not be called if the layout update has been previously cancelled.
  • beforeRender: Called before rendering chart. If any plugin returns false, the rendering is cancelled until another render is triggered.
  • afterRender: Called after the chart has been fully rendered (and animation completed). Note that this hook will not be called if the rendering has been previously cancelled.
  • beforeDraw: Called before drawing chart at every animation frame specified by the given easing value. If any plugin returns false, the frame drawing is cancelled until another render is triggered.
  • afterDraw: Called after the chart has been drawn for the specific easing value. Note that this hook will not be called if the drawing has been previously cancelled.
  • beforeDatasetsDraw: Called before drawing the chart datasets. If any plugin returns false, the datasets drawing is cancelled until another render is triggered.
  • afterDatasetsDraw: Called after the chart datasets have been drawn. Note that this hook will not be called if the datasets drawing has been previously cancelled.
  • beforeDatasetDraw: Called before drawing the chart dataset at the given args.index (datasets are drawn in the reverse order). If any plugin returns false, the datasets drawing is cancelled until another render is triggered.
  • afterDatasetDraw: Called after the chart datasets at the given args.index have been drawn (datasets are drawn in the reverse order). Note that this hook will not be called if the datasets drawing has been previously cancelled.
  • beforeTooltipDraw: Called before drawing the tooltip. If any plugin returns false, the tooltip drawing is cancelled until another render is triggered.
  • afterTooltipDraw: Called after drawing the tooltip. Note that this hook will not be called if the tooltip drawing has been previously cancelled.
  • beforeEvent: Called before processing the specified event. If any plugin returns false, the event will be discarded.
  • afterEvent: Called after the event has been consumed. Note that this hook will not be called if the event has been previously discarded.
  • resize: Called after the chart as been resized.
  • destroy: Called after the chart as been destroyed.

Leave a comment