12.3.1 ⁑The bchart Package
The bchart package [48] provides the bchart
environment
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.)
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:
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:
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:
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.
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.
This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-07-4).