# BarChart component for Stripe Apps A bar chart visualizes data as a series of data points using bars. # v8 > This is a v8 for when app-sdk-version is 8. View the full page at https://docs.stripe.com/stripe-apps/components/barchart?app-sdk-version=8. To add the `BarChart` component to your app: ```js import {BarChart} from '@stripe/ui-extension-sdk/ui'; ``` The following shows a preview of the `BarChart` UI component: ### BarChart props | Property | Type | | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `data` | (Required) `{ [x: string]: any; }[]` The data used to generate the chart. | | `x` | (Required) `string | number | Channel` The property or accessor for the point on the x axis. Related types: [Channel](https://docs.stripe.com/stripe-apps/components/barchart.md#channel). | | `y` | (Required) `string | number | Channel` The property or accessor for the point on the y axis. Related types: [Channel](https://docs.stripe.com/stripe-apps/components/barchart.md#channel). | | `axis` | (Optional) `("x" | "y" | "both" | "none") | undefined` Determines whether to render labels and ticks for each axis. | | `color` | (Optional) `(string | number | Channel) | undefined` Groups data by color based on a property or accessor. Related types: [Channel](https://docs.stripe.com/stripe-apps/components/barchart.md#channel). | | `grid` | (Optional) `("x" | "y" | "both" | "none") | undefined` Determines whether to render grid lines for each axis. | | `legend` | (Optional) `boolean | undefined` Determines whether to render the legend (when more than one item is present). | | `tooltip` | (Optional) `boolean | undefined` Determines whether to render a tooltip when hovering over the chart. | | `z` | (Optional) `(string | number | Channel) | undefined` Groups data based on a property or accessor. Related types: [Channel](https://docs.stripe.com/stripe-apps/components/barchart.md#channel). | ### Channel | Property | Type | | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `domain` | (Optional) `any[] | undefined` | | `format` | (Optional) `((Currency | UnitIdentifier) | ("capitalize" | { [x: string]: string; })) | undefined` Related types: [Currency](https://docs.stripe.com/stripe-apps/components/barchart.md#currency), [UnitIdentifier](https://docs.stripe.com/stripe-apps/components/barchart.md#unitidentifier). | | `label` | (Optional) `string | undefined` | | `value` | (Optional) `(string | number) | undefined` | ### Currency | Property | Type | | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `currency` | (Required) `'AED' | 'AFN' | 'ALL' | 'AMD' | 'ANG' | 'AOA' | 'ARS' | 'AUD' | 'AWG' | 'AZN' | 'BAM' | 'BBD' | 'BDT' | 'BGN' | 'BHD' | 'BIF' | 'BMD' | 'BND' | 'BOB' | 'BRL' | 'BSD' | 'BTN' | 'BWP' | 'BYN' | 'BZD' | 'CAD' | 'CDF' | 'CHF' | 'CLP' | 'CNY' | 'COP' | 'CRC' | 'CUC' | 'CUP' | 'CVE' | 'CZK' | 'DJF' | 'DKK' | 'DOP' | 'DZD' | 'EGP' | 'ERN' | 'ETB' | 'EUR' | 'FJD' | 'FKP' | 'GBP' | 'GEL' | 'GHS' | 'GIP' | 'GMD' | 'GNF' | 'GTQ' | 'GYD' | 'HKD' | 'HNL' | 'HRK' | 'HTG' | 'HUF' | 'IDR' | 'ILS' | 'INR' | 'IQD' | 'IRR' | 'ISK' | 'JMD' | 'JOD' | 'JPY' | 'KES' | 'KGS' | 'KHR' | 'KMF' | 'KPW' | 'KRW' | 'KWD' | 'KYD' | 'KZT' | 'LAK' | 'LBP' | 'LKR' | 'LRD' | 'LSL' | 'LYD' | 'MAD' | 'MDL' | 'MGA' | 'MKD' | 'MMK' | 'MNT' | 'MOP' | 'MRU' | 'MUR' | 'MVR' | 'MWK' | 'MXN' | 'MYR' | 'MZN' | 'NAD' | 'NGN' | 'NIO' | 'NOK' | 'NPR' | 'NZD' | 'OMR' | 'PAB' | 'PEN' | 'PGK' | 'PHP' | 'PKR' | 'PLN' | 'PYG' | 'QAR' | 'RON' | 'RSD' | 'RUB' | 'RWF' | 'SAR' | 'SBD' | 'SCR' | 'SDG' | 'SEK' | 'SGD' | 'SHP' | 'SLL' | 'SOS' | 'SRD' | 'SSP' | 'STN' | 'SYP' | 'SZL' | 'THB' | 'TJS' | 'TMT' | 'TND' | 'TOP' | 'TRY' | 'TTD' | 'TWD' | 'TZS' | 'UAH' | 'UGX' | 'USD' | 'UYU' | 'UZS' | 'VES' | 'VND' | 'VUV' | 'WST' | 'XAF' | 'XCD' | 'XOF' | 'XPF' | 'YER' | 'ZAR' | 'ZMW'` | ### UnitIdentifier | Property | Type | | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `unit` | (Required) `'acre' | 'bit' | 'byte' | 'celsius' | 'centimeter' | 'day' | 'degree' | 'fahrenheit' | 'fluid-ounce' | 'foot' | 'gallon' | 'gigabit' | 'gigabyte' | 'gram' | 'hectare' | 'hour' | 'inch' | 'kilobit' | 'kilobyte' | 'kilogram' | 'kilometer' | 'liter' | 'megabit' | 'megabyte' | 'meter' | 'mile' | 'mile-scandinavian' | 'milliliter' | 'millimeter' | 'millisecond' | 'minute' | 'month' | 'ounce' | 'percent' | 'petabyte' | 'pound' | 'second' | 'stone' | 'terabit' | 'terabyte' | 'week' | 'yard' | 'year' | `${'acre' | 'bit' | 'byte' | 'celsius' | 'centimeter' | 'day' | 'degree' | 'fahrenheit' | 'fluid-ounce' | 'foot' | 'gallon' | 'gigabit' | 'gigabyte' | 'gram' | 'hectare' | 'hour' | 'inch' | 'kilobit' | 'kilobyte' | 'kilogram' | 'kilometer' | 'liter' | 'megabit' | 'megabyte' | 'meter' | 'mile' | 'mile-scandinavian' | 'milliliter' | 'millimeter' | 'millisecond' | 'minute' | 'month' | 'ounce' | 'percent' | 'petabyte' | 'pound' | 'second' | 'stone' | 'terabit' | 'terabyte' | 'week' | 'yard' | 'year'}-per-${'acre' | 'bit' | 'byte' | 'celsius' | 'centimeter' | 'day' | 'degree' | 'fahrenheit' | 'fluid-ounce' | 'foot' | 'gallon' | 'gigabit' | 'gigabyte' | 'gram' | 'hectare' | 'hour' | 'inch' | 'kilobit' | 'kilobyte' | 'kilogram' | 'kilometer' | 'liter' | 'megabit' | 'megabyte' | 'meter' | 'mile' | 'mile-scandinavian' | 'milliliter' | 'millimeter' | 'millisecond' | 'minute' | 'month' | 'ounce' | 'percent' | 'petabyte' | 'pound' | 'second' | 'stone' | 'terabit' | 'terabyte' | 'week' | 'yard' | 'year'}`` | ## Using color The `color` channel groups data: ## Axis and value formatting Instead of passing a string for an axis value, you can add richer formatting by passing an object including the `value`, `label` and/or `format` properties. | Property | Type | | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `value` | `string | number` The property name in the data set. Required. | | `label` | `string` The display text for the axis. | | `format` | `object` Format a number with one of the [supported currency codes](https://raw.githubusercontent.com/unicode-org/cldr/main/common/validity/currency.xml) for example `{currency: 'USD'}`, or a [supported unit](https://tc39.es/proposal-unified-intl-numberformat/section6/locales-currencies-tz_proposed_out.html#sec-issanctionedsimpleunitidentifier) such as `{unit: 'minute'}`. You can also create a compound unit with `-per-` in between, such as `{unit: 'megabyte-per-hour'}`. | ## Domain To set the minimum and maximum values of an axis, use the `domain` prop. For example, if you always want the `y` axis to go from 0 to 10 (rather than automatically adjusting to the data provided), add the `domain` property to your configuration: # v9 > This is a v9 for when app-sdk-version is 9. View the full page at https://docs.stripe.com/stripe-apps/components/barchart?app-sdk-version=9. To add the `BarChart` component to your app: ```js import {BarChart} from '@stripe/ui-extension-sdk/ui'; ``` The following shows a preview of the `BarChart` UI component: ### BarChart props | Property | Type | | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `data` | (Required) `{ [x: string]: any; }[]` The data used to generate the chart. | | `x` | (Required) `string | number | Channel` The property or accessor for the point on the x axis. Related types: [Channel](https://docs.stripe.com/stripe-apps/components/barchart.md#channel). | | `y` | (Required) `string | number | Channel` The property or accessor for the point on the y axis. Related types: [Channel](https://docs.stripe.com/stripe-apps/components/barchart.md#channel). | | `axis` | (Optional) `("x" | "y" | "both" | "none") | undefined` Determines whether to render labels and ticks for each axis. | | `color` | (Optional) `(string | number | Channel) | undefined` Groups data by color based on a property or accessor. Related types: [Channel](https://docs.stripe.com/stripe-apps/components/barchart.md#channel). | | `grid` | (Optional) `("x" | "y" | "both" | "none") | undefined` Determines whether to render grid lines for each axis. | | `legend` | (Optional) `boolean | undefined` Determines whether to render the legend (when more than one item is present). | | `tooltip` | (Optional) `boolean | undefined` Determines whether to render a tooltip when hovering over the chart. | | `z` | (Optional) `(string | number | Channel) | undefined` Groups data based on a property or accessor. Related types: [Channel](https://docs.stripe.com/stripe-apps/components/barchart.md#channel). | ### Channel | Property | Type | | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `domain` | (Optional) `any[] | undefined` | | `format` | (Optional) `((CurrencyFormat | UnitIdentifier | { style?: "decimal" | undefined; }) | ("capitalize" | { [x: string]: string; })) | undefined` Related types: [CurrencyFormat](https://docs.stripe.com/stripe-apps/components/barchart.md#currencyformat), [UnitIdentifier](https://docs.stripe.com/stripe-apps/components/barchart.md#unitidentifier). | | `label` | (Optional) `string | undefined` | | `nice` | (Optional) `boolean | undefined` | | `tickFormat` | (Optional) `((CurrencyFormat | UnitIdentifier | { style?: "decimal" | undefined; }) | ("capitalize" | { [x: string]: string; })) | undefined` Related types: [CurrencyFormat](https://docs.stripe.com/stripe-apps/components/barchart.md#currencyformat), [UnitIdentifier](https://docs.stripe.com/stripe-apps/components/barchart.md#unitidentifier). | | `ticks` | (Optional) `number | undefined` | | `value` | (Optional) `(string | number) | undefined` | | `zero` | (Optional) `boolean | undefined` | ### CurrencyFormat | Property | Type | | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `currency` | (Required) `'AED' | 'AFN' | 'ALL' | 'AMD' | 'ANG' | 'AOA' | 'ARS' | 'AUD' | 'AWG' | 'AZN' | 'BAM' | 'BBD' | 'BDT' | 'BGN' | 'BHD' | 'BIF' | 'BMD' | 'BND' | 'BOB' | 'BRL' | 'BSD' | 'BTN' | 'BWP' | 'BYN' | 'BZD' | 'CAD' | 'CDF' | 'CHF' | 'CLP' | 'CNY' | 'COP' | 'CRC' | 'CUC' | 'CUP' | 'CVE' | 'CZK' | 'DJF' | 'DKK' | 'DOP' | 'DZD' | 'EGP' | 'ERN' | 'ETB' | 'EUR' | 'FJD' | 'FKP' | 'GBP' | 'GEL' | 'GHS' | 'GIP' | 'GMD' | 'GNF' | 'GTQ' | 'GYD' | 'HKD' | 'HNL' | 'HRK' | 'HTG' | 'HUF' | 'IDR' | 'ILS' | 'INR' | 'IQD' | 'IRR' | 'ISK' | 'JMD' | 'JOD' | 'JPY' | 'KES' | 'KGS' | 'KHR' | 'KMF' | 'KPW' | 'KRW' | 'KWD' | 'KYD' | 'KZT' | 'LAK' | 'LBP' | 'LKR' | 'LRD' | 'LSL' | 'LYD' | 'MAD' | 'MDL' | 'MGA' | 'MKD' | 'MMK' | 'MNT' | 'MOP' | 'MRU' | 'MUR' | 'MVR' | 'MWK' | 'MXN' | 'MYR' | 'MZN' | 'NAD' | 'NGN' | 'NIO' | 'NOK' | 'NPR' | 'NZD' | 'OMR' | 'PAB' | 'PEN' | 'PGK' | 'PHP' | 'PKR' | 'PLN' | 'PYG' | 'QAR' | 'RON' | 'RSD' | 'RUB' | 'RWF' | 'SAR' | 'SBD' | 'SCR' | 'SDG' | 'SEK' | 'SGD' | 'SHP' | 'SLL' | 'SOS' | 'SRD' | 'SSP' | 'STN' | 'SYP' | 'SZL' | 'THB' | 'TJS' | 'TMT' | 'TND' | 'TOP' | 'TRY' | 'TTD' | 'TWD' | 'TZS' | 'UAH' | 'UGX' | 'USD' | 'UYU' | 'UZS' | 'VES' | 'VND' | 'VUV' | 'WST' | 'XAF' | 'XCD' | 'XOF' | 'XPF' | 'YER' | 'ZAR' | 'ZMW'` | | `fractionalDigits` | (Optional) `(0 | "auto") | undefined` | ### UnitIdentifier | Property | Type | | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `unit` | (Required) `'acre' | 'bit' | 'byte' | 'celsius' | 'centimeter' | 'day' | 'degree' | 'fahrenheit' | 'fluid-ounce' | 'foot' | 'gallon' | 'gigabit' | 'gigabyte' | 'gram' | 'hectare' | 'hour' | 'inch' | 'kilobit' | 'kilobyte' | 'kilogram' | 'kilometer' | 'liter' | 'megabit' | 'megabyte' | 'meter' | 'mile' | 'mile-scandinavian' | 'milliliter' | 'millimeter' | 'millisecond' | 'minute' | 'month' | 'ounce' | 'percent' | 'petabyte' | 'pound' | 'second' | 'stone' | 'terabit' | 'terabyte' | 'week' | 'yard' | 'year' | `${'acre' | 'bit' | 'byte' | 'celsius' | 'centimeter' | 'day' | 'degree' | 'fahrenheit' | 'fluid-ounce' | 'foot' | 'gallon' | 'gigabit' | 'gigabyte' | 'gram' | 'hectare' | 'hour' | 'inch' | 'kilobit' | 'kilobyte' | 'kilogram' | 'kilometer' | 'liter' | 'megabit' | 'megabyte' | 'meter' | 'mile' | 'mile-scandinavian' | 'milliliter' | 'millimeter' | 'millisecond' | 'minute' | 'month' | 'ounce' | 'percent' | 'petabyte' | 'pound' | 'second' | 'stone' | 'terabit' | 'terabyte' | 'week' | 'yard' | 'year'}-per-${'acre' | 'bit' | 'byte' | 'celsius' | 'centimeter' | 'day' | 'degree' | 'fahrenheit' | 'fluid-ounce' | 'foot' | 'gallon' | 'gigabit' | 'gigabyte' | 'gram' | 'hectare' | 'hour' | 'inch' | 'kilobit' | 'kilobyte' | 'kilogram' | 'kilometer' | 'liter' | 'megabit' | 'megabyte' | 'meter' | 'mile' | 'mile-scandinavian' | 'milliliter' | 'millimeter' | 'millisecond' | 'minute' | 'month' | 'ounce' | 'percent' | 'petabyte' | 'pound' | 'second' | 'stone' | 'terabit' | 'terabyte' | 'week' | 'yard' | 'year'}`` | ## Using color The `color` channel groups data: ## Axis and value formatting Instead of passing a string for an axis value, you can add richer formatting by passing an object including the `value`, `label` and/or `format` properties. | Property | Type | | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `value` | `string | number` The property name in the data set. Required. | | `label` | `string` The display text for the axis. | | `format` | `object` Format a number with one of the [supported currency codes](https://raw.githubusercontent.com/unicode-org/cldr/main/common/validity/currency.xml) for example `{currency: 'USD'}`, or a [supported unit](https://tc39.es/proposal-unified-intl-numberformat/section6/locales-currencies-tz_proposed_out.html#sec-issanctionedsimpleunitidentifier) such as `{unit: 'minute'}`. You can also create a compound unit with `-per-` in between, such as `{unit: 'megabyte-per-hour'}`. | ## Domain To set the minimum and maximum values of an axis, use the `domain` prop. For example, if you always want the `y` axis to go from 0 to 10 (rather than automatically adjusting to the data provided), add the `domain` property to your configuration: ## Next version The next version of `BarChart` component is available. For more details on how to use Next UI components, see [this guide](https://docs.stripe.com/stripe-apps/next-ui-components.md). ### Axis (next) ### Forecasted (next) ### Incomplete (next) ### Stacked (next) ## See also - [Design patterns to follow](https://docs.stripe.com/stripe-apps/patterns.md) - [Style your app](https://docs.stripe.com/stripe-apps/style.md) - [UI testing](https://docs.stripe.com/stripe-apps/ui-testing.md)