ContentsChartingScaling
Previous: Charting | Next: Rendering options

Scaling

The first topic to be demystified is how scaling works. The way that the horizontal (independent) axis is scaled is different than the vertical axis. I apologize in advance to my mathematically inclined readers for whom this topic may seem pedantic, colloquial, and unnecessary.

Horizontal Scaling

The horizontal (or X) axis represents a range of values that we are interested in viewing. Usually (but not always) this range is evenly divided and increases in value from left to right.

Value sets are superimposed onto this axis. The value sets represent data which are dependent on the horizontal axis values.

Scaling the horizontal values is done as required to map the entire array of data onto the width of the chart, as specified by the width parameter of the PdfChart.drawMain() method.

In other words, if you use a provided ValueSet, all of your data will be automatically scaled to fit the width of the chart on the horizontal axis.

An important ramification of this technique is that - as far as the horizontal axis is concerned - you must provide your data at regular intervals.

It's also important to remember to be careful not to try to compare apples to oranges. For most purposes, your chart will be useless if you do. The data values provided for each of your value sets must be representative of the exactly same range on the X axis. For example, if the X axis represents a range of time, it would be confusing to the point of worthless to try to show a set of values representing several seconds superimposed on other sets of values representing days or years.

Vertical Scaling

Whereas the X axis should represent the same range for all value sets, it is very common for the vertical (or Y) axis to show different ranges. This is because you are deliberately comparing apples to oranges on some common attribute: their X axis values. Often, this common attribute is some measurement of time (for example, "what will each of several things do over a span of 15 seconds").

In order to get disparate values to appear in a superimposed fashion, it is necessary to manually apply a logical scaling. Physical scaling to fit the chart to the height specified in PdfPage.drawMain() will still happen automatically, analogous to the way that the horizontal axis is mapped to the width.

The logical vertical scaling of values is often different for each set of values. The unit of measurement may even be different. In many ways, this is the value of a chart... it lets you see if their is an unknown correlation between different factors which are acquired through different measurements.

To set the logical scale of a set of values, invoke ValueSet.setRange(). The minValue / maxValue range should usually encompass the actual values of the provided data, and if it doesn't you may not see anything; because out-of-range data is clipped at the chart border. The baseValue is the offset to apply to the range in order to shift the location of zero.

Here are three ValueSets which represent the same data using different vertical scalings. code / output


ContentsChartingScaling
Previous: Charting | Next: Rendering options