Calculating values for bar charts in LaTeX

The bchart package

If you want to add some bar charts to your latex document you might want to use bchart. This pdf by Tobias Kuhn shows some examples of how to use the package. Description taken from that pdf:

bchart is a LATEX package for drawing simple bar charts with horizontal bars on a numerical x-axis. It is based on the TikZ drawing package. The focus of this package is on simplicity and aesthetics.

Using the package one can display labels, specify the axis range, bar colors or unit of the values.

Calculating values

Unfortunately the package has a drawback. If you use math expressions they will be calculated for the bars but wont their values won't be displayed. In addition you cannot use \pgfmathparse{} to calculate the value for the chart because it will cause errors in displaying the bars.

Which renders:

I believe it is due to internal usage of pgfmath of the package.

There is a simple solution though, using \\pgfmathsetmacro{}{}:

Which renders:

One other way to add bar charts is to use pgfplots package. Here is an example of a bar chart with semi log y axis, labels above the bars and ticks on x axis only for bars:

Which renders:

Visit TeXample.net for some tkiz examples or this for percentage barcharts.

Comments

Popular posts from this blog

Android Virtual Machine and non-ASCII characters the path

Installing FANN on Java project and NativeLibrary.loadLibrary problems with 32bit/64bit

MongoDB and distinct values in arrays