CxJS

BarGraph

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

The BarGraph component renders a series of horizontal bars. Use with CategoryAxis on the Y axis for category labels.

For multiple series, use size and offset to position bars side by side. Click legend entries to toggle series visibility.

<div controller={PageController}>
  <Legend />
  <Svg style="height: 300px; border: 1px dashed #ddd">
    <Chart
      margin="20 20 30 80"
      axes={{
        x: <NumericAxis snapToTicks={1} />,
        y: <CategoryAxis vertical />,
      }}
    >
      <Rectangle fill="white" />
      <Gridlines />
      <BarGraph
        name="Q1"
        data={m.data}
        colorIndex={0}
        xField="q1"
        yField="city"
        size={0.3}
        offset={-0.15}
        active={m.q1Active}
      />
      <BarGraph
        name="Q2"
        data={m.data}
        colorIndex={5}
        xField="q2"
        yField="city"
        size={0.3}
        offset={0.15}
        active={m.q2Active}
      />
    </Chart>
  </Svg>
</div>
Q1
Q2

Configuration

PropertyTypeDescription
dataarrayArray of data points.
xFieldstringField name for the bar value (length). Default is "x".
yFieldstringField name for the category. Default is "y".
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.
sizenumberBar 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.
x0FieldstringField name for the bar start value (for range bars).
selectionobjectSelection configuration for interactive bars.