# barchart: Create a Bar Chart

> barchart (Create a Bar Chart) is a 1001fx API function in the group Charts: POST https://api.1001fx.com/charts/barchart, 3 credits per call. It works as a ready-made module in Make and n8n or as a plain HTTP call.

Creates a bar chart with custom data and styling. Output can be an image or a PDF.

- Group: Charts
- Endpoint: `POST https://api.1001fx.com/charts/barchart`
- Authentication: header `X-API-KEY: YOURSECRETAPIKEY`
- Content type: application/json
- Credits: 3 credits per call
- Ready-made in: Make and n8n
- Docs: https://1001fx.com/functions/barchart

## Parameters

- `data` (array<object>, required) – Data: An array of data to be displayed
  - `label` (string, required) – Label: The text to associate with your value
  - `value` (number, required) – Value: The value of your entry
  - `backgroundColor` (string (HEX Color), optional) – Background Color: The background color of your bar. Defaults to #000000 if no color is provided.
  - `borderColor` (string (HEX Color), optional) – Border Color: The border color of your bar. Defaults to #000000 if no color is provided.
- `options` (object, optional) – Chart Options: Options to customize your chart.
  - `title` (string, optional) – Chart Title: The title to be displayed above your chart.
  - `titleAlignment` (enum, optional, one of `start`, `center`, `end`, default `center`) – Chart Title Alignment: Where to place your chart title. Defaults to center.
  - `titleColor` (string (HEX Color), optional) – Title Color: The title's color. Defaults to #000000 if no color is provided.
  - `titleFontSize` (number, optional) – Title Fontsize: The title's font size.
  - `subtitle` (string, optional) – Chart Subtitle: The subtitle to be displayed above your chart.
  - `subtitleAlignment` (enum, optional, one of `start`, `center`, `end`, default `center`) – Chart Subtitle Alignment: Where to place your chart subtitle. Defaults to center.
  - `subtitleColor` (string (HEX Color), optional) – Subtitle Color: The subtitle's color. Defaults to #000000 if no color is provided.
  - `subtitleFontSize` (number, optional) – Subtitle Fontsize: The subtitleFontSize's font size.
  - `backgroundColor` (string (HEX Color), optional) – Chart Background Color: The chart's backgroundColor. Defaults to #ffffff if no color is provided.
  - `padding` (number, optional) – Chart Padding: The padding around your chart. Defaults to 50.
  - `fontFamily` (enum, optional, one of `Alegreya`, `Barlow`, `Inter`, `Lato`, `Montserrat`, `OpenSans`, `Oswald`, `Poppins`, `PTSans`, `Raleway`, `Roboto`) – Font: The font to use in your chart.
  - `dataLabelAnchor` (enum, optional, one of `start`, `center`, `end`, default `center`) – Data Label Anchor: Anchor position of your element. Defaults to center.
  - `dataLabelAlignment` (enum, optional, one of `start`, `center`, `end`, `left`, `top`, `right`, `bottom`, default `center`) – Data Label Alignment: Defines the position of the label relative to the anchor point. Defaults to center.
  - `dataLabelFontSize` (number, optional) – Data Label Font Size: The data label's font size
  - `dataLabelOffset` (number, optional) – Data Label Offset: Offset from the anchor point. Defaults to 0.
  - `dataLabelsHidden` (boolean, optional, default `false`) – Data Labels Hidden: When true hides all data labels. Defaults to false.
  - `dataLabelClamp` (boolean, optional, default `false`) – Data Label Clamping: When true enforces the anchor position to be calculated based on the visible geometry of the associated element. Defaults to false.
  - `yAxisTitle` (string, optional) – Y Axis Title: Text to be displayed on the y axis.
  - `xAxisTitle` (string, optional) – X Axis Title: Text to be displayed on the x axis.
  - `axisTitleFontSize` (number, optional) – Axis Title Fontsize: The axis title's font size.
  - `axisTitleColor` (string (HEX Color), optional) – Axis Title Color: The axis title's color. Defaults to #000000 if no color is provided.
  - `gridColor` (string (HEX Color), optional) – Grid Color: The grid's color. Defaults to #f2f2f2 if no color is provided. Hide by setting to same as chart background color.
  - `axisColor` (string (HEX Color), optional) – Axis Color: The grid's color. Defaults to #a0a0a0 if no color is provided. Hide by setting to same as chart background color.
  - `axisFontSize` (number, optional) – Axis Fontsize: The axis's font size.
  - `borderWidth` (number, optional) – Border Width: The border width of your bars. Defaults to 0.
  - `borderRadius` (number, optional) – Border Radius: The border radius of your bars. Defaults to 0.
  - `indexAxis` (enum, optional, one of `x`, `y`) – Index Axis: The base axis. x for vertical bars. y for horizontal bars. Defaults to x.
- `outputFormat` (enum, required, one of `pdf`, `png`, `jpg`) – Output Format: The desired output format.

## Use cases

- Send a weekly revenue bar chart per region by email from a Google Sheet
- Add a chart of open tickets per team to a Slack report
- Put a bar chart of survey answers into a PDF report
- Compare monthly sign-ups in a horizontal bar chart

## Example: Bar chart as PDF

```bash
curl -X POST 'https://api.1001fx.com/charts/barchart' \
  -H 'X-API-KEY: YOURSECRETAPIKEY' \
  -H 'Content-Type: application/json' \
  -d '{"type":"pie","data":[{"label":"January","value":65,"backgroundColor":"#FF638433","borderColor":"#FF6384"},{"label":"February","value":39,"backgroundColor":"#FF9F4033","borderColor":"#FF9F40"},{"label":"March","value":49,"backgroundColor":"#FFCD5633","borderColor":"#FFCD56"},{"label":"April","value":72,"backgroundColor":"#4BC0C033","borderColor":"#4BC0C0"},{"label":"May","value":93,"backgroundColor":"#36A2EB33","borderColor":"#36A2EB"},{"label":"June","value":84,"backgroundColor":"#9966FF33","borderColor":"#9966FF"}],"options":{"title":"Barchart Generation for Automation Platforms with 1001fx","titleAlignment":"center","titleColor":"#2563EB","subtitle":"Automatic barchart generation from your data as image and PDF. Highly customizable.","subtitleAlignment":"center","subtitleColor":"#333333","gridColor":"#f2f2f2","fontFamily":"Roboto","titleFontSize":20,"subtitleFontSize":16,"axisTitleFontSize":16,"axisFontSize":16,"padding":0,"dataLabelAnchor":"center","dataLabelAlignment":"center","dataLabelFontSize":16,"indexAxis":"y"},"outputFormat":"pdf"}'
```

## FAQ

**In which formats can I get the chart?**

As PNG, JPG or PDF, set with outputFormat. The answer is the file itself, ready to attach to an email or upload to a drive.

**How do I create horizontal bars?**

Set options.indexAxis to y. The default x draws vertical bars.

**Why are my bars black?**

Each entry has its own backgroundColor as a hex color. Without it the bar is drawn in #000000.
