Scrollable Bars
When displaying many data points, vertical scrolling keeps the chart readable while showing all data. The x-axis stays fixed at the bottom using ContentPlaceholderScope and putInto.
<div controller={PageController}>
<Legend />
<ContentPlaceholderScope name="xAxis">
<div style="border: 1px dashed #ddd">
<div style="overflow-y: auto; max-height: 400px; margin-top: 16px">
<Svg
style={{
width: "100%",
height: expr(m.data, (data) => (data?.length ?? 0) * 25),
}}
>
<Chart
offset="1 -20 0 120"
axes={{
x: (
<NumericAxis
snapToTicks={1}
putInto="xAxis"
anchors="0 1 0 0"
offset="-1 0 0 0"
/>
),
y: <CategoryAxis vertical />,
}}
>
<Rectangle fill="white" />
<Gridlines />
<BarGraph
name="2023"
data={m.data}
colorIndex={0}
size={0.3}
offset={-0.15}
xField="v1"
yField="city"
active={m.v1Active}
/>
<BarGraph
name="2024"
data={m.data}
colorIndex={5}
size={0.3}
offset={0.15}
xField="v2"
yField="city"
active={m.v2Active}
/>
</Chart>
</Svg>
</div>
<Svg style="height: 40px; width: 100%; margin-top: -1px">
<ContentPlaceholder name="xAxis" />
</Svg>
</div>
</ContentPlaceholderScope>
</div> 2023
2024
How It Works
- Wrap the chart in a
ContentPlaceholderScopewith a unique name - Set
putIntoon the axis to render it in a separateContentPlaceholder - Use
anchorsandoffsetto position the axis correctly - Calculate Svg height dynamically based on data length
Configuration
| Property | Type | Description |
|---|---|---|
putInto | string | Name of the ContentPlaceholder where the axis should render. |
anchors | string | Bounded object anchors. Use "0 1 0 0" for top-anchored axis. |
offset | string | Bounded object offset to fine-tune axis position. |