@@ -26,89 +26,67 @@ import { ChartMixin } from './vaadin-chart-mixin.js';
26
26
* There are two ways of configuring your `<vaadin-chart>` element: **HTML API**, **JS API** and **JSON API**.
27
27
* Note that you can make use of all APIs in your element.
28
28
*
29
- * #### Configuring your chart using HTML API
29
+ * #### Using HTML API
30
30
*
31
31
* `vaadin-chart` has a set of attributes to make it easier for you to customize your chart.
32
32
*
33
33
* ```html
34
- * <vaadin-chart title="The chart title" subtitle="The chart subtitle">
35
- * <vaadin-chart-series
36
- * type="column"
37
- * title="The series title"
38
- * values="[10,20,30]">
39
- * </vaadin-chart-series>
40
- * </vaadin-chart>
34
+ * <vaadin-chart title="The chart title" subtitle="The chart subtitle">
35
+ * <vaadin-chart-series
36
+ * type="column"
37
+ * title="The series title"
38
+ * values="[10, 20, 30]"
39
+ * > </vaadin-chart-series>
40
+ * </vaadin-chart>
41
41
* ```
42
42
*
43
43
* > Note that while you can set type for each series individually, for some types, such as `'bar'`, `'gauge'` and `'solidgauge'`, you
44
44
* > have to set it as the default series type on `<vaadin-chart>` in order to work properly.
45
45
*
46
- * #### Configuring your chart using JS API
46
+ * #### Using JS API
47
+ *
48
+ * Use [`configuration`](#/elements/vaadin-chart#property-configuration) property to set chart title, categories and data:
47
49
*
48
- * 1. Set an id for the `<vaadin-chart>` in the template
49
- * ```html
50
- * <vaadin-chart id="mychart"></vaadin-chart>
51
- * ```
52
- * 1. Add a function that uses `configuration` property (JS Api) to set chart title, categories and data
53
- * ```js
54
- * initChartWithJSApi() {
55
- * requestAnimationFrame(() => {
56
- * const configuration = this.$.mychart.configuration;
57
- * configuration.setTitle({ text: 'The chart title' });
58
- * // By default there is one X axis, it is referenced by configuration.xAxis[0].
59
- * configuration.xAxis[0].setCategories(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']);
60
- * configuration.addSeries({
61
- * type: 'column',
62
- * data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
63
- * });
64
- * });
65
- * }
66
- * ```
67
- * 1. Call that function from connectedCallback (when the element is added to a document)
68
50
* ```js
69
- * connectedCallback() {
70
- * super.connectedCallback();
71
- * this.initChartWithJSApi();
72
- * }
51
+ * const chart = document.querySelector('vaadin-chart');
52
+ *
53
+ * // Wait for default configuration to be ready
54
+ * requestAnimationFrame(() => {
55
+ * const configuration = chart.configuration;
56
+ * configuration.setTitle({ text: 'The chart title' });
57
+ * // By default there is one X axis, it is referenced by configuration.xAxis[0].
58
+ * configuration.xAxis[0].setCategories(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']);
59
+ * configuration.addSeries({
60
+ * type: 'column',
61
+ * data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
62
+ * });
63
+ * });
73
64
* ```
74
65
*
75
- * #### Configuring your chart using JS JSON API
66
+ * #### Using JS JSON API
76
67
*
77
- * JS JSON API is a simple alternative to the JS API.
68
+ * Use [`updateConfiguration`](#/elements/vaadin-chart#method-updateConfiguration) method to set chart title, categories and data:
78
69
*
79
- * 1. Set an id for the `<vaadin-chart>` in the template
80
- * ```html
81
- * <vaadin-chart id="mychart"></vaadin-chart>
82
- * ```
83
- * 1. Add a function that uses `updateConfiguration` method (JS JSON Api) to set chart title, categories and data
84
- * ```js
85
- * initChartWithJSJSONApi() {
86
- * this.$.mychart.updateConfiguration({
87
- * title: {
88
- * text: 'The chart title'
89
- * },
90
- * subtitle: {
91
- * text: 'Subtitle'
92
- * },
93
- * xAxis: {
94
- * categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
95
- * },
96
- * series: [{
97
- * type: 'column',
98
- * data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
99
- * }]
100
- * });
101
- * }
102
- * ```
103
- * 1. Call that function from connectedCallback (when the element is added to a document)
104
70
* ```js
105
- * connectedCallback() {
106
- * super.connectedCallback();
107
- * this.initChartWithJSJSONApi();
108
- * }
71
+ * const chart = document.querySelector('vaadin-chart');
72
+ * chart.updateConfiguration({
73
+ * title: {
74
+ * text: 'The chart title'
75
+ * },
76
+ * subtitle: {
77
+ * text: 'Subtitle'
78
+ * },
79
+ * xAxis: {
80
+ * categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
81
+ * },
82
+ * series: [{
83
+ * type: 'column',
84
+ * data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
85
+ * }]
86
+ * });
109
87
* ```
110
88
*
111
- * It should be noted that chart style customization cannot be done via the JS or JSON API.
89
+ * **Note:** chart style customization cannot be done via the JS or JSON API.
112
90
* Styling properties in the JSON configuration will be ignored. The following section discusses chart styling.
113
91
*
114
92
* ### CSS Styling
0 commit comments