Column Chart: Core Setup, Styling, and Layout

In the realm of data visualization and reporting, the Column Chart (a vertical bar chart) is the primary tool for comparing discrete categories over a single or multiple metrics. Unlike horizontal bar charts that are well-suited for long text labels, vertical column charts utilize height differences to instantly communicate volume, growth, and variance. Whether you are displaying quarterly sales figures, server CPU utilization spikes, or web traffic by channel, column charts provide a clear visual standard for category-based metrics.

The Mechanics of Vertical Columns

In Apache ECharts, both horizontal bar charts and vertical column charts rely on the 'bar' series type. The key factor that creates a column chart is placing category labels on the horizontal axis (xAxis) while setting the vertical axis (yAxis) to numerical values. The chart engine reads the data array and dynamically scales the height of each vertical column relative to the numerical scale.

1. Essential Setup

To build a basic column chart, define a category-based X-axis and map your dataset to a series object with type: 'bar':

option = {
    xAxis: {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
        type: 'value'
    },
    series: [
        {
            type: 'bar',
            data: [120, 200, 150, 80, 70, 110, 130]
        }
    ]
};

 

Advanced Structural Techniques

When building dashboards, simple single-series charts are often insufficient. ECharts provides clean syntax options to manage multi-series comparisons, custom dimensions, and layout spacing.

Multi-Series Comparison

To compare multiple datasets side-by-side (such as year-over-year revenue), add multiple objects inside the series array. The layout engine will group related columns per category along the X-axis:

option = {
    xAxis: {
        type: 'category',
        data: ['Q1', 'Q2', 'Q3', 'Q4']
    },
    yAxis: {
        type: 'value'
    },
    series: [
        {
            name: '2025 Revenue',
            type: 'bar',
            data: [320, 332, 301, 334]
        },
        {
            name: '2026 Revenue',
            type: 'bar',
            data: [220, 182, 191, 234]
        }
    ]
};

 

Custom Column Styles and Individual Highlighting

You can apply global styles to an entire series or target specific data points directly. This is particularly useful for highlighting key events, outliers, or specific targets.

  • color: Sets fill color (hex, RGB, or linear gradients).
  • borderRadius: Adds rounded corners to columns (e.g., [5, 5, 0, 0] for top corners).
  • opacity: Adjusts column transparency.
  • shadowBlur & shadowColor: Adds elevation and drop shadows to columns.
option = {
    xAxis: {
        type: 'category',
        data: ['Direct', 'Email', 'Ad Networks', 'Video Ads', 'Search']
    },
    yAxis: {
        type: 'value'
    },
    series: [
        {
            type: 'bar',
            data: [
                320,
                332,
                {
                    value: 401,
                    // Highlight a single peak column
                    itemStyle: {
                        color: '#ee6666',
                        borderRadius: [6, 6, 0, 0]
                    }
                },
                334,
                390
            ],
            itemStyle: {
                color: '#5470c6',
                borderRadius: [4, 4, 0, 0]
            }
        }
    ]
};

 

Fine-Tuning Layout and Sizing

Column dimensions and spacing significantly impact readability, especially when displaying charts across responsive screens or dense dashboards.

1. Controlling Width and Limits

By default, column widths scale dynamically based on the chart container. You can control these proportions using sizing properties:

  • barWidth: Defines column width using fixed pixels or a percentage of category width (e.g., '30%').
  • barMaxWidth: Sets an upper limit on width so columns don’t stretch excessively on widescreen displays.
  • barMinHeight: Enforces a minimum pixel height so near-zero values remain clickable and visible.

2. Column Spacing and Background Tracks

To give your columns a modern dashboard appearance, adjust inner gaps or enable full-height background tracks:

option = {
    xAxis: {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri']
    },
    yAxis: {
        type: 'value'
    },
    series: [
        {
            type: 'bar',
            data: [120, 200, 150, 80, 70],
            barWidth: '40%',
            showBackground: true,
            backgroundStyle: {
                color: 'rgba(180, 180, 180, 0.15)',
                borderRadius: [4, 4, 0, 0]
            }
        }
    ]
};

 

Strategic Best Practices

  • Keep Spacing Balanced: Avoid setting barWidth too wide (above 60%) to prevent the visual layout from feeling overcrowded.
  • Horizontal vs. Vertical Decision: Use column charts when category labels are short (e.g., months, quarters, codes). If your labels are long descriptions or names, consider swapping category data to the yAxis to make a horizontal bar chart instead.
  • Zero Baseline Integrity: Always keep the numerical axis starting at zero (0). Truncating the bottom scale in column charts distorts height ratios and misleads viewers.
滚动至顶部