> For the complete documentation index, see [llms.txt](https://antv.gitbook.io/f2/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://antv.gitbook.io/f2/developer/plugin.md).

# Plugin

Plugins are the most efficient way to customize or change the default behavior of a chart.&#x20;

### How to use plugins

1. Global registeration for plugins

   ```javascript
   const plugin1 = { /* plugin implementation */ };
   const plugin2 = { /* plugin implementation */ };
   // Global registeration, plugin will be registered to all the chart plugins
   Chart.plugins.register(plugin1); 
   // Global registeration for multiple plug-in
   Chart.plugins.register([ plugin1, plugin2 ]);
   ```
2. Register for a chart instance

   ```javascript
   const plugin1 = { /* plugin implementation */ };
   const plugin2 = { /* plugin implementation */ };

   // chart1 use "plugin1"
   const chart1 = new Chart({
     plugins: plugin1
   );
   // chart2 use "plugin2"
   const chart2 = new Chart({
     plugins: plugin2
   );
   // chart3 doesn't use "plugin"
   const chart3 = new Chart({});
   ```

### Unregister plugins

Use `Chart.plugins.unregister(plugins)` to unregister a plug-in.

### Clear plugins

Use `Chart.plugins.clear()` to clear all the plugins.

### Get registered plugins

Use `Chart.plugins.getAll()` to get all successfully registered plug-ins.

### How to define plugin

The implementation of a plugin is very simple, all you need to do is define the behaviors of the plugin during the life circle of the chart.&#x20;

```javascript
const plugin = {
    init(chart) {
       // do something when initialize the chart 
    }
};
```

### Available hooks

* `init`: After initialization of the chart
* `beforeGeomDraw`: Before drawing the geometry
* `afterGeomDraw`: After drawing the geometry
* `beforeCanvasDraw`: before drawing the canvas
* `clear`: Clear the chart, remove geometry
* `clearInner`: Clear the layers
* `repaint`: Redraw


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://antv.gitbook.io/f2/developer/plugin.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
