12.3.1 The bchart Package

The bchart package [48] provides the bchart environment

bar drawing commands

The optional argument ⟨options⟩ is a key=value list where the following keys are available:

The maximum x-axis value. (The default is 100.)

The minimum x-axis value. (The default is 0.)

The step size along the x-axis.

For irregular intervals or if rounding errors cause a problem for the step option, this option can be used instead. The value should be a comma-separated list of intervals along the x-axis.

Hides all the tick marks along the x-axis.

Specifies a unit to append to all the values displayed on the chart. The default is empty.

Sets the width of the chart. The default is 8 cm. This setting doesn't change the height of the chart.

Scales both the width and height, maintaining the aspect ratio. (This doesn't change the text size.)

The font declaration used for the text displayed in the bar chart is given by:


This can be redefined using \renewcommand or set to empty to use the document font. The default definition is \sf, which is an obsolete font changing command and may cause issues with some classes such as the KOMA-Script classes. I suggest you redefine \bcfontstyle to use a modern declaration, such as \sffamily. For example:


Within the bchart environment, the bars are displayed using:


where ⟨number⟩ is the bar's value. The optional argument ⟨options⟩ is a key=value list with the following keys:

Sets the text displayed inside the bar (to the right of the y-axis).

Sets the label displayed on the left of the y-axis.

Sets the bar colour.

Hides the bar's value, which by default is displayed to the right of the bar.

Sets the value displayed to the right of the bar. The default is the ⟨number⟩ in the mandatory argument of \bcbar.

You can insert vertical gaps between bars using:


Within the scope of the bchart environment, the standard vertical skips \smallskip, \medskip and \bigskip are redefined in terms of \bcskip and may be used to insert small, medium or large gaps. As with \bcskip, these three commands also have an optional argument. This option only has one key available: label, which specifies a label.

A “free” label is placed to the left of the y-axis at the current location using:


where ⟨text⟩ is the label text. This doesn't add any gap or bar to the chart.

The x-axis can be labelled using:



Here's the data from the pie chart in Example 61 reproduced as a bar chart:


This produces the chart shown in Figure 12.8.

Figure 12.8: A Bar Chart (bchart package)
Image of bar chart. The bars are horizontal with the label to the left of the vertical axis and the value to the right of the bar. The horizontal axis has tick marks below it with values in increments of 5 starting from 0 and ending with 40.

A │ [yellow bar] 5
B │ [cyan bar] 10
C │ [green bar] 15
D │ [pink bar] 30
E │ [orange bar] 40
  0  5  10 15 20 25 30 35 40

End of Image.

Exercise 32. A Bar Chart (bchart package)

Reproduce the bar chart shown in Figure 12.9. (The bar colours are the default setting.) Hint: if you actually try to enter values such as 75000 you are likely to get a “Dimension too large” error, so enter the numbers as one thousandth of the actual value and set the unit key so that the numbers are displayed as shown.

You can download or view the solution to this exercise.

Figure 12.9: Bar Chart (bchart package) Exercise
Image of bar chart. The bars are horizontal and all filled with a pale blue colour. The label is to the left of the vertical axis and the value is to the right of the bar. There is a small vertical gap between each bar. The horizontal axis doesn't have any tick marks, but below it is the label “Company Profits (£)”.

2011/12 │ [horizontal bar] 50,000
2012/13 │ [horizontal bar] 75,000
2013/14 │ [horizontal bar] 60,000
           Company Profits (£)

End of Image.

This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-07-4).

© 2015 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs