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 for some tkiz examples or this for percentage barcharts.


Popular posts from this blog

MongoDB and distinct values in arrays

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

Creation method in Mongoose.js, alternative to custom constructor or hooks