Axis
Every series on the chart registers themselves to an axis. Axes are used to group series together on a scale. By default, all series use the same axis and place themselves on the chart aligned to a single scale.
Series components accept the axisId
prop that is used to register themselves to an axis. The default axisId
for every series is '0'
.
Single axis Section titled Single axis
Here is a chart with three series that all use the same axis scale:
import { Axis, AxisGrid, AxisLabel, AxisLine, Chart, Line } from 'solid-charts'
const lower = [0, 3, 2, 5, 3, 6, 2]
const middle = [28, 20, 39, 21, 27, 37, 25]
const high = [514, 421, 536, 518, 412, 455, 572]
const data = lower.map((lower, index) => ({
xAxis: `Day ${index + 1}`,
lower,
middle: middle[index],
higher: high[index],
}))
const SingleAxisChart = () => {
return (
<div class="h-62.5 text-sm w-125 m-6">
<Chart data={data}>
<Axis axis="y" position="left">
<AxisLabel />
<AxisGrid class="opacity-20" />
</Axis>
<Axis axis="x" position="bottom" dataKey="xAxis">
<AxisLabel />
<AxisLine />
</Axis>
<Line dataKey="lower" class="stroke-sc-400" stroke-width={3} />
<Line dataKey="middle" class="stroke-sc-400" stroke-width={3} />
<Line dataKey="higher" class="stroke-sc-400" stroke-width={3} />
</Chart>
</div>
)
}
export default SingleAxisChart
While this makes sense for some charts, you might want to split the series up into multiple series to ensure better readability.
Multiple axes Section titled Multiple axes
The example above had one series with much higher values than the others. This can lead to a chart that is hard to read. Lets solve this by creating a seperate axis scale for the series with the high numbers:
import { Axis, AxisGrid, AxisLabel, AxisLine, Chart, Line } from 'solid-charts'
const lower = [0, 3, 2, 5, 3, 6, 2]
const middle = [28, 20, 39, 21, 27, 37, 25]
const high = [514, 421, 536, 518, 412, 455, 572]
const data = lower.map((lower, index) => ({
xAxis: `Day ${index + 1}`,
lower,
middle: middle[index],
higher: high[index],
}))
const MultipleAxisChart = () => {
return (
<div class="h-62.5 text-sm w-125 m-6">
<Chart data={data}>
<Axis axis="y" position="left">
<AxisLabel />
<AxisGrid class="opacity-20" />
</Axis>
<Axis axis="y" position="right" axisId="high" axisRange={[400, 600]}>
<AxisLabel class="text-sc-400" />
</Axis>
<Axis axis="x" position="bottom" dataKey="xAxis">
<AxisLabel />
<AxisLine />
</Axis>
<Line dataKey="lower" stroke-width={3} />
<Line dataKey="middle" stroke-width={3} />
<Line
dataKey="higher"
axisId="high"
class="stroke-sc-400"
stroke-width={3}
/>
</Chart>
</div>
)
}
export default MultipleAxisChart
The axis labels on the right now correspond with the high value series, which improves the scaling of the other axis and makes reading the chart easier.
v0.0.1
Developed and designed by Jasmin