Creating Bullet Charts with CanvasJS
StackedBar100 and Bar Charts

Sachin Bisht
3 min readFeb 12, 2024

--

Bullet charts are a powerful visualization tool used to compare a target value to an actual value while providing additional context such as ranges or benchmarks. CanvasJS, a JavaScript charting library, offers a flexible and intuitive way to create bullet charts using its StackedBar100 and Bar chart types. In this article, we’ll explore how to leverage CanvasJS to build compelling bullet charts for your data visualization needs.

Understanding Bullet Charts: Before delving into the implementation, let’s briefly review the components of a bullet chart:

  1. Target Value: The goal or desired value for a particular metric.
  2. Actual Value: The current or observed value for the same metric.
  3. Ranges (Optional): Additional qualitative ranges such as poor, satisfactory, and excellent, which provide context to the actual value.

To begin, ensure you have the CanvasJS library included in your project. You can either download it locally or use a CDN link (https://cdn.canvasjs.com/canvasjs.min.js).

<script src="https://cdn.canvasjs.com/canvasjs.min.js"></script>

Step 1: Define Your Data: Start by structuring your data. Each data point represents a metric to be displayed on the bullet chart. For example:

var bulletChartData = [
{ label: "Metric 1", target: 80, actual: 65 },
{ label: "Metric 2", target: 75, actual: 72 },
{ label: "Metric 3", target: 90, actual: 85 }
];

Step 2: Create the Chart: Instantiate a new CanvasJS Chart object and configure its properties:

var bulletChart = new CanvasJS.Chart("chartContainer", {
title: { text: "Bullet Chart Example" },
data: [
{ /* StackedBar100 series for Target */ },
{ /* StackedBar100 series for Difference */ },
{ /* Bar series for Actual */ }
]
});

Step 3: Configure Data Series: Define the data series for your bullet chart. Utilize StackedBar100 for target and difference, and Bar for the actual value. Map the data points accordingly:

data: [
{
type: "stackedBar100",
name: "Target",
showInLegend: true,
color: "#7f7f7f",
dataPoints: bulletChartData.map(item => ({ label: item.label, y: item.target }))
}, {
type: "stackedBar100",
name: "Difference",
color: "#afabab",
toolTipContent: null,
dataPoints: bulletChartData.map(item => ({ label: item.label, y: item.target - item.actual }))
}, {
type: "bar",
toolTipContent: null,
dataPoints:[{}]
}, {
type: "bar",
name: "Actual",
color: "#000",
showInLegend: true,
dataPoints: bulletChartData.map(item => ({ label: item.label, y: item.actual }))
}, {
type: "bar",
toolTipContent: null,
dataPoints:[{}]
}
]
});

Step 4: Customize Appearance: Customize the appearance of your chart by modifying properties such as colors, axis labels, titles, etc.

Step 5: Render the Chart: Finally, render the chart within the specified container:

bulletChart.render();

Bullet charts are effective tools for visualizing performance metrics, allowing for quick and easy comparison between target and actual values. By leveraging CanvasJS and its StackedBar100 and Bar chart types, creating dynamic and insightful bullet charts becomes a straightforward task. Whether for business dashboards, analytics reports, or data-driven presentations, bullet charts empower users to make informed decisions with clarity and precision. Experiment with different configurations and data sets to unleash the full potential of bullet charts in your visualizations.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Sachin Bisht
Sachin Bisht

Written by Sachin Bisht

Software developer striving to be my best and help others do the same.

No responses yet

Write a response