Skip to main content

Bullet Chart

A Bullet Chart is a variation of a bar chart developed by Stephen Few. It's designed to replace dashboard gauges and meters. A bullet chart compares a primary measure (e.g., year-to-date revenue) to one or more target measures (e.g., annual revenue goal) and qualitative ranges (e.g., poor, satisfactory, good).

Installation

The BulletChart component is part of the @rexora/charts package. You can install it using npm or yarn:

bash
npm install @rexora/charts
# or
yarn add @rexora/charts

Usage

Here's a basic example of how to use the BulletChart component:

tsx
import React from 'react';
import { BulletChart } from '@rexora/charts';

const data = {
title: 'Revenue',
subtitle: 'US$, in thousands',
ranges: [150, 225, 300], // Bad, Satisfactory, Good
measures: [270], // Current year-to-date
markers: [250], // Previous year-to-date
};

const MyBulletChart = () => {
return (
<div>
<h2>My Dashboard</h2>
<BulletChart data={data} width={400} height={80} />
</div>
);
};

export default MyBulletChart;

Props and Options

The BulletChart component accepts the following props:

PropTypeDescriptionRequiredDefault
dataobjectAn object containing the data for the chart. See data structure below.Yes
widthnumberThe width of the chart in pixels.No960
heightnumberThe height of the chart in pixels.No50
marginobjectAn object defining the chart margins (top, right, bottom, left).No{ top: 0, right: 40, bottom: 0, left: 120 }

Data Structure

The data prop is an object with the following structure:

PropertyTypeDescriptionRequired
titlestringThe main title of the bullet chart.Yes
subtitlestringA subtitle or descriptive text for the chart.No
rangesnumber[]An array of numbers representing the qualitative ranges (e.g., poor, good).Yes
measuresnumber[]An array of numbers representing the primary measures.Yes
markersnumber[]An array of numbers representing the target markers.No

Notes

  • The ranges, measures, and markers arrays should contain numbers representing the values on the chart's scale.
  • The number of elements in ranges, measures, and markers will determine the visual representation of the chart.
  • The D3 implementation within the component will handle the scaling and rendering based on the provided data and dimensions.