Overview
The Bar Chart component displays categorical data using vertical bars, ideal for comparing values across different products, time periods, or measurement categories. Uses Apache ECharts dataset mode for efficient data binding.Props
Two-dimensional array where the first row contains column headers and subsequent rows contain data values.Dataset Structure:
- First row: Header labels (category name + series names)
- Remaining rows: Data rows (category value + numeric values for each series)
Dataset Mode
The component uses ECharts dataset mode, which offers several advantages:Automatic Series Binding
Each column after the first is automatically bound to a bar series. No need to manually configure series data.
Data Separation
Chart configuration is separated from data, making it easier to update values without changing options.
Column-Based Format
Data is organized by columns, matching common data sources like CSV files or database queries.
Chart Configuration
The Bar Chart includes these built-in features:Legend
Automatic legend generation based on dataset column headers (excluding the first column). Legend items are horizontally aligned.Tooltip
Hover over any bar to see detailed information about that data point, including category name and value.Axes
xAxis
Type:
'category'Automatically populated from the first column of the dataset. Categories are evenly distributed along the x-axis.yAxis
Type:
'value' (default)Automatically scales based on the range of values in the dataset.Series
The number of bar series is determined by the number of columns in the dataset (minus the category column). Each series represents one year/period/measurement type.The component creates one bar series per data column. In the example above, three columns (‘2015’, ‘2016’, ‘2017’) generate three bar series.
Usage Examples
Basic Bar Chart
Water Treatment Plant Comparison
Water Quality Parameters by Zone
Monthly Chemical Consumption
Data Format Requirements
Important: The dataset array must have at least 2 columns (1 category + 1 value series) and at least 2 rows (1 header + 1 data row).
Valid Dataset Examples
Customization Options
While the component provides sensible defaults, you can extend it by modifying the source:- Colors: Modify series colors via
itemStyle.color - Bar Width: Adjust via
series.barWidth - Stacking: Enable via
series.stack - Horizontal Bars: Change
xAxis.typeto'value'andyAxis.typeto'category' - Toolbox: Enable
saveAsImage,dataView,magicTypefeatures
Performance Considerations
- Dataset mode is optimized for updates - changing data doesn’t require reconfiguring series
- Recommended maximum: 50 categories × 10 series for optimal rendering
- For large datasets, consider data aggregation or pagination
Accessibility
- Include descriptive category and series names in the dataset headers
- Use high-contrast color schemes for better visibility
- Consider adding
aria-labelattributes to the chart container
Related Components
- Line Chart - For time-series trend visualization
- Pie Chart - For part-to-whole relationships
- Gauge - For single metric display
Source Reference
File:~/workspace/source/src/modules/Charts/components/BarDataSet.jsx:4
Built with Apache ECharts dataset mode for the Centinela water treatment monitoring system.