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
Bars are cool. They come in two flavors: [BarY](#BarY) for vertical bars (columns) and [BarX](#BarX) for horizontal bars.
11
-
12
-
Here's a very simple bar chart:
10
+
Bars are useful to show quantitative data for different categories. They come in two flavors: [BarX](#BarX) for horizontal bars (y axis requires band scale) and [BarY](#BarY) for vertical bars aka. columns (x axis requires band scale).
SveltePlot automatically infers a band scale for the y axis in the above example. but since our data is missing a value for 2023, the value `"2023"` is entirely missing from the band scale domain. We could fix this by passing the domain value manually, or by using the `interval` option of the y axis:
40
+
41
+
```svelte live
42
+
<script>
43
+
import { Plot, BarX, RuleX } from 'svelteplot';
44
+
const data = [
45
+
{ year: 2019, value: 20 },
46
+
{ year: 2020, value: 24 },
47
+
{ year: 2021, value: 32 },
48
+
{ year: 2022, value: 39 },
49
+
{ year: 2024, value: 56 }
50
+
];
51
+
</script>
52
+
53
+
<Plot y={{ interval: 1 }}>
54
+
<BarX {data} x="value" y="year" />
55
+
<RuleX data={[0]} />
56
+
</Plot>
57
+
```
58
+
59
+
```
60
+
<Plot y={{ interval: 1 }}>
61
+
<BarX {data} x="value" y="year" />
32
62
<RuleX data={[0]} />
33
63
</Plot>
34
64
```
35
65
36
-
You can create stacked bar charts by defining a fill channel which will be used for grouping the series by the implicit [stack transform](/transforms/stack):
66
+
You can create stacked bar charts by defining a fill channel which will be used for grouping the series by the implicit [stack transform](/transforms/stack). In the following example we're first grouping the penguins dataset by island to then stack them by species:
37
67
38
68
```svelte live
39
69
<script lang="ts">
@@ -82,7 +112,7 @@ You can create stacked bar charts by defining a fill channel which will be used
82
112
83
113
The `BarX` component renders horizontal bars, typically used with a band scale on the y-axis. This is ideal for categorical data where the categories run along the y-axis, and the values extend horizontally.
84
114
85
-
### Properties
115
+
**Properties**
86
116
87
117
-**data** - The data array to visualize
88
118
-**x** - Value accessor for the x channel (length of bar)
@@ -99,35 +129,11 @@ The `BarX` component renders horizontal bars, typically used with a band scale o
99
129
100
130
Additionally, `BarX` supports all common styling properties like `fill`, `stroke`, `opacity`, etc.
101
131
102
-
### Example
103
-
104
-
```svelte
105
-
<Plot y={{ type: 'band' }} x={{ grid: true }}>
106
-
<BarX
107
-
data={myData}
108
-
y="category"
109
-
x="value"
110
-
fill="steelblue" />
111
-
</Plot>
112
-
```
113
-
114
-
For stacked bar charts, provide a `fill` channel that will be used for grouping the series:
The `BarY` component renders vertical bars (columns), typically used with a band scale on the x-axis. This is ideal for categorical data where the categories run along the x-axis, and the values extend vertically.
129
135
130
-
### Properties
136
+
**Properties**
131
137
132
138
-**data** - The data array to visualize
133
139
-**x** - Value accessor for the x channel (position on the category axis)
@@ -145,45 +151,8 @@ The `BarY` component renders vertical bars (columns), typically used with a band
145
151
146
152
Additionally, `BarY` supports all common styling properties like `fill`, `stroke`, `opacity`, etc.
0 commit comments