Skip to content

Commit cefdb10

Browse files
authored
Added documentation for plugins
1 parent 03132d1 commit cefdb10

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

docs/documentation/docs/controls/ChartControl.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ For example:
205205
## Implementation
206206

207207
### ChartControl Properties
208-
The ChartControl can be configured with the following properties:
208+
The ChartControl control can be configured with the following properties:
209209

210210
| Property | Type | Required | Description |
211211
| ---- | ---- | ---- | ---- |
@@ -221,6 +221,21 @@ The ChartControl can be configured with the following properties:
221221
| onHover | (chart: Chart, event: MouseEvent, activeElements: Array<{}>) => void | no | Optional callback method that get called when a user hovers the chart |
222222
| onResize | (chart: Chart, newSize: ChartSize) => void | no | Optional callback method that get called when the window containing the ChartXontrol resizes |
223223

224+
You can call the following methods to interact with the chart after it has been initialized:
225+
226+
| Method | Type | Description |
227+
| ---- | ---- | ---- |
228+
| clear | void | Will clear the chart canvas. Used extensively internally between animation frames, but you might find it useful. |
229+
| getCanvas | () => HTMLCanvasElement | Return the canvass element that contains the chart |
230+
| getChart | () => Chart | Returns the Chart.js instance |
231+
| getDatasetAtEvent | (e: MouseEvent) => Array<{}> | Looks for the element under the event point, then returns all elements from that dataset. This is used internally for 'dataset' mode highlighting |
232+
| getElementAtEvent | (e: MouseEvent) => {} | Calling getElementAtEvent(event) passing an argument of an event will return the single element at the event position. For example, you can use with `onClick` event handlers. |
233+
| getElementsAtEvent | (e: MouseEvent) => Array<{}> | Looks for the element under the event point, then returns all elements at the same data index. This is used internally for 'label' mode highlighting. Calling `getElementsAtEvent(event)` passing an argument of an event will return the point elements that are at that the same position of that event. |
234+
| renderChart | (config: {}) => void | Triggers a redraw of all chart elements. Note, this does not update elements for new data. Use .update() in that case. |
235+
| stop | void | Use this to stop any current animation loop. This will pause the chart during any current animation frame. |
236+
| toBase64Image | () => string | Returns a base 64 encoded string of the chart in it's current state. |
237+
| update | (config?: number \| boolean \| string) => void | Triggers an update of the chart. This can be safely called after updating the data object. This will update all scales, legends, and then re-render the chart. |
238+
224239
### IChartAccessibility
225240

226241
The `IChartAccessibility` interface implements the following properties:
@@ -271,7 +286,34 @@ Defines the type of chart that will be rendered. For more information what data
271286
| Radar | [radar](https://www.chartjs.org/docs/latest/charts/radar.html) | Radar chart |
272287
| Scatter | [scatter](https://www.chartjs.org/docs/latest/charts/scatter.html) | Scatter graph |
273288

289+
### IChartPlugin
290+
291+
The easiest way to customize a chart is to use the plugin functionality provided by Chart.js. In order to use a plugin, simply pass an array of objects that implement the `IChartPlugin` interface to the `plugins` property of the ChartControl.
274292

293+
If a hook is listed as cancellable, you can return `false` to cancel the event.
294+
295+
| Property | Type | Required | Description |
296+
| ---- | ---- | ---- | ---- |
297+
| afterDatasetsDraw | (chartInstance: Chart, easing: string, options?: {}) => void | no | Called after the datasets are drawn but after scales are drawn. |
298+
| afterDatasetUpdate | (chartInstance: Chart, options?: {}) => void | no | Called after a dataset was updated. |
299+
| afterDraw | (chartInstance: Chart, easing: string, options?: {}) => void | no | Called after an animation frame was drawn. |
300+
| afterEvent | (chartInstance: Chart, event: Event, options?: {}) => void | no | Called after an event occurs on the chart. |
301+
| afterInit | (chartInstance: Chart, options?: {}) => void | no | Called after a chart initializes |
302+
| afterLayout | (chartInstance: Chart, options?: {}) => void | no | Called after the chart layout was rendered. |
303+
| afterRender | (chartInstance: Chart, options?: {}) => void | no | Called after a rander. |
304+
| afterTooltipDraw | (chartInstance: Chart, tooltipData?: {}, options?: {}) => void | no | Called after drawing the `tooltip`. Note that this hook will not be called if the tooltip drawing has been previously cancelled. |
305+
| afterUpdate | (chartInstance: Chart, options?: {}) => void | no | Called after a chart updates |
306+
| beforeDatasetsDraw | (chartInstance: Chart, easing: string, options?: {}) => void | no | Called before the datasets are drawn but after scales are drawn. Cancellable. |
307+
| beforeDatasetUpdate| (chartInstance: Chart, options?: {}) => void | no | Called before a dataset is updated. Cancellable. |
308+
| beforeDraw | (chartInstance: Chart, easing: string, options?: {}) => void | no | Called before an animation frame is drawn. |
309+
| beforeEvent | (chartInstance: Chart, event: Event, options?: {}) => void | no | Called when an event occurs on the chart. Cancellable. |
310+
| beforeInit | (chartInstance: Chart, options?: {}) => void | no | Called before a chart initializes |
311+
| beforeLayout | (chartInstance: Chart, options?: {}) => void | no | Called before rendering the chart's layout. Cancellable. |
312+
| beforeRender | (chartInstance: Chart, options?: {}) => void | no | Called at the start of a render. It is only called once, even if the animation will run for a number of frames. Use beforeDraw or afterDraw to do something on each animation frame. Cancellable. |
313+
| beforeTooltipDraw | (chartInstance: Chart, tooltipData?: {}, options?: {}) => void | no | Called before drawing the `tooltip`. Cancellable. If it returns `false`, tooltip drawing is cancelled until another `render` is triggered. |
314+
| beforeUpdate | (chartInstance: Chart, options?: {}) => void | no | Called before updating the chart. Cancellable. |
315+
| destroy | (chartInstance: Chart) => void | no | Called when a chart is destroyed. |
316+
| resize | (chartInstance: Chart, newChartSize: Chart.ChartSize, options?: {}) => void | no | Called when a chart resizes. Cancellable. |
275317

276318

277319
![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/ChartControl)

0 commit comments

Comments
 (0)