Skip to main content

Bar Charts

Introduction

Bar charts are one of the most widely used and intuitive data visualizations in Grafana. They display categorical data with rectangular bars whose heights or lengths represent the values they correspond to. Bar charts excel at comparing values across different categories, making them perfect for visualizing data distributions, comparisons between groups, and tracking changes over time.

In Grafana, bar charts are versatile visualizations that can be configured in numerous ways to meet specific data representation needs. Whether you're monitoring system metrics, analyzing business KPIs, or visualizing application performance, bar charts provide an accessible and clear way to communicate your data.

Understanding Bar Charts in Grafana

Basic Concepts

A bar chart in Grafana consists of several key components:

  • Bars: Rectangular elements whose height (vertical bars) or length (horizontal bars) represents the magnitude of data
  • X-axis: Typically represents the categories being compared
  • Y-axis: Typically represents the measured values
  • Legends: Help identify different series of data when multiple are displayed

Bar charts can be oriented either vertically (columns) or horizontally (bars), depending on your data presentation needs.

When to Use Bar Charts

Bar charts are ideal when you need to:

  • Compare values across different categories
  • Show distributions of data
  • Track changes over time across categories
  • Highlight differences between similar items
  • Display part-to-whole relationships (stacked bars)

Creating a Basic Bar Chart in Grafana

Let's create a simple bar chart to visualize CPU usage across different servers:

  1. Create a new panel in your Grafana dashboard
  2. Select "Bar chart" from the visualization options
  3. Configure your data source query to retrieve CPU usage per server

Here's a basic example using PromQL (for Prometheus data source):

sql
avg by(instance) (node_cpu_seconds_total{mode="idle"})

This query will return the average idle CPU time for each server instance, which we can then visualize as a bar chart.

Essential Configuration Options

Once you have your data, you can configure the bar chart appearance:

Orientation and Display

In the Panel options section, you can configure:

  • Orientation: Choose between vertical (default) or horizontal bars
  • Bar width: Adjust the width of individual bars
  • Bar group width: Control spacing between bar groups
  • Line width: Set the width of bar outlines
javascript
// Example configuration in Grafana JSON dashboard model
"options": {
"orientation": "auto",
"barWidth": 0.7,
"groupWidth": 0.3,
"showValue": "auto"
}

Value Display Options

You can also control how values are displayed on your bars:

  • Show values: "Auto," "Always," or "Never"
  • Value placement: "Inside" or "Outside" the bars
  • Value color: Automatic or custom color for value labels

Advanced Bar Chart Configurations

Stacked Bar Charts

Stacked bar charts allow you to display multiple series stacked on top of each other, which is useful for showing part-to-whole relationships:

  1. In the "Stack series" option, select "Normal" for basic stacking
  2. Configure your query to return multiple series

For example, this query returns CPU usage by mode for each instance:

sql
avg by(mode, instance) (rate(node_cpu_seconds_total[5m]))

Here's how to configure a stacked bar chart:

javascript
// Example configuration in Grafana JSON dashboard model
"options": {
"stacking": {
"mode": "normal",
"group": "A"
},
"showValue": "auto",
"tooltip": {
"mode": "multi",
"sort": "desc"
}
}

Grouped Bar Charts

Grouped bar charts place bars for different series side by side rather than stacking them:

  1. In the "Stack series" option, select "None"
  2. Configure your query to return multiple series
  3. Adjust the "Bar group width" option to control spacing

Time Series Bar Charts

Bar charts can effectively visualize time series data:

  1. Configure a time series query
  2. Use the bar chart visualization
  3. Adjust the time axis settings

Example query for hourly API requests over the past 24 hours:

sql
sum by(endpoint) (increase(api_requests_total[1h]))

Real-World Examples

Example 1: Server Resource Utilization

Let's create a panel to monitor resource utilization across different servers:

sql
# CPU usage by server
100 - (avg by (instance) (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)

This query calculates the percentage of CPU being used (100 minus idle percentage) for each server.

Configure the bar chart with:

  • Vertical orientation
  • Value display inside bars
  • Alert thresholds at 70% (warning) and 90% (critical)

Example 2: Application Error Distribution

To visualize error counts by type across different services:

sql
# Error counts by service and type
sum by(service, error_type) (increase(application_errors_total[24h]))

Configure as a stacked bar chart with:

  • Horizontal orientation (better for many categories)
  • Services on the Y-axis
  • Error types as stacked components
  • Custom color scheme to highlight critical errors

Example 3: Monthly Revenue Comparison

For business metrics, such as comparing monthly revenue:

sql
# Monthly revenue by product category
sum by(category) (monthly_revenue)

Configure with:

  • Vertical bars
  • Time on the X-axis
  • Currency format for values
  • Sorted bars (highest to lowest)

Customizing Bar Charts for Better Clarity

Color Schemes

Grafana offers various ways to customize colors:

  1. Standard color palette: Select from Grafana's built-in color schemes
  2. Color by value: Change colors based on thresholds
  3. Color by series: Assign specific colors to different data series

Example threshold configuration:

javascript
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{ "color": "green", "value": null },
{ "color": "yellow", "value": 70 },
{ "color": "red", "value": 90 }
]
}
}
}

Axis Configuration

Properly configured axes enhance readability:

  • Axis titles: Add descriptive titles to both axes
  • Unit formatting: Set appropriate units (percentage, bytes, etc.)
  • Scale: Linear, logarithmic, or category scales
  • Min/max range: Set specific value ranges when needed

Sorting and Limiting

To focus on the most important data:

  • Sort bars by value (ascending or descending)
  • Limit the number of bars displayed
  • Group smaller values into an "Other" category

Best Practices for Bar Charts

For effective bar chart visualizations:

  1. Keep it simple: Avoid too many categories or series
  2. Start y-axis at zero: Non-zero baselines can distort comparisons
  3. Use clear labels: Label axes and include units
  4. Sort meaningfully: Arrange bars in a logical order (alphabetical, numerical, etc.)
  5. Use color purposefully: Highlight important information
  6. Consider orientation: Use horizontal bars for long category names
  7. Add context: Include reference lines or thresholds when appropriate

Troubleshooting Common Issues

No Data Appears

If your bar chart shows no data:

  • Verify your query returns data (test in the query editor)
  • Check time range selection
  • Confirm data source connectivity

Bars Too Thin or Wide

If bars display poorly:

  • Adjust "Bar width" setting
  • Change the dashboard time range
  • Modify "Group width" for grouped bars

Legend Issues

If legends aren't displaying correctly:

  • Check "Legend" options in panel settings
  • Verify series naming in your query
  • Consider using aliases for clearer names

Summary

Bar charts in Grafana provide a powerful and flexible way to visualize categorical and time-series data. From simple comparisons to complex stacked representations, they offer numerous configuration options to present your data effectively.

By understanding the various customization options and following best practices, you can create bar chart visualizations that communicate your data clearly and intuitively, helping viewers quickly derive meaningful insights.

Additional Resources

  • Explore Grafana's official documentation on bar charts
  • Practice creating different types of bar charts with sample data
  • Experiment with combining bar charts with other visualizations in a dashboard

Exercises

  1. Create a basic bar chart showing the top 5 CPU-consuming processes on a server
  2. Build a stacked bar chart displaying disk usage by mount point and type
  3. Design a horizontal bar chart comparing response times across different API endpoints
  4. Create a time-series bar chart showing daily error counts for the past week
  5. Construct a grouped bar chart comparing this month's metrics to last month's


If you spot any mistakes on this website, please let me know at [email protected]. I’d greatly appreciate your feedback! :)