Skip to content

Commit f548b83

Browse files
benmccannetimberg
authored andcommitted
Combine performance docs (#6643)
1 parent 3b790ef commit f548b83

File tree

3 files changed

+82
-78
lines changed

3 files changed

+82
-78
lines changed

docs/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* [Options](general/options.md)
1717
* [Colors](general/colors.md)
1818
* [Fonts](general/fonts.md)
19+
* [Performance](general/performance.md)
1920
* [Configuration](configuration/README.md)
2021
* [Animations](configuration/animations.md)
2122
* [Layout](configuration/layout.md)

docs/charts/line.md

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -216,75 +216,3 @@ var stackedLine = new Chart(ctx, {
216216
}
217217
});
218218
```
219-
220-
## High Performance Line Charts
221-
222-
When charting a lot of data, the chart render time may start to get quite large. In that case, the following strategies can be used to improve performance.
223-
224-
### Data Decimation
225-
226-
Decimating your data will achieve the best results. When there is a lot of data to display on the graph, it doesn't make sense to show tens of thousands of data points on a graph that is only a few hundred pixels wide.
227-
228-
There are many approaches to data decimation and selection of an algorithm will depend on your data and the results you want to achieve. For instance, [min/max](https://digital.ni.com/public.nsf/allkb/F694FFEEA0ACF282862576020075F784) decimation will preserve peaks in your data but could require up to 4 points for each pixel. This type of decimation would work well for a very noisy signal where you need to see data peaks.
229-
230-
### Disable Bezier Curves
231-
232-
If you are drawing lines on your chart, disabling bezier curves will improve render times since drawing a straight line is more performant than a bezier curve.
233-
234-
To disable bezier curves for an entire chart:
235-
236-
```javascript
237-
new Chart(ctx, {
238-
type: 'line',
239-
data: data,
240-
options: {
241-
elements: {
242-
line: {
243-
tension: 0 // disables bezier curves
244-
}
245-
}
246-
}
247-
});
248-
```
249-
250-
### Disable Line Drawing
251-
252-
If you have a lot of data points, it can be more performant to disable rendering of the line for a dataset and only draw points. Doing this means that there is less to draw on the canvas which will improve render performance.
253-
254-
To disable lines:
255-
256-
```javascript
257-
new Chart(ctx, {
258-
type: 'line',
259-
data: {
260-
datasets: [{
261-
showLine: false // disable for a single dataset
262-
}]
263-
},
264-
options: {
265-
showLines: false // disable for all datasets
266-
}
267-
});
268-
```
269-
270-
### Disable Animations
271-
272-
If your charts have long render times, it is a good idea to disable animations. Doing so will mean that the chart needs to only be rendered once during an update instead of multiple times. This will have the effect of reducing CPU usage and improving general page performance.
273-
274-
To disable animations
275-
276-
```javascript
277-
new Chart(ctx, {
278-
type: 'line',
279-
data: data,
280-
options: {
281-
animation: {
282-
duration: 0 // general animation time
283-
},
284-
hover: {
285-
animationDuration: 0 // duration of animations when hovering an item
286-
},
287-
responsiveAnimationDuration: 0 // animation duration after a resize
288-
}
289-
});
290-
```

docs/general/performance.md

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,84 @@
11
# Performance
22

3-
Chart.js charts are rendered on `canvas` elements, which makes rendering quite fast. For large datasets or performance sensitive applications, you may wish to consider the tips below:
3+
Chart.js charts are rendered on `canvas` elements, which makes rendering quite fast. For large datasets or performance sensitive applications, you may wish to consider the tips below.
44

5-
* Set `animation: { duration: 0 }` to disable [animations](../configuration/animations.md).
6-
* [Specify a rotation value](https://www.chartjs.org/docs/latest/axes/cartesian/#tick-configuration) by setting `minRotation` and `maxRotation` to the same value
7-
* For large datasets:
8-
* You may wish to sample your data before providing it to Chart.js. E.g. if you have a data point for each day, you may find it more performant to pass in a data point for each week instead
9-
* Set the [`ticks.sampleSize`](../axes/cartesian/README.md#tick-configuration) option in order to render axes more quickly
5+
## Tick Calculation
6+
7+
### Rotation
8+
9+
[Specify a rotation value](https://www.chartjs.org/docs/latest/axes/cartesian/#tick-configuration) by setting `minRotation` and `maxRotation` to the same value, which avoids the chart from having to automatically determine a value to use.
10+
11+
### Sampling
12+
13+
Set the [`ticks.sampleSize`](../axes/cartesian/README.md#tick-configuration) option. This will determine how large your labels are by looking at only a subset of them in order to render axes more quickly. This works best if there is not a large variance in the size of your labels.
14+
15+
## Disable Animations
16+
17+
If your charts have long render times, it is a good idea to disable animations. Doing so will mean that the chart needs to only be rendered once during an update instead of multiple times. This will have the effect of reducing CPU usage and improving general page performance.
18+
19+
To disable animations
20+
21+
```javascript
22+
new Chart(ctx, {
23+
type: 'line',
24+
data: data,
25+
options: {
26+
animation: {
27+
duration: 0 // general animation time
28+
},
29+
hover: {
30+
animationDuration: 0 // duration of animations when hovering an item
31+
},
32+
responsiveAnimationDuration: 0 // animation duration after a resize
33+
}
34+
});
35+
```
36+
37+
## Data Decimation
38+
39+
Decimating your data will achieve the best results. When there is a lot of data to display on the graph, it doesn't make sense to show tens of thousands of data points on a graph that is only a few hundred pixels wide.
40+
41+
There are many approaches to data decimation and selection of an algorithm will depend on your data and the results you want to achieve. For instance, [min/max](https://digital.ni.com/public.nsf/allkb/F694FFEEA0ACF282862576020075F784) decimation will preserve peaks in your data but could require up to 4 points for each pixel. This type of decimation would work well for a very noisy signal where you need to see data peaks.
42+
43+
44+
## Line Charts
45+
46+
### Disable Bezier Curves
47+
48+
If you are drawing lines on your chart, disabling bezier curves will improve render times since drawing a straight line is more performant than a bezier curve.
49+
50+
To disable bezier curves for an entire chart:
51+
52+
```javascript
53+
new Chart(ctx, {
54+
type: 'line',
55+
data: data,
56+
options: {
57+
elements: {
58+
line: {
59+
tension: 0 // disables bezier curves
60+
}
61+
}
62+
}
63+
});
64+
```
65+
66+
### Disable Line Drawing
67+
68+
If you have a lot of data points, it can be more performant to disable rendering of the line for a dataset and only draw points. Doing this means that there is less to draw on the canvas which will improve render performance.
69+
70+
To disable lines:
71+
72+
```javascript
73+
new Chart(ctx, {
74+
type: 'line',
75+
data: {
76+
datasets: [{
77+
showLine: false // disable for a single dataset
78+
}]
79+
},
80+
options: {
81+
showLines: false // disable for all datasets
82+
}
83+
});
84+
```

0 commit comments

Comments
 (0)