Graph grid GRID command

Commands in this namespace document the graph grid.

GRID is used below as a placeholder for:

GRAPHINST grid

The grid draws horizontal and vertical lines across the plotting area at axis tick positions.

The grid follows the graph’s -renderer and -antialias settings. Cairo preserves its axis mappings, major/minor tick selection, dash pattern, and color. A zero -linewidth remains a one-pixel hairline. Grid labels and all other text remain native.

For example:

graph .g
.g grid configure -hide no -color grey70 -dashes dot

The grid is a single component of the graph. Unlike elements, markers, or pens, there are no named grid objects.

Grid axes

-mapx and -mapy select the axes whose tick positions are used to generate the grid.

-mapx controls the vertical grid lines:

.g grid configure -mapx x

-mapy controls the horizontal grid lines:

.g grid configure -mapy y

Either mapping may be empty to disable grid lines for that direction:

.g grid configure -mapx {}

This is especially useful for bar charts, where the default grid uses only the Y axis.

The axis names refer to graph axes documented by AXIS.

Major and minor grid lines

Grid lines normally follow both major and minor axis ticks.

The -minor option controls whether lines are also drawn at minor tick positions:

.g grid configure -minor no

With -minor no, only major tick positions generate grid lines. With -minor yes, minor tick positions are included as well.

The number and spacing of the grid lines therefore depend on the tick configuration of the mapped axes.

Showing and hiding the grid

The -hide option controls grid visibility:

.g grid configure -hide no

The GRID on, GRID off, and GRID toggle operations provide convenient alternatives:

.g grid on
.g grid off
.g grid toggle

These operations change the same state represented by -hide. For example, after:

.g grid off

querying:

.g grid cget -hide

returns a true value.

Widget-specific defaults

The initial grid configuration depends on the graph widget type.

Widget

-hide

-mapx

-mapy

graph

yes

x

y

stripchart

yes

x

y

barchart

no

empty

y

Thus a graph or stripchart does not initially display its grid, while a barchart initially displays horizontal grid lines associated with its Y axis.

The remaining grid defaults are common to all graph widget types.

Grid options

Option

Database name

Database class

Description

-color color

color

Color

Sets the color used to draw grid lines. The default is grey64, or black on monochrome displays.

-dashes dashes

dashes

Dashes

Sets the dash pattern used to draw grid lines. An empty value selects solid lines. The default is dot. Each numeric list item accepts a Tcl integer expression.

-hide boolean

hide

Hide

Controls whether the grid is displayed. The default is yes for graph, stripchart, and polar widgets and no for barchart widgets.

-linewidth distance

lineWidth

Linewidth

Sets the non-negative width of grid lines. Values 0 and 1 use the native thin-line width. The default is 0.

-mapx axisName

mapX

MapX

Specifies the X axis whose ticks generate vertical grid lines. The axis must exist and must be an X axis. An empty value disables X grid lines. The default is x for graph and stripchart widgets and empty for barchart widgets.

-mapy axisName

mapY

MapY

Specifies the Y axis whose ticks generate horizontal grid lines. The axis must exist and must be a Y axis. An empty value disables Y grid lines. The default is y.

-minor boolean

minor

Minor

Controls whether grid lines are also generated at minor tick positions. The default is yes.

Grid configuration options may also be supplied through Tk’s option database. The resource name is grid and the resource class is Grid.

For example:

option add *Graph.grid.Color grey70
option add *Graph.Grid.Linewidth 1

Copyright (c) George Yashin