## Feature Examples

### Items
- description: Pass the data as an array of `items`. The only required field is `value`. It sets the width of each bar and is displayed on the bar when there is no label. Bars are sorted from the highest value to the lowest and colored in a fixed sequence.
- example:
```jsx
<StorybookComponents.Stack flexDirection="column" width="100%">
  <BarChart
    items={[
      { value: 220 },
      { value: 270 },
      { value: 720 },
      { value: 250 },
      { value: 450 },
    ]}
  />
</StorybookComponents.Stack>;
```

### Description
- description: Explain what each bar stands for with `description`, shown under the bar, and `descriptionInfo`, shown in a tooltip on hover.
- example:
```jsx
<StorybookComponents.Stack flexDirection="column" width="100%">
  <BarChart
    items={[
      {
        value: 2400,
        description: 'Facebook',
        descriptionInfo: '2,400 visitors came from Facebook',
      },
      {
        value: 1150,
        description: 'Instagram',
        descriptionInfo: '1,150 visitors came from Instagram',
      },
      {
        value: 980,
        description: 'Direct link',
        descriptionInfo: '980 visitors came by direct link',
      },
    ]}
  />
</StorybookComponents.Stack>;
```

### Label
- description: Format the value shown on a bar with `label`, for example as a currency or a percentage. The bar width is still calculated from `value`.
- example:
```jsx
<StorybookComponents.Stack flexDirection="column" width="100%">
  <BarChart
    items={[
      {
        value: 25000,
        label: '$25,000',
        description: 'Sales',
      },
      {
        value: 48000,
        label: '$48,000',
        description: 'Subscriptions',
      },
      {
        value: 42000,
        label: '$42,000',
        description: 'Ads',
      },
    ]}
  />
</StorybookComponents.Stack>;
```

### Total
- description: By default the chart takes the full width and sizes the bars against the sum of all values. Set `total` to a higher number when the items are only a part of a larger whole. The bars then take a proportional share of the width and the rest stays as an empty track.
- example:
```jsx
<StorybookComponents.Stack flexDirection="column" width="100%">
  <BarChart
    items={[
      {
        value: 250,
        description: 'Desktop',
        descriptionInfo: '250 of 730 visitors browsed from a desktop',
      },
      {
        value: 480,
        description: 'Mobile',
        descriptionInfo: '480 of 730 visitors browsed from a mobile device',
      },
    ]}
  />
  <BarChart
    total={1200}
    items={[
      {
        value: 250,
        description: 'Desktop',
        descriptionInfo: '250 of 1,200 visitors browsed from a desktop',
      },
      {
        value: 480,
        description: 'Mobile',
        descriptionInfo: '480 of 1,200 visitors browsed from a mobile device',
      },
    ]}
  />
</StorybookComponents.Stack>;
```

### Single item
- description: A chart with one item shows how that item relates to the `total`, for example unique visitors out of all visits.
- example:
```jsx
<StorybookComponents.Stack flexDirection="column" width="100%">
  <BarChart
    total={1200}
    items={[
      {
        value: 570,
        description: 'Unique visitors',
        descriptionInfo: '570 of 1,200 visitors were unique for this page',
      },
    ]}
  />
</StorybookComponents.Stack>;
```

### Short label
- description: Add `labelShort` as a compact version of the label. It replaces `label` when the bar is too narrow to display the full text.
- example:
```jsx
<StorybookComponents.Stack flexDirection="column" width="600px">
  <BarChart
    items={[
      {
        value: 25000000,
        label: '$25,000,000',
        labelShort: '$25M',
        description: 'Sales',
      },
      {
        value: 20000000,
        label: '$20,000,000',
        labelShort: '$20M',
        description: 'Subscriptions',
      },
      {
        value: 42000000,
        label: '$42,000,000',
        labelShort: '$42M',
        description: 'Ads',
      },
      {
        value: 72000000,
        label: '$72,000,000',
        labelShort: '$72M',
        description: 'Other',
      },
    ]}
  />
</StorybookComponents.Stack>;
```

### Overflow
- description: When a bar is too narrow for its label, the text is truncated with an ellipsis. Add `descriptionInfo` to hide the truncated label instead and reveal the full value in a tooltip on hover. Bars too narrow for any text stay empty. The tooltip keeps their data reachable.
- example:
```jsx
<StorybookComponents.Stack flexDirection="column" width="600px">
  <BarChart
    items={[
      {
        value: 30000000,
        label: '$30,000,000',
        labelShort: '$30M',
        description: 'Sales',
      },
      {
        value: 20000000,
        label: '$20,000,000',
        labelShort: '$20M',
        description: 'Subscriptions',
        descriptionInfo: '$20,000,000 revenue from subscriptions',
      },
      {
        value: 42000000,
        label: '$42,000,000',
        description: 'Ads',
      },
      {
        value: 65000000,
        label: '$65,000,000',
        labelShort: '$65M',
        description: 'Other',
        descriptionInfo: '$65,000,000 revenue from other sources',
      },
    ]}
  />
</StorybookComponents.Stack>;
```

## Common Use Case Examples

### Statistics card
- description: Place the chart in a card with a title and a time range to compare sources of income, traffic or orders on a dashboard.
- example:
```jsx
<Layout>
  <Cell span={8}>
    <Card>
      <Card.Header title="Revenue by source" subtitle="Last 30 days" />
      <Card.Divider />
      <Card.Content>
        <BarChart
          items={[
            {
              value: 42000,
              label: '$42,000',
              labelShort: '$42K',
              description: 'Online store',
              descriptionInfo: '$42,000 revenue from online store orders',
            },
            {
              value: 25000,
              label: '$25,000',
              labelShort: '$25K',
              description: 'Bookings',
              descriptionInfo: '$25,000 revenue from bookings',
            },
            {
              value: 18000,
              label: '$18,000',
              labelShort: '$18K',
              description: 'Subscriptions',
              descriptionInfo: '$18,000 revenue from subscriptions',
            },
            {
              value: 9500,
              label: '$9,500',
              labelShort: '$9.5K',
              description: 'Gift cards',
              descriptionInfo: '$9,500 revenue from gift cards',
            },
          ]}
        />
      </Card.Content>
    </Card>
  </Cell>
</Layout>;
```
