Previous to version 3.2, to create an axis tick representing a value such as the average of the plotted data, the value had to be calculated, then, an axis tick was manually added to the axis. This process has now been simplified down to one simple line of code.
Calculated Axis Tick
The following code adds a calculated tick to an axis.
As you can see, this code does not specify any data to perform the calculation on. In this case, the data plotted on the axis is calculated.
A calculation based on only one series of the data shown on an axis is often desired. When this is the case, a single series or any number of series can be specified to base the calculation on.
The following code demonstrates specifying a series:
|To specify multiple series, place them into a series collection which can be specified as a method parameter.|
Using a template
The resulting axis tick will show the calculated value, however, if additional formatting or textual modifications are required, a template can be specified. The '%Value' token in the template will be replaced with the resulting value. The following examples demonstrate template usage.
Chart.YAxis.AddCalculatedTick("Average: %Value", Calculation.Average);
// Resulting Ticks:
// Average: 123
Chart.YAxis.AddCalculatedTick("Average: %Value", Calculation.Average)
' Resulting Ticks:
' Average: 123
Calculated Ticks of Shadow Axes
Calculated axis ticks can also be generated for shadow axes. Despite the data not being bound to the actual axis, a shadow axis will base it's calculations on the parent axis' data.
A common task could be to have an original axis show the scale, and a shadow axis on the other side of the chart can show the calculated axis ticks as shown below.
Axis axisReplica = Chart.XAxis.Calculate("Replica",true,Orientation.Right);
Dim axisReplica As Axis = Chart.XAxis.Calculate("Replica",True,Orientation.Right)