ContentsBasic ChartingAdd a grid
Previous: Plot a sine wave | Next: Axis labels

Add a grid

To add a simple grid, just invoke the appendGridX() method -> see the code.

When you run this first version of the hello5 servlet, what you get should look like this.

Here's what we've done:

The <spacing> unit is the denominator of the graph, which is defined by the "minorX" parameter of PdfChart.drawMain(). If the units-per-grid parameter had been "2", the grid would only appear every other spacing unit. If it had been "3", the grid would only appear on every third spacing unit, etc.

One of the annoying things about the chart so far is that the grid is hidden by the data (this may be what you want sometimes). The way to control this is to tell the AreaValueSet to go behind the grid when it is constructed -> see the code

Now the output should look like this. The only difference is that the data is behind the grid. Only line 25 is effected, where the behindGrid parameter is set to "true".

Sine waves have some interesting things happen at the quadrants. Let's add a bold grid over the top -> see the code / output

Why do it this way? Why not specify an absolute value for the grid spacing? ... so that the chart is independent of the rendering! In fact, we can do several renderings with the same data by additional invocations of PdfChart.drawMain() -> see the code / output


ContentsBasic ChartingAdd a grid
Previous: Plot a sine wave | Next: Axis labels