A Calculated axis is a Shadow Axis that mimics another axis that already exists but with a change in behavior.
The different behavioral changes and forms of shadow axes are:
- Numeric Unit Conversion
- Time Interval Conversion
- Custom tick label manipulation delegate method
- Completely custom replica axis.
|Calculated axes do not fill alternating grid areas.|
.netCHARTING is equipped with calculations for converting between 1092 different units. If you have an axis with a scale that represents some measure, it can be easily converted to another unit. For example feet to inches and so on.
The process for adding a calculated axis is simple:
- Instantiate a calculated axis by calling the Calculate method of an existing axis.
- Add it to the Chart.AxisCollection collection.
Axis inchAxis = Chart.YAxis.Calculate("Inches",Length.Feet, Length.Inch);
Dim inchAxis As Axis = Chart.YAxis.Calculate("Inches",Length.Feet, Length.Inch)
That is all. The axis will automatically show up on the chart by the original axis.
|Do not add axes to AxisCollection that are not calculated axes. See Axis Tutorial > Multiple Axes for information on how additional axes can be used.|
There is another feature worth discussing. The new converted unit axis will by default take the parent axis ticks and convert them to the specified unit. The refresh scale option will allow the axis to come up with its own intervals. They will not match the parent axis tick positions exactly but will behave as if it is the original axis. This option is specified in the Calculate method as a parameter and illustrated below.
Time Interval Conversion
This type of conversion allows the resulting axis to show different time intervals than the original axis. For example, the first axis can show days and the calculated axis can show weeks.
Chart.XAxis.TimeInterval = TimeInterval.Days;
Chart.XAxis.Label.Text = "Days";
Chart.XAxis.TimeInterval = TimeInterval.Days
Chart.XAxis.Label.Text = "Days"
Custom Tick Label Manipulation Method
The third conversion requires a custom delegate method that takes a string and returns a processed string. This gives you full control over the axis tick label text if necessary.
|To only show the calculated axis on the chart and not it's parent, use ParentAxis.Clear() |
to make it disappear as shown in the customFunction.aspx sample.
[C#]Axis axisReplica = Chart.XAxis.Calculate("Replica");
[Visual Basic]Dim axisReplica As Axis = Chart.XAxis.Calculate("Replica")
Some possible uses of this type of shadow axis are shown in the following samples.
After reviewing the above samples you will see that this feature can be useful, however, don't limit yourself to the demonstrated possibilities. The dynamic nature of this feature allows for countless different ways to better describe your data you're plotting.
Axis Calculated Ticks