Skip to content

Commit c793a5c

Browse files
authored
Customization: Basic chart styling (ChartsCSS#39)
* Update config.js * Update 3d-effects.md * Create basic-styling.md * Update README.md * Update usage.md
1 parent 6543284 commit c793a5c

File tree

5 files changed

+120
-14
lines changed

5 files changed

+120
-14
lines changed

src/.vuepress/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ module.exports = {
123123
collapsable: false,
124124
sidebarDepth: -1,
125125
children: [
126+
'/customization/basic-styling',
126127
'/customization/3d-effects',
127128
'/customization/motion-effects',
128129
'/customization/animations',

src/customization/3d-effects.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
permalink: /customization/3d-effects/
3-
prev: ../
43
---
54

65
# 3D Effects

src/customization/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
prev: ../charts/mixed
3-
next: ./3d-effects
3+
next: ./basic-styling
44
---
55

66
# Customization
@@ -9,7 +9,7 @@ One of the key features in **Charts.css** is the ability to **_customize visibil
99

1010
## Custom Styling
1111

12-
To add custom CSS simply add an `id` attribute to the `<table>` tag:
12+
To add custom CSS simply add an `id` attribute to the `<table>` element:
1313

1414
```html
1515
<table id="my-chart" class="charts-css bar|column|area|line ...">
@@ -47,12 +47,12 @@ We recommend adding the chart type to your selector. This way the custom style w
4747

4848
```css
4949
/* Customize only bar charts */
50-
#my-chart.bar {
50+
#my-chart > table.bar {
5151
...
5252
}
5353

54-
/* Customize only pie charts */
55-
#my-chart.pie {
54+
/* Customize only column charts */
55+
#my-chart > table.column {
5656
...
5757
}
5858
```
@@ -61,10 +61,11 @@ This is important because each chart type has its own structure and layout. You
6161

6262
## Basic Examples
6363

64-
There are many ways to customize the framework. We prepared some basic examples to get you started, covering three topics.
64+
There are many ways to customize the framework. We prepared some basic examples to get you started, covering the following topics.
6565

66+
* [Basic Styling](/customization/basic-styling/)
6667
* [3D Effects](/customization/3d-effects/)
6768
* [Motion Effects](/customization/motion-effects/)
6869
* [Animations](/customization/animations/)
6970

70-
have a beautiful design? Create a codepen and share with the community!
71+
Have a beautiful design? Create a codepen and share with the community!

src/customization/basic-styling.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
permalink: /customization/basic-styling/
3+
prev: ../
4+
---
5+
6+
# Basic Styling
7+
8+
Charts are styled using regular CSS rules. You can apply custom styles on any HTML element or [chart layer](../docs/anatomy/) inside the `<table>` element.
9+
10+
## Style Specific Elements
11+
12+
To style specific elements, use any method supported by CSS.
13+
14+
### CSS Selectors
15+
16+
Use CSS `:nth-of-type()` pseudo-class to match the nth data CSS based on the position among siblings.
17+
18+
```html
19+
<tbody>
20+
<tr>
21+
<td> 20 </td>
22+
</tr>
23+
<tr>
24+
<td> 40 </td>
25+
</tr>
26+
<tr>
27+
<td> 60 </td>
28+
</tr>
29+
<tbody>
30+
```
31+
32+
```css
33+
#my-chart tbody tr:nth-of-type(2) td {
34+
font-weight: bold;
35+
}
36+
```
37+
38+
### CSS Classes
39+
40+
Use custom classes on the element you want to style, and apply custom styles only on that CSS class.
41+
42+
```html
43+
<tr>
44+
<td> 20 </td>
45+
<td> 40 </td>
46+
<td> 60 </td>
47+
<td> 80 </td>
48+
<td class="highlight"> 100 </td>
49+
</tr>
50+
```
51+
52+
```css
53+
.highlight {
54+
font-weight: bold;
55+
}
56+
```
57+
58+
## Style Chart Elements
59+
60+
To style specific chart elements or layers, use one of the HTML tag - `<caption>`, `<tbody>`, `<tr>`, `<th>` or `<td>`.
61+
62+
### Colors
63+
64+
To control the color of different elements, simply use element selector.
65+
66+
```css
67+
/* Heading */
68+
#my-chart caption {
69+
color: red;
70+
}
71+
72+
/* Labels */
73+
#my-chart tbody th {
74+
color: green;
75+
}
76+
77+
/* Data */
78+
#my-chart tbody td {
79+
color: blue;
80+
}
81+
```
82+
83+
### Backgrounds
84+
85+
To control the backgrounds of different elements, use one of the following selectors.
86+
87+
```css
88+
/* Heading */
89+
#my-chart caption {
90+
background-color: hotpink;
91+
color: white;
92+
}
93+
94+
/* Chart */
95+
#my-chart tbody {
96+
background-color: beige;
97+
color: black;
98+
}
99+
100+
/* Labels */
101+
#my-chart tbody th {
102+
background-color: deepskyblue;
103+
color: blue;
104+
}
105+
```

src/docs/usage.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ This is an expected behaviour. Search engines and screen readers should consume
174174

175175
## Charts.css Utility Classes
176176

177-
To transform the HTML table to a chart, the framework offers several [chart types](/charts/) and [components](/components/). To apply any of them, simple add the relevant CSS class to the table.
177+
To transform the HTML table to a chart, the framework offers several [chart types](/charts/) and [components](/components/). To apply any of them, simply add the relevant CSS class to the table.
178178

179179
### General Class
180180

@@ -218,9 +218,9 @@ If the class becomes longer then expected and unreadable, use the [class groupin
218218

219219
The biggest advantage this framework has to offer is the ability to [customize](/customization/) visibility using CSS. Select any HTML element inside the `<table>` and add your own CSS rules.
220220

221-
Use either an `id` or a `class` for your custom styles. In any case, you need to know basic concepts like CSS specificity, and know when one rule overrides the other.
221+
Use either an `id` or a `class` attribute for your custom styles. In any case, you need to know basic concepts like CSS specificity, and know when one rule overrides the other.
222222

223-
The `id` can be applied to the `<table>` element:
223+
The `id` attribute can be applied to the `<table>` element:
224224

225225
```html{1}
226226
<table class="charts-css bar ..." id="my-chart">
@@ -234,7 +234,7 @@ The `id` can be applied to the `<table>` element:
234234
}
235235
```
236236

237-
Or to the wrapper element:
237+
Or add the `id` attribute to the wrapper element:
238238

239239
```html{1}
240240
<div id="my-chart">
@@ -247,9 +247,9 @@ Or to the wrapper element:
247247
```
248248

249249
```css
250-
#my-chart .bar {
250+
#my-chart > .bar {
251251
...
252252
}
253253
```
254254

255-
To demonstrate how easy it is to add custom styling, check out our basic examples for creating [3D effects](/customization/3d-effects/), [motion effects](/customization/motion-effects/) and [animations](/customization/animations/). It's amazing what you can do with a few lines of CSS.
255+
To demonstrate how easy it is to add custom styling, check out our examples for applying [basic styles](/customization/basic-styling/), [3D effects](/customization/3d-effects/), [motion effects](/customization/motion-effects/) and [animations](/customization/animations/). It's amazing what you can do with a few lines of CSS.

0 commit comments

Comments
 (0)