<--previous | contents | next-->

# Getting Started

This section gives a quick overview of the features of the PyGDChart library by working through a simple example. We first show the example program, and the graph it produces, in full. Then we proceed with a line-by-line analysis, introducing the basic workings of PyGDChart as we go along.

## The Code

`

    import gdchart

    x = gdchart.Bar3D()
    x.width = 250
    x.height = 250
    x.xtitle = "Weekday"
    x.ytitle = "Percentage"
    x.title = "Example Graph"
    x.ext_color = [ "white", "yellow", "red", "blue", "green"]
    x.setData([20, 100, 80, 30, 50])
    x.setLabels(["Mon", "Tue", "Wed", "Thu", "Fri"])
    x.draw("simple.png")

`

## Explanation

### Choosing a Chart Class

`

    x = gdchart.Bar3D()

`

The PyGDChart library is based around a number of chart classes, each of which represents a different chart style. The first step in using PyGDChart is usually to instantiate one of these classes. In this case, we will be drawing a 3D bar graph.

### Setting Options

`

    x.width = 250
    x.height = 250
    x.xtitle = "Weekday"
    x.ytitle = "Percentage"
    x.title = "Example Graph"
    x.ext_color = [ "white", "yellow", "red", "blue", "green"]

`

Although they look like simple object attributes, PyGDChart options are actually "smart" properties. Whenever you assign to, or retreive the value of, an option, a certain amount of checking and conversion code is run. This allows us to ensure that values assigned to options are appropriate - for instance, we can prevent a user from assigning a string to an option when the underlying C library expects an integer.

"Smart" options can also make things more convenient by performing some types of automatic data conversion. Note that the code snippet above uses descriptive names to specify colours. In the underlying library, however, colours are stored as integers - colour names are converted to the appropriate integer values on assignment. PyGDChart's colour handling capabilities are discussed in greater depth later in this manual.

### Data and Labels

`

    x.setData([20, 100, 80, 30, 50])

`

Each chart type has a .setData() method, but different chart types may require different data formats. Bar graphs, like the one in the example, can be specified using one or more lists of values. If were drawing a floating bar graph, however, the data format would be more complex, since we would have to specify both the upper and lower bounds for every bar. The data requirements for the various chart types are discussed in the appropriate sections elsewhere in this manual.

`

    x.setLabels(["Mon", "Tue", "Wed", "Thu", "Fri"])

`

The .setLabels method is used to specify the labels that appear on the X axis of a graph. In order to avoid ambiguity, PyGDChart ensures that the number of labels conforms with the number of data points along the X axis.

<--previous | contents | next--> | (12/31/03)

PyGDChart User's Manual