Search Locate Previous Next Contents

ch.Bar – barcharts

Accepts an array of numbers and plots a barchart according to the current settings.

ch.Bar mat

The axis is always uniform, and is unlabelled unless you set the axis labels explicitly. If you need to position the bars in the x-direction, use ch.XBar instead.

Default (grouped) barchart

BMAT„3 2½2 1 6 4 8 10
ch.Set('style' 'Boxed,ForceZero,Values')
ch.Set('Head' 'Barchart')('Key' 'First,Second')('Xlab' 'UK,Europe,Export')
ch.Set'kstyle' 'boxed,vertical'
ch.Bar BMAT ª ch.WriteKey 0.75 9
PG„ch.Close

The default barchart style (multiple bar or 'grouped' ) is shown here. A table (array of arrays) is taken to represent categories of data, with one reading per row, or you can use a category variable to split data from a database table. The bars are plotted in groups, with extra space between each group. Use the gap and groupgap properties to change the spacing.

Stacked barchart

ch.Set('style' 'Boxed,ForceZero,Relative,Stacked,Values')('Head' 'Stacked Bar')
ch.Set('Ycap' 'Share')('Ystyle' 'Atend')('Key' 'First,Second')('Xstyle' 'Plain')
ch.Set'Values' 'UK,Europe,Export,Other'
ch.Bar BMAT
PG„ch.Close

This is a composite barchart, with relative data. The bars are plotted as a stack, with automatic accumulation of the values. To omit the bottom bar of each stack, include the keyword ‘floating’ in the chart style.

Horizontal barchart

ch.Set('style' 'Boxed,ForceZero,Relative,hbar,cbar')('Head' 'Horizontal Bar')
ch.Set 'mleft' 32
ch.Set'YLab' 'UK,Europe,Export,Other'
ch.Bar BMAT
PG„ch.Close

This illustrates a typical horizontal barchart, in this case drawn as a composite bar. In general you will need to increase the left-hand margin to allow space for the bar labels. The grouped and floating styles also work as you would expect. If you use value-labels on horizontal bars they are drawn at the left/right end of the bar depending on which direction the bar is drawn from the Y-axis or baseline. See the Population example in the collection of barcharts.

See also ...
ch.Xbar – bar charts with a defined x-axis
Four Barcharts on One Page
Barchart style


Continue to: ch.Boxplot – box and whisker charts
© Copyright Causeway Graphical Systems Ltd 2003