From Steema Software Reference Wiki
Revision as of 14:16, 29 April 2016 by Clive (Talk | contribs) (Axis events)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Net iphone.png

Contents page
Previous | Next

Tutorial4 - Axis Control

TeeChart NET for iOS will automatically define all Axis labelling for you and offers plenty of flexibility to tailor any specific requirements you may have. TeeChart NET for iOS offers true Multiple Axes. These are available at design or run time and offer countless possibilities and flexibility for Axis definition. See the section in this tutorial for more information.

Axes control - Key areas

Axis scales are set automatically when you add Series data to your Chart. You may change from the defaults at design time or at runtime by using Axis properties.

Automatic selects the best axis scale range to fit your data. If you turn Automatic off the scales section will ungrey options and you can change Axis values. Important, remember to select the Axis that you wish to configure.

Random rnd = new Random();  
for(int i = 0; i <= 40; i)  

Setting axis scales by code
You can change the Maximum and Minimum at runtime using this code:

Steema.TeeChart.Axis bottomAxis = tChart1.Axes.Bottom;
bottomAxis.Automatic = false;
bottomAxis.Maximum = 36;
bottomAxis.Minimum = 5;

You may set Axis scale Maximum and Minimum to automatic individually. e.g:

Steema.TeeChart.Axis bottomAxis = tChart1.Axes.Bottom;
bottomAxis.AutomaticMaximum = true;
bottomAxis.AutomaticMinimum = false;
bottomAxis.Minimum = 5;

You may tailor the intervals for the Axis. You may change this by code at runtime:

Steema.TeeChart.Axis bottomAxis = tChart1.Axes.Bottom;
bottomAxis.Increment = 20;
Datetime data 

If your data is datetime, set the increment for the desired increment:

Random rnd = new Random();
DateTime today = DateTime.Today;
TimeSpan oneDay = TimeSpan.FromDays(1);
line1.XValues.DateTime = true;
for(int i = 1; i <= 25; i)
     today = oneDay;

Change the Increment at runtime:

Steema.TeeChart.Axis bottomAxis = tChart1.Axes.Bottom;
bottomAxis.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.TwoDays);

See the AxisLabels.ExactDateTime property for more information about date axis labelling.

Titles are set in the Titles section of the Axis page. You may change the Title text for the Axis and its font and shadow properties. The angle and size of the Title text may also be specified. For runtime see the AxisTitle Class.

See the AxisLabels Class for a resume of Labels properties.


When changing axis label frequency, bear in mind that TeeChart will avoid label overlap according to the setting of the AxisLabels.Separation property. This means that if the label frequency is too high for the labels to fit, then TeeChart will allocate 'best fit'. Changing the label angle and label separation are 2 options that may help you fit the labels you require. See the AxisLabels.Angle property.

Label formats

You may apply all standard number and date formats to Axis labels. At runtime use:

tChart1.Axes.Bottom.Labels.ValueFormat = "#,##0.00;(#,##0.00)";

or for datetime data

tChart1.Axes.Bottom.Labels.DateTimeFormat = "dddd/MMMM/yyyy";

MultiLine labels Axis labels can be displayed as multi-line text instead of a single line of text. Lines are separated using the LineSeparator character ().


bar1.Add(1234, "New" Steema.TeeChart.Texts.LineSeparator "Cars", UIColor.Red.CGColor);  
bar1.Add(2000, "Old" Steema.TeeChart.Texts.LineSeparator "Bicycles", UIColor.Red.CGColor);
tChart1.Panel.MarginBottom = 10;

Example for DateTime labels:
The following will show the Bottom Axis labels in two lines of text, one showing the month and day, and the second line showing the year:

Feb-29     Mar-1  ..
2012        2012 ..

bar1.Add(DateTime.Parse("29/2/2012"), 100, UIColor.Red.CGColor);  
bar1.Add(DateTime.Parse("1/3/2012"), 200, UIColor.Red.CGColor);  
bar1.Add(DateTime.Parse("2/3/2012"), 150, UIColor.Red.CGColor);  
bar1.XValues.DateTime = true;  
tChart1.Axes.Bottom.Labels.DateTimeFormat = "MM/dd hh:mm";
tChart1.Axes.Bottom.Labels.MultiLine = true;  
tChart1.Panel.MarginBottom = 10;

