A barchart widget has several configurable components: coordinate axes, data elements, legend, grid, cross hairs, pens, postscript, and annotation markers. Each component can be queried or modified.
Up to four coordinate axes (two X-coordinate and two Y-coordinate axes) can be displayed, but you can create and use any number of axes. Axes control what region of data is displayed and how the data is scaled. Each axis consists of the axis line, title, major and minor ticks, and tick labels. Tick labels display the value at each major tick.
A special case exists when two or more data points have the same abscissa (X-coordinate). By default, the bars are overlayed, one on top of the other. The bars are drawn in the order of the element display list. But you can also configure the bars to be displayed in two other ways. They may be displayed as a stack, where each bar (with the same abscissa) is stacked on the previous. Or they can be drawn side-by-side as thin bars. The width of each bar is a function of the number of data points with the same abscissa.
barchart pathName ?option value?...
The barchart command creates a new window pathName and makes it into a barchart widget. At the time this command is invoked, there must not exist a window named pathName, but pathName's parent must exist. Additional options may be specified on the command line or in the option database to configure aspects of the graph such as its colors and font. See the configure operation below for the exact details about what option and value pairs are valid.
If successful, barchart returns the path name of the widget. It also creates
a new Tcl command by the same name. You can use this command to invoke
various operations that query or modify the graph. The general form is:
pathName operation ?arg?...
Both operation and its arguments determine the exact behavior of the command. The operations available for the graph are described in the BARCHART OPERATIONS section.
The command can also be used to access components of
the graph.
pathName component operation ?arg?...
The operation, now located after the name of the component, is the function to be performed on that component. Each component has its own set of operations that manipulate that component. They will be described below in their own sections.
# Create a new bar chart. Plotting area is black.
barchart .b -plotbackground black
A new Tcl command .b is created. This command can be used to query and modify
the bar chart. For example, to change the title of the graph to "My Plot",
you use the new command and the configure operation.
# Change the title.
.b configure -title "My Plot"
To add data elements, you use the command and the element component.
# Create a new element named "e1"
.b element create e1 \
-xdata { 1 2 3 4 5 6 7 8 9 10 } \
-ydata { 26.18 50.46 72.85 93.31 111.86 128.47 143.14
155.85 166.60 175.38 }
The element's X-Y coordinates are specified using lists of numbers. Alternately,
BLT vectors could be used to hold the X-Y coordinates.
# Create two vectors and add them to the barchart.
vector xVector yVector
xVector set { 1 2 3 4 5 6 7 8 9 10 }
yVector set { 26.18 50.46 72.85 93.31 111.86 128.47 143.14 155.85
166.60 175.38 }
n.b element create e1 -xdata xVector -ydata yVector
The advantage of using vectors is that when you modify one, the graph is
automatically redrawn to reflect the new values.
# Change the y coordinate of the first point.
set yVector(0) 25.18
An element named e1 is now c