This document describes the various types of bar charts that you can create using the Chart API.
Table of Contents
Chart-Specific Features
|
Standard Features
|
Overview
There are a variety of bar charts that you can create, including vertical, horizontal, grouped, stacked, and overlapped versions of each.
Bar charts are good for side-by-side comparison and spotting trends in a small number of discrete data points. They're a good alternative to line charts when you have only a few data points in a series.
There are three general ways to show multiple series in a bar chart:
Grouped |
Stacked |
Overlapped |
cht=bvg |
cht=bvs |
cht=bvo |
You can control bar width and spacing using the chbh
parameter.
If you do not specify chbh
, some
bars might be cropped.
Note that by default, all series are displayed in the same color; if you don't specify different colors for different series, it will be hard to distinguish that there are multiple series in your chart. See Series Colors for details.
Bar charts will display at least one axis by default; if you want to hide any
default axes, use the chxs
parameter and specify an underscore for the <axis_or_tick>
value.
If you use simple text format in stacked charts, you should beware that the chart will crop anything above 100 as the total stack height unless you add custom scaling, as shown here:
Without scaling, the middle three bars exceed 100, and get cropped in a simple text formatted data chart. | cht=bhs |
If we want to show the full stacked bar length, we must either use a different encoding scheme, or use text formatting with custom scaling. The maximum scale value should be relative to the total stacked bar height; this example goes up to 160 (the maximum summed value). | cht=bhs |
Chart Types (cht
)
There are a few different types of bar charts that you can make. Specify a bar chart with the following syntax:
Syntax
cht=<chart_type>
Where <chart_type>
is one of the the following
types:
Chart Type | Description | Example |
---|---|---|
|
Horizontal bar chart with stacked bars. The first example (all bars in dark blue) has one data series. The second example (bars in dark and pale blue) has two series. (It is also scaled to show the summed bar value, which exceeds 100). As you can see, multiple series are stacked. If you don't specify different series colors, all colors will be the same (and the bars won't look stacked). You can also specify a color for each bar within a single series. |
cht=bhs |
|
Vertical bar chart with stacked bars. This example has two series, and uses text format with custom scaling to ensure that all stacked values are fully visible. Note that if you move the zero line in a |
|
bvo |
Vertical bar chart in which bars are stacked in front of one another, rather than atop one another. The height of each bar is its individual value, not its summed value. Bars will be sorted for you by height so that all bars are visible. |
|
|
Horizontal bar charts with grouped bars. The top chart uses default group spacing values; the bottom chart uses the chbh parameter to modify the default bar width and group spacing to make groups more obvious. |
|
|
Vertical bar chart with grouped bars. |
|
Series Colors chco
You can specify the colors of individual bars, individual series, or multiple
series using the chco
parameter.
If you don't specify a different color for each series, all series will be
the same color.
Syntax
chco=<series_1_color>, ..., <series_n_color> or chco=<series_1_bar_1>|<series_1_bar_2>|...|<series_1_bar_n>,<series_2>,...,<series_n>
<color>
- An RRGGBB format hexadecimal number to apply to a series or individual bar. To apply the color to the whole series, it should be comma-delimited. To apply the color to an individual bar, it should be pipe-delimited. You can mix these two formats. See the table below for examples. Whenever you have fewer color values than data points or series, the colors will cycle through the list again, starting from the first color in that group.
Examples
Description | Example |
---|---|
One color per series, with comma-delimited colors. |
|
One color per value, with pipe-delimited colors. |
|
A combination of series colors and individual bar colors. This example shows a bar chart with two series. The first series all black
( |
|
This example demonstrates setting different colors for every bar in a multi-series chart. | chco= |
You can also specify fills to color a series with solid, striped,
or gradient colors. Solid fills look the same as using chco , but stripes or
gradients create unique effects. |
chd=
chd=t: |
Bar Labels
Bar charts support standard axis labels,
but labels along the base of the bars are assigned to individual bars, rather
than spread out along the bar chart. (To spread out labels evenly, use the chxp
parameter
as described below.) If you specify axis labels but don't specify custom labels
along the bar axis, the bar labels will be the index number of each bar or group
of bars. You can customize axis labels using the chxl
parameter.
Description | Example |
---|---|
A bar chart using the default x-axis labels. | chxt=x,y |
A bar chart using custom x-axis labels. |
|
If you have a different number of labels and bars
and want to space the labels evenly (rather than beneath each bar), use the
|
|
Bar Width and Spacing chbh
You can optionally specify custom values for bar widths and spacing between bars
and groups. You can only specify one set of width values for all bars. If you don't
specify chbh
, all bars will be 23 pixels wide, which means
that the end bars can be clipped if the total bar + space width is wider than the
chart width.
Syntax
chbh= <bar_width_or_scale>,<space_between_bars>,<space_between_groups>
- <bar_width_or_scale>
- The width of the bar. You can specify widths and spacing absolutely
or relatively, by entering one of the following values. Default
value is 23 pixels, absolute value.
- width - Bar width, in pixels. All spacing values are also absolute values, in pixels. Bars can be clipped if the chart isn't wide enough.
a
- space_between_bars and space_between_groups are given in absolute units (or default absolute values, if not specified). Bars will be resized so that all bars will fit in the chart.r
- space_between_bars and space_between_groups are given in relative units (or default relative values, if not specified) Relative units are floating point values compared to the bar width, where the bar width is 1.0: for example, 0.5 is half the bar width, 2.0 is twice the bar width. Bars can be clipped if the chart isn't wide enough.
- <space_between_bars>
- [Optional] Space between bars in the same group. If sizing is absolute, this is a width in pixels; if sizing is relative, this is a floating point value where 1.0 is the bar width. Default value is 4 pixels for absolute values, or 4/23 for relative values.
- <space_between_groups>
- [Optional] Space between bar groups in the same group. If sizing is absolute, this is a width in pixels; if sizing is relative, this is a floating point value where 1.0 is the bar width. Default value is 8 pixels for absolute values, or 8/23 for relative values.
You cannot omit intermediate optional parameters; you must end with a stated
value. For example: chbh=10,5,10
is valid, chbh=10,,10
is
not, chbh=10,5,
is not.
Description | Example |
---|---|
This chart uses the The first chart specifies no group spacing, so groups are not apparent. The second chart adds some spacing (15 pixels) between groups. |
|
This chart uses the |
|
The first chart has five values in each series, but the chart is too small to hold all the bars with default values: 10
* 23 pixels for bars + ...so some bars are clipped. The second chart specifies absolute bar and spacing values to fit all bars in the chart. |
|
Zero Line chp
You can specify a custom zero line for your chart using either the chp
parameter,
or using text encoding
with data scaling. These zero lines work in two different
ways:
- Data scaling - When you use text format
data with the scaling parameter
chds
, it will push the zero line up as much as necessary to show all negative values. chp
parameter - You can also move the zero line manually, in any data format, to any location, using thechp
parameter. This actually creates an artificial zero line, and redraws the bars as the difference between the data value and your arbitrary zero value (that is, the bars are drawn from your zero line to the bar value). This cannot be used in combination withchds
.
Syntax
chp= <zero_value_series_1>, ..., <zero_value_series_n>
- <zero_value_series_1>
- A floating point value from 0.0—1.0, inclusive, where 0.0 is the bottom of the axis, and 1.0 is top of the axis. Bars will be redrawn to show the difference between this and their value.
Description | Example |
---|---|
Here are three copies of a bar chart with the same data:
|
|
This example shows setting a zero
line by using text
formatted data with custom scaling ( The example has values ranging from -60 to 120. The scale is set to -80 to 140, to leave space above and below the bars. |
chd=t:30,-60,50,120,80 |
Compound Charts
You can add lines, candlesticks, and shape markers to a bar chart to make a compound chart. See Compound Charts for more details.
Markers on Specific Bars (cht=bvg
only)
By default, when you draw a chm
marker on a grouped vertical chart, the
marker is drawn on the same series from which it derives its data. If the data is a hidden series, the default behavior is to center the marker on the bar group.
However, with vertically grouped bar charts (type bvg
) you can specify
a placement series that is different from the marker's data series. To do this,
specify the <series_index>
parameter (the third parameter) using
the following syntax: <data_series_index>:<placement_series_index>
.
Note that if you specify a hidden or nonexistent placement series, the marker will be centered horizontally on the group.
The best way to use this feature is to use a hidden series for the marker data, and place the marker on a visible series.
The following examples show the default behavior, with both the data series and placement series the same, and the advanced syntax, specifying a different data and placement series.
Hidden data series, default marker placement | Hidden data series, advanced marker placement |
---|---|
In this example, basic syntax specifies that marker data and placement should be on the same series. Since this is a hidden series, default placement is centered vertically on each group. |
In this example, advanced syntax specifies a different data source and placement series for the markers. Circles use data from hidden series 2 and are placed on series 0; squares use data from hidden series 3 and are placed on series 1. |
The following example shows how to add several different marker types to individual bars in a grouped bar chart. Note how the black circle is centered on the groups, because it specifies a hidden series as the placement series.
chd=t4: // First four series are rendered as bars. Remaining data is hidden.
5,10,15,20,25,30 // Purple bar
10,20,30,40,50,60 // Blue bar
30,40,50,60,70,80 // Olive bar
5,5,5,5,5,5 // Black bar
0,15,25,30,45,55 // Hidden data: Purple circle, blue error bar start
15,30,40,45,55,65 // Hidden data: Blue error bar end
20,35,45,50,55,65 // Hidden data: Yellow error bar start
40,45,55,80,75,85 // Hidden data: Yellow error bar end
chm= // Markers:
o,D000D0,4:0,,10 // Purple circle: data series 4, placement series 0 (purple)
E,00D0D0,4:1,,1:10 // Blue error bars: data series 4, placement series 1 (blue)
E,D0D000,6:2,,1:10 // Yellow error bars: data series 6, placement series 2 (olive)
o,000000,3:4,,10 // Black circle: data series 3, placement 4 (hidden placement series, centered in group)
Standard Features
The rest of the features on this page are standard chart features.