You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/configuration/index.md
+32Lines changed: 32 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,38 @@
2
2
3
3
The configuration is used to change how the chart behaves. There are properties to control styling, fonts, the legend, etc.
4
4
5
+
## Cofiguration object structure
6
+
7
+
The top level structure of Chart.js configuration:
8
+
9
+
```javascript
10
+
constconfig= {
11
+
type:'line'
12
+
data: {}
13
+
options: {}
14
+
plugins: []
15
+
}
16
+
```
17
+
18
+
### type
19
+
20
+
Chart type determines the main type of the chart.
21
+
22
+
**note** A dataset can override the `type`, this is how mixed charts are constructed.
23
+
24
+
### data
25
+
26
+
See [Data Structures](../general/data-structures) for details.
27
+
28
+
### options
29
+
30
+
Majority of the documentation talks about these options.
31
+
32
+
### plugins
33
+
34
+
Inline plugins can be included in this array. It is an alternative way of adding plugins for single chart (vs registering the plugin globally).
35
+
More about plugins in the [developers section](../developers/plugins.md).
36
+
5
37
## Global Configuration
6
38
7
39
This concept was introduced in Chart.js 1.0 to keep configuration [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself), and allow for changing options globally across chart types, avoiding the need to specify options for each instance, or the default for a particular chart type.
Copy file name to clipboardExpand all lines: docs/configuration/interactions.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -108,6 +108,8 @@ When configuring the interaction with the graph via `interaction`, `hover` or `t
108
108
109
109
The modes are detailed below and how they behave in conjunction with the `intersect` setting.
110
110
111
+
See how different modes work with the tooltip in [tooltip interactions sample](../samples/tooltip/interactions.md)
112
+
111
113
### point
112
114
113
115
Finds all of the items that intersect the point.
@@ -126,7 +128,7 @@ const chart = new Chart(ctx, {
126
128
127
129
### nearest
128
130
129
-
Gets the items that are at the nearest distance to the point. The nearest item is determined based on the distance to the center of the chart item (point, bar). You can use the `axis` setting to define which directions are used in distance calculation. If `intersect` is true, this is only triggered when the mouse position intersects an item in the graph. This is very useful for combo charts where points are hidden behind bars.
131
+
Gets the items that are at the nearest distance to the point. The nearest item is determined based on the distance to the center of the chart item (point, bar). You can use the `axis` setting to define which coordinates are considered in distance calculation. If `intersect` is true, this is only triggered when the mouse position intersects an item in the graph. This is very useful for combo charts where points are hidden behind bars.
Copy file name to clipboardExpand all lines: docs/general/data-structures.md
+32-7Lines changed: 32 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,24 +8,44 @@ The provides labels can be of the type string or number to be rendered correctly
8
8
## Primitive[]
9
9
10
10
```javascript
11
-
data: [20, 10],
12
-
labels: ['a', 'b']
11
+
type:'bar',
12
+
data: {
13
+
datasets: [{
14
+
data: [20, 10],
15
+
}],
16
+
labels: ['a', 'b']
17
+
}
13
18
```
14
19
15
20
When the `data` is an array of numbers, values from `labels` array at the same index are used for the index axis (`x` for vertical, `y` for horizontal charts).
This is also the internal format used for parsed data. In this mode, parsing can be disabled by specifying `parsing: false` at chart options or dataset. If parsing is disabled, data must be sorted and in the formats the associated chart type and scales use internally.
Copy file name to clipboardExpand all lines: docs/getting-started/index.md
+48-15Lines changed: 48 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,50 @@ Now that we have a canvas we can use, we need to include Chart.js in our page.
18
18
19
19
Now, we can create a chart. We add a script to our page:
20
20
21
+
```html
22
+
<script>
23
+
constlabels= [
24
+
'January',
25
+
'February',
26
+
'March',
27
+
'April',
28
+
'May',
29
+
'June',
30
+
];
31
+
32
+
constdata= {
33
+
labels: labels,
34
+
datasets: [{
35
+
label:'My First dataset',
36
+
backgroundColor:'rgb(255, 99, 132)',
37
+
borderColor:'rgb(255, 99, 132)',
38
+
data: [0, 10, 5, 2, 20, 30, 45],
39
+
}]
40
+
};
41
+
42
+
constconfig= {
43
+
type:'line',
44
+
data: data,
45
+
options: {}
46
+
};
47
+
</script>
48
+
```
49
+
50
+
Finally, render the chart using our configuration:
51
+
52
+
```html
53
+
<script>
54
+
constmyChart=newChart(
55
+
document.getElementById('myChart'),
56
+
config
57
+
);
58
+
</script>
59
+
```
60
+
61
+
It's that easy to get started using Chart.js! From here you can explore the many options that can help you customise your charts with scales, tooltips, labels, colors, custom actions, and much more.
62
+
63
+
Here the sample above is presented with our sample block:
64
+
21
65
```js chart-editor
22
66
// <block:setup:1>
23
67
constlabels= [
@@ -53,21 +97,10 @@ module.exports = {
53
97
};
54
98
```
55
99
56
-
Finally, render the chart using our configuration:
57
-
58
-
```html
59
-
<script>
60
-
// === include 'setup' then 'config' above ===
61
-
62
-
constmyChart=newChart(
63
-
document.getElementById('myChart'),
64
-
config
65
-
);
66
-
</script>
67
-
```
68
-
69
-
It's that easy to get started using Chart.js! From here you can explore the many options that can help you customise your charts with scales, tooltips, labels, colors, custom actions, and much more.
100
+
:::tip Note
101
+
As you can see, some of the boilerplate needed is not visible in our sample blocks, as the samples focus on the configuration options.
102
+
:::
70
103
71
-
All our examples are [available online](/samples/) but you can also download the `Chart.js.zip` archive attached to every [release](https://github.com/chartjs/Chart.js/releases) to experiment with our samples locally from the `/samples` folder.
104
+
All our examples are [available online](/samples/).
72
105
73
106
To run the samples locally you first have to install all the necessary packages using the `npm ci` command, after this you can run `npm run docs:dev` to build the documentation. As soon as the build is done, you can go to [http://localhost:8080/samples/](http://localhost:8080/samples/) to see the samples.
0 commit comments