Bar chart
Display horizontal bar comparisons with the BarChart component.
A bar chart shows data in horizontal bars. Bar charts can display one or multiple measures side by side divided by attribute values or a single measure stacked by attribute values. Use it to compare values across categories, for example, sales by product.

Buckets
| Prop | Required | Takes | What it does |
|---|---|---|---|
measures | Yes | One or more measures | Sets the length of the bars, one bar per measure. |
viewBy | No | One or two attributes | Slices the measures by the attribute values along the Y axis. With two attributes, the values of the second attribute are grouped under each value of the first. Extra attributes are ignored. |
stackBy | No | One attribute | Splits each bar into segments, one per attribute value. Works only with a single measure. |
filters | No | Filters | Limits the data the bar chart shows. |
Sorting
BarChart applies no default sorting. To sort the data, pass sort items in the sortBy prop. To sort stacked bars by their totals, use an attribute area sort (newAttributeAreaSort) on the viewBy attribute. See Sort items.
Configuration
Pass these options in the config prop. See Chart configuration for details.
| Option | What it changes |
|---|---|
colors, colorPalette, colorMapping | Colors of the bars: one per measure, or one per stackBy value. |
legend | Whether the legend shows and where. |
dataLabels | visible shows or hides the labels. totalsVisible shows or hides the totals of stacked bars, which are hidden by default. style: "backplate" adds a background behind the labels. |
stackMeasures, stackMeasuresToPercent | stackMeasures stacks the measures into one bar. stackMeasuresToPercent stacks the measures, or the stackBy segments, to 100% and overrides stackMeasures. |
enableReversedStacking | Reverses the order of the segments in stacked bars. |
xaxis, yaxis | Visibility, labels, rotation, and name of the axes. xaxis is the horizontal value axis, where min and max set the scale. yaxis is the vertical axis with the viewBy values. |
secondary_xaxis | Shows the measures listed in measures (local identifiers) on a secondary axis at the top. Takes the same options as xaxis. |
enableJoinedAttributeAxisName | With two viewBy attributes, their axis has no name by default. This option shows the attribute names joined by › as the name. |
grid | enabled shows or hides the grid lines. |
chartFill | type sets how bars are filled: "solid", "pattern", or "outline". |
separators | Thousands and decimal separators in the number format. |
zoomInsight | Lets users zoom and pan along the axis with the viewBy values. |
enableCompactSize | Hides axis labels and names when the chart is too small for them. Has no effect when zoomInsight is on. |
Limits
- A bar chart renders up to 6,000 data points, counted as the number of
viewByvalues times the number of series (measures orstackByvalues), including empty combinations. With more, the chart shows an error andonErrorreceives aDataTooLargeToDisplaySdkError. Filter the data to fit. - A stacked bar chart renders up to 1,000 series:
stackByvalues, or measures stacked withstackMeasuresorstackMeasuresToPercent. With more, the chart shows the same error. - A measure shown in % (
computeRatio) works only when it’s the only measure. With two or more measures, the chart turnscomputeRatiooff on all of them. See Show a measure as a percentage.
Structure
import "@gooddata/sdk-ui-charts/styles/css/main.css";
import { BarChart } from "@gooddata/sdk-ui-charts";
<BarChart
measures={<measures>}
config={<chart-config>}
…
/>
Example
import "@gooddata/sdk-ui-charts/styles/css/main.css";
import { BarChart } from "@gooddata/sdk-ui-charts";
import * as Md from "./catalog.js";
const style = { height: 300 };
<div style={style}>
<BarChart
measures={[Md.$TotalSales]}
viewBy={Md.DateMonth.Short}
/>
</div>
Props
| Prop | Type | Required | Description | Inherited from |
|---|---|---|---|---|
measures | AttributesMeasuresOrPlaceholders | Yes | Specify one or more measures to display on the bar chart. | IBarChartBucketProps |
backend | IAnalyticalBackend | No | Analytical backend, from which the chart will obtain data to visualize If you do not specify instance of analytical backend using this prop, then you MUST have BackendProvider up in the component tree. | IBucketChartProps |
config | IChartConfig | No | Configure chart’s behavior and appearance. | ICommonChartProps |
drillableItems | ExplicitDrill[] | No | Configure drillability; e.g. which parts of the visualization can be interacted with. | IVisualizationProps |
ErrorComponent | ComponentType<IErrorProps> | No | React component to display in the event when there is an error with either obtaining the data from backend or with the data itself. | IVisualizationProps |
execConfig | IExecutionConfig | No | Execution configuration, will provide the execution with necessary config before initiating execution. | ICommonChartProps |
exportTitle | string | No | Set title to use for exported files. | IVisualizationProps |
filters | NullableFiltersOrPlaceholders | No | Specify filters to apply on the data to chart. | IBarChartBucketProps |
height | number | No | Set height of the chart (in pixels). | ICommonChartProps |
LoadingComponent | ComponentType<ILoadingProps> | No | React component to display while loading data from the backend. | IVisualizationProps |
locale | string | No | Set Locale for visualization localization. | IVisualizationProps |
onDataView | OnDataView | No | (Alpha) Called when the visualization loads a DataView, i.e. it receives data from the backend. | IVisualizationCallbacks |
onDrill | OnFiredDrillEvent | No | Called when user triggers a drill on a visualization. | IVisualizationCallbacks |
onError | OnError | No | Called when an error occurs while loading data for the visualization. | IVisualizationCallbacks |
onExportReady | OnExportReady | No | Called when the visualization is ready to be exported. | IVisualizationCallbacks |
onLegendReady | OnLegendReady | No | Called when legend is rendered. | IChartCallbacks |
onLoadingChanged | OnLoadingChanged | No | Called when loading status of the visualization changes - vis starts or stops loading | IVisualizationCallbacks |
placeholdersResolutionContext | any | No | Resolution context for composed placeholders. | IBarChartBucketProps |
sortBy | SortsOrPlaceholders | No | Specify how to sort the data to chart. | IBarChartBucketProps |
stackBy | AttributeOrPlaceholder | No | Specify attribute to stack the bars by. | IBarChartBucketProps |
viewBy | AttributeOrPlaceholder | AttributesOrPlaceholders | No | Specify one or two attributes to slice the measures along the Y axis. | IBarChartBucketProps |
width | number | No | Set width of the chart (in pixels). | ICommonChartProps |
workspace | string | No | Identifier of analytical workspace, from which the chart will obtain data to visualize. If you do not specify workspace identifier, then you MUST have WorkspaceProvider up in the component tree. | IBucketChartProps |
Related
Display vertical bar comparisons with the ColumnChart component.
Combine bars and lines in a single visualization with the ComboChart component.
Compare measures against targets using the BulletChart component.
Configure chart appearance, axes, legends, colors, and data labels.
Shared behavior of GoodData.UI visual components — responsive sizing, the style and data props model, and the visualization lifecycle callbacks.