Setting the AxisLabels.MultiLine property to True will automatically split labels in lines where there is a space, effectively dividing the Label into two:
'mm/dd' for the first line
'hh:mm' for the second line  

At run-time you can always split the label into lines programmatically, using the OnGetAxisLabel event:

tchart.GetAxisLabel = new Steema.TeeChart.GetAxisLabelEventHandler(tchart_GetAxisLabel);  

        public void tchart_GetAxisLabel(object sender, Steema.TeeChart.GetAxisLabelEventArgs e)
            if (sender==tchart.chart.Axes.Left)

In the example above, the global "TeeSplitInLines" procedure converts all spaces in "LabelText" to line separators (returns).

The axis AxisLabels.Angle property can also be used with multi-line axis labels.

Customising Axis labels

Further Label control may be obtained by using Axis events. The events permit you to activate/deactivate/change any individual Axis label. The following example modifies each Label, putting a textual phrase in front of the point index value:

            tChart1.Axes.Bottom.Labels.Style = AxisLabelStyle.Mark;

private void tChart1_GetAxisLabel(object sender, Steema.TeeChart.TChart.GetAxisLabelEventArgs e)
            e.LabelText = "Period " Convert.ToString(e.ValueIndex);

See the section entitled [#AxisEvents Axis events] for more information about customising labels with Axis events.

Logarithmic Labels Normal Logarithmic labelling may be set in the following way:

            Random rnd = new Random();
            Steema.TeeChart.Axis leftAxis = tChart1.Axes.Left;
            tChart1.Aspect.View3D = false;
            bar1.Marks.Visible = false;
            for(int i = 0; i <= 100; i)
            bar1.Add(rnd.Next(100) * i);
            leftAxis.LogarithmicBase = 10;
            leftAxis.Logarithmic = true;
            leftAxis.SetMinMax(0, 10000);
            leftAxis.Labels.ValueFormat = "#e 0"; //exponential format 

Labels will be set according to the Logarithmic base (default 10) thus, in this case giving labels at 1, 10, 100, 1000, 10000.

Ticks and Minor

There are 3 tick types and 2 types of Grid. You may change the length, width and colour of each tick and Grid type. Changes can be made to Ticks, their associated Grid and Inner Ticks.

Steema.TeeChart.Axis bottomAxis = tChart1.Axes.Bottom;  
bottomAxis.Ticks.Length = 7;  
bottomAxis.Ticks.Color = UIColor.Green.CGColor;
bottomAxis.MinorTickCount = 10;    

Axis position Axes have a property to modify where each axis is to be located. In this example, the axis is moved 50% of the total Chart width, so it is shown at the chart center:

Steema.TeeChart.Axis bottomAxis = tChart1.Axes.Bottom;
bottomAxis.PositionUnits = PositionUnits.Percent;
bottomAxis. RelativePosition = 50

Additional Axes

Copying axes
TeeChart offers 5 axes to be associated with data Series: Left, Top, Bottom, Right and Depth. When you add a new series to a Chart you may define to which of the axes the Series should be related. You may repeat any one (or all) of the front 4 axes at any place on the Chart by using the Axis Customdraw method. Note that this method  makes a copy of your Axis, it does not add a new Custom Axis. See the next section, Multiple Custom Axes, for more information.

Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line();

Random Rnd = new Random();
_controller.chart.Aspect.View3D = false;
for(int t = 0; t <= 20; t)
line1.Add(t, ((Rnd.Next(100)) 1) - ((Rnd.Next(70)) 1), UIColor.Yellow.CGColor);

_controller.chart.Axes.Left.AxisPen.Color = UIColor.White.CGColor;
_controller.chart.Axes.Bottom.AxisPen.Color = UIColor.White.CGColor;
_controller.chart.Axes.Left.AxisPen.Width = 1;
_controller.chart.Axes.Bottom.AxisPen.Width = 1;
line1.BeforeDrawValues = new Steema.TeeChart.Styles.Series.PaintChartEventHandler(line1_BeforeDrawValues);
Josep: private void line1_BeforeDrawValues(object sender, Steema.TeeChart.Drawing.Graphics3D g)  

int posAxis = 0;
if(_controller.chart.Axes.Left.Maximum > 0)
_controller.chart.Axes.Left.Draw(g.ChartXCenter - 10,g.ChartXCenter - 20,g.ChartXCenter,true);
posAxis = _controller.chart.Axes.Left.CalcYPosValue(10);
_controller.chart.Axes.Bottom.Draw(posAxis 10, posAxis 40, posAxis, true);

The example code above will produce the image below:


Custom axes

In this example, TeeChart will plot the New axes, one horizontal and one vertical in the centre of your Chart. When you scroll the Chart (dragging with right mouse button), the new vertical axis will always remain central to the Chart, the new horizontal axis will move up and down with vertical scrolling. The new axes are exact copies of the default axes.

Multiple Custom Axes
Together with the PositionPercent and stretching properties, it's possible to have unlimited axes floating anywhere on the  chart. Scroll, zoom, and axis hit-detection also apply to custom-created axes. Creating extra axes is possible at runtime via a few lines of code:

Via Code 
            Line line1 = new Line();  
            Line line2 = new Line();
            tChart1.Aspect.View3D = false;
            tChart1.Panel.Gradient.Visible = true;  
            tChart1.Header.Text = "TeeChart Multiple Axes";  

            for(int t = 0; t <= 10; t)              

                line1.Add(Convert.ToDouble(t), Convert.ToDouble(10 t), UIColor.Red.CGColor);  
                if(t > 1)  
                line2.Add(Convert.ToDouble(t), Convert.ToDouble(t), UIColor.Green.CGColor);  

            Axis leftAxis = tChart1.Axes.Left;  

            leftAxis.StartPosition = 0;  
            leftAxis.EndPosition = 50;  
            leftAxis.AxisPen.Color = UIColor.Red. CGColor;  
            leftAxis.Title.Font.Color = UIColor.Red. CGColor;  
            leftAxis.Title.Font.Bold = true;  
            leftAxis.Title.Text = "1st Left Axis";  
//            You are able to then position the new Axis in overall relation to the Chart  
//            by using the StartPosition and EndPosition  properties.  
//            StartPosition=50  
//            EndPosition=100  
//            These figures are expressed as percentages of the Chart Rectangle with 0 (zero)  
//            (in the case of a vertical Axis) being Top. These properties can be applied to  
//            the Standard Axes to create completely partitioned 'SubCharts' within the Chart.  

            Axis axis1 = new Axis(false, false, tChart1.Chart);  

            line2.CustomVertAxis = axis1;  

            axis1.StartPosition = 50;
            axis1.EndPosition = 100;
            axis1.AxisPen.Color = UIColor.Green.CGColor;
            axis1.Title.Font.Color = UIColor.Green.CGColor;
            axis1.Title.Font.Bold = true;
            axis1.Title.Text = "Extra Axis";
            axis1.PositionUnits= PositionUnits.Percent;
            axis1.RelativePosition = 20;

The code above will produce the following Chart

Multiple axes

Options are limitless! We advise caution when using Custom Axes as it is easy to start filling the screen with new axes and to lose track of which one you wish to manage !

Axis events

Axis events offer runtime flexibility to modify Axis Labels and present user interactivity on Axis Clicks.


Can be used to modify Axis Labels. See the OnGetAxisLabel event.



            tChart1.Axes.Bottom.Labels.Style = AxisLabelStyle.Mark;

private void tChart1_GetAxisLabel(object sender, Steema.TeeChart.TChart.GetAxisLabelEventArgs e)

            e.LabelText = "Period " Convert.ToString(e.ValueIndex);

OnGetNextAxisLabel Can be used to decide which Axis Labels should be displayed. See the OnGetNextAxisLabel event. You should use the e.Stop Boolean property to include/exclude Axis Labels.




private void tChart1_GetNextAxisLabel(object sender, Steema.TeeChart.TChart.GetNextAxisLabelEventArgs e)


                e.Stop = false;

                    case 0: e.LabelValue = 5; break;
                    case 1: e.LabelValue = 13; break;
                    case 2: e.LabelValue = 19; break;
                    default: e.Stop = true; break;
End Sub



© 1998-2019 Steema Software SL. All rights reserved.