About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Latest news 2019-11-04: The giveaway of two signed copies of “Quack, quack, quack. Give my hat back!” has closed and the winning entrants have been selected. Thank you to everyone who took part.


12.3.1 The bchart Package

The bchart package [48] provides the bchart environment

\begin{bchart}[options]
bar drawing commands
\end{bchart}

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

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

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

step
The step size along the x-axis.

steps
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.

plain
Hides all the tick marks along the x-axis.

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

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

scale
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:

\bcfontstyle

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:

\renewcommand*{\bcfontstyle}{\sffamily}

Within the bchart environment, the bars are displayed using:

\bcbar[options]{number}

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

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

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

color
Sets the bar colour.

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

value
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:

\bcskip[options]{length}

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:

\bclabel{text}

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

The x-axis can be labelled using:

\bcxlabel{text}

Example:

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

\begin{bchart}[max=40,step=5]
\bcbar[label=A,color=yellow]{5}
\bcbar[label=B,color=cyan]{10}
\bcbar[label=C,color=green]{15}
\bcbar[label=D,color=pink]{30}
\bcbar[label=E,color=orange]{40}
\end{bchart}

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