CxJS

Bar

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

The Bar component renders individual horizontal bars. Unlike BarGraph which takes data arrays, Bar is used with Repeater for more control over each bar.

Use height and offset to position multiple series side by side. Hover over bars to see tooltips.

<div controller={PageController}>
  <Legend />
  <Svg style="height: 280px; border: 1px dashed #ddd">
    <Chart
      margin="20 20 30 100"
      axes={{
        x: <NumericAxis snapToTicks={0} />,
        y: <CategoryAxis vertical />,
      }}
    >
      <Rectangle fill="white" />
      <Gridlines />
      <Repeater records={m.data} recordAlias="$point">
        <Bar
          colorIndex={0}
          name="2023"
          height={0.3}
          offset={-0.15}
          x={m.$point.v1}
          y={m.$point.category}
          tooltip={format(m.$point.v1, "n;0")}
          active={m.v1Active}
        />
        <Bar
          colorIndex={5}
          name="2024"
          height={0.3}
          offset={0.15}
          x={m.$point.v2}
          y={m.$point.category}
          tooltip={format(m.$point.v2, "n;0")}
          active={m.v2Active}
        />
      </Repeater>
    </Chart>
  </Svg>
</div>
2023
2024

Configuration

PropertyTypeDescription
xnumberBar value (length).
x0numberBar start value for range bars. Default is 0.
ystringCategory value.
colorIndexnumberIndex of the color from the theme palette.
colorMapstringName of the color map for automatic color assignment.
namestringSeries name for the legend.
activebooleanBinding to control visibility. Works with Legend interaction.
heightnumberBar thickness as a fraction of available space. Default is 0.5.
offsetnumberOffset for positioning multiple series. Default is 0.
stackedbooleanSet to true to stack bars.
borderRadiusnumberCorner radius for rounded bars.
tooltipobjectTooltip configuration. Use tpl for template strings.