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
As of version 1.0.0, the new best practice is to add a wrapper element to all your charts.
36
+
Although a wrapper div is not required, as of version 1.0.0 the new best practice is to add a wrapper element to all charts.
35
37
36
-
## Data Table
38
+
## Customizing the Wrapper
37
39
38
-
To turn the data table into a chart, you need to add the `.charts-css` class to the `<table>` element itself:
39
-
40
-
```html
41
-
<tableclass="charts-css">
42
-
...
43
-
</table>
44
-
```
45
-
46
-
This class will reset, contain, pad and remove all other styles. But it won't transform the data table into a chart, yet.
47
-
48
-
## Chart Classes
49
-
50
-
To visualize the data you need to decide which [chart type](/charts/) you want to use and add the chart class after the main class. For example, to display a column chart we need to add the `.column` class.
51
-
52
-
```html
53
-
<tableclass="charts-css column">
54
-
...
55
-
</table>
56
-
```
57
-
58
-
To create a bar chart you need to add the `.bar` class.
59
-
60
-
```html
61
-
<tableclass="charts-css bar">
62
-
...
63
-
</table>
64
-
```
65
-
66
-
Only then add some inner components like [axes](/components/axes), [tooltips](/components/tooltips) etc.
67
-
68
-
```html
69
-
<tableclass="charts-css bar show-primary-axis show-4-secondary-axes show-data-axes">
70
-
...
71
-
</table>
72
-
```
73
-
74
-
## Customizing the Chart
75
-
76
-
A simple customization will include the `height` and `width` of the chart.
40
+
A simple customization will include custom width for the wrapper.
77
41
78
42
```css
79
-
#my-chart.bar{
80
-
height: 300px;
81
-
width: 600px;
43
+
#my-chart {
44
+
width: 100%;
45
+
max-width: 300px;
82
46
margin: 0auto;
83
47
}
84
48
```
85
49
86
-
In addition, you can add any CSS to style the chart. For example, add your brand logo in the background.
50
+
To customize chart components, use descendant combinators with the component selector.
87
51
88
52
```css
89
-
#my-chart.bar {
90
-
background-image: url(path/to/your/logo.svg);
91
-
background-repeat: no-repeat;
92
-
background-position: centercenter;
93
-
background-size: 100px100px;
53
+
#my-chart.legend {
54
+
...
55
+
}
56
+
#my-chart.bar,
57
+
#my-chart.column,
58
+
#my-chart.area,
59
+
#my-chart.line,
60
+
#my-chart.pie {
61
+
...
94
62
}
95
63
```
96
64
@@ -99,19 +67,67 @@ In addition, you can add any CSS to style the chart. For example, add your brand
99
67
Media queries can be used to set different dimensions for different screen sizes.
100
68
101
69
```css
102
-
#my-chart.bar{
70
+
#my-chart {
103
71
max-width: 600px;
104
72
}
105
73
106
74
@media (min-width: 600px) {
107
-
#my-chart.bar{
75
+
#my-chart {
108
76
max-width: 800px;
109
77
}
110
78
}
111
79
112
80
@media (min-width: 1000px) {
113
-
#my-chart.bar{
81
+
#my-chart {
114
82
max-width: 1000px;
115
83
}
116
84
}
117
85
```
86
+
87
+
Alternatively, container queries can be used to style based on the size and layout of specific elements on the page. For example, you can position the legend and the chart side-by-side, and under a certain width to position them below each other.
88
+
89
+
```css
90
+
#my-chart {
91
+
container-name: chart;
92
+
container-type: inline-size;
93
+
}
94
+
95
+
#my-chart {
96
+
display: flex;
97
+
flex-direction: row;
98
+
}
99
+
100
+
@container charts (max-width: 600px) {
101
+
#my-chart {
102
+
flex-direction: column;
103
+
}
104
+
}
105
+
```
106
+
107
+
## Additional Elements
108
+
109
+
Add your own elements to the chart and style them accordingly.
110
+
111
+
```html
112
+
<divid="my-chart">
113
+
114
+
<tableclass="charts-css bar|column|area|line">
115
+
...
116
+
</table>
117
+
118
+
<ulclass="charts-css legend">
119
+
...
120
+
</ul>
121
+
122
+
<divclass="my-chart-element">
123
+
...
124
+
</div>
125
+
126
+
<divclass="another-custom-element">
127
+
...
128
+
</div>
129
+
130
+
</div>
131
+
```
132
+
133
+
For a concrete example, see how easy it is to add [axes titles](./axes/#axis-title) with custom HTML elements and some CSS magic.
0 commit comments