CxJS

Swimlanes

import { Swimlanes } from 'cx/charts'; Copied

Swimlanes draws horizontal or vertical bands in the chart background. Besides aesthetics, swimlanes make it easier to read axis values by providing visual separation between categories.

<div controller={PageController} style="display: flex; gap: 16px">
  <Svg style="flex: 1; height: 400px">
    <Chart
      offset="20 -20 -30 100"
      axes={{
        x: { type: NumericAxis, snapToTicks: 1 },
        y: { type: CategoryAxis, vertical: true },
      }}
    >
      <Swimlanes size={0.6} step={1} />
      <BarGraph
        data={m.points}
        colorIndex={0}
        name="2023"
        size={0.3}
        offset={-0.15}
        xField="v1"
        yField="city"
        selection={{
          type: KeySelection,
          bind: m.selected,
          keyField: "city",
        }}
      />
      <BarGraph
        data={m.points}
        colorIndex={6}
        name="2024"
        size={0.3}
        offset={0.15}
        xField="v2"
        yField="city"
        selection={{
          type: KeySelection,
          bind: m.selected,
          keyField: "city",
        }}
      />
    </Chart>
  </Svg>
  <Legend vertical />
</div>
2023
2024

Features

  • Automatic swimlane generation based on axis
  • Works with both horizontal and vertical orientations
  • Configurable size and step
  • Combines well with bar graphs for grouped data visualization

Configuration

PropertyTypeDefaultDescription
xAxisstringAxis name for vertical swimlanes.
yAxisstringAxis name for horizontal swimlanes (auto-detected).
sizenumber1Swimlane width relative to axis step (0-1).
stepnumber1Step between swimlanes. Use 2 for alternating lanes.
styleobjectCSS style for swimlane rectangles.
classstringCSS class for swimlane elements.