TeeChart NET for iOS and Xamarin.iOS Unified API

As you know the TeeChart NET for iOS have been available since the first MonoTouch version created by Xamarin team. The TeeChart product allows to add professional Charts to your apps easily.

With a very few lines of code you can create the Chart, customize it, set a DataSource for the data and add as a View to the app. You just need to reference to the TeeChart.IOS dll and start working with it. Here you can find an article which shows how to display data from SQLite database into the Chart. This all using a Classic Xamarin iPnone project and the MonoTouch API.

Now Xamarin has introduced the new Xamarin.iOS Unified API. This new api allow to support 32 and 64 bit applications with the same binary. See more info about the Unified API here.

In order to continue supporting all the available Xamarin options, Steema has prepared the new TeeChart NET for Xamarin.iOS Unified version. Now both (the Classic and UInified versions) are included into the TeeChart NET for Xamarin.iOS product, so you can decide which one to use depending on your needs.

You can download the new installer at the customers download page or at the Evaluation versions page.

Here I’m going to show how to create a small dashboard application which uses several Charts on it by using the new Xamarin.iOS Unified and the TeeChart.iOS.Unified versions.

All from the Xamarin Studio IDE.

1) Creating the new Xamarin.iOS app from Xamarin Studio :
Open Xamarin Studio and go to File -> New -> Solution and then select c# -> iOS -> Unified API -> iPhone -> Single View Application.

TeeChartNET_IOS_Unified_1
2) Adding the TeeChart NET for Xamarin.iOS reference to the project :
Right click over the Project references and click “Add references”. Find the TeeChart.iOS.Unified.dll on your hard disk and add it to the the project references.

TeeChartNET_IOS_Unified_2
3) Adding code to the App’s RootViewController :
In order to add some Charts to our application we have to add the using Steema.TeeChart to the top of the unit :

using Steema.TeeChart;
Then create and customize the Charts inside the main View. First we define all the Chart View object we’re going to use, and also an image which will be used to load the logo.


TChart chart1;
TChart chart2;
TChart chart3;
TChart chart4;
UIImageView imageview;

Inside the ViewDidLoad method we’ll create all the Charts, create the Series we want to use and set the specific aspect and features for each Chart. We’ll add the following code :


public override void ViewDidLoad()
{
base.ViewDidLoad();

// Create the Chart View objects
chart1 = new TChart();
chart2 = new TChart();
chart3 = new TChart();
chart4 = new TChart();

// Setting specific frame for each Chart
CoreGraphics.CGRect r1 = this.View.Frame;
r1.Height = r1.Height / 4;
r1.Y = (r1.Height*3)-50;
chart1.Frame = r1 ;

CoreGraphics.CGRect r4 = this.View.Frame;
r4.Height = r4.Height / 4;
r4.Y = (r4.Height*2)-50;
chart4.Frame = r4 ;

CoreGraphics.CGRect r2 = this.View.Frame;
r2.Height = r2.Height / 2 - 50;
r2.Width = r2.Width / 2;
r2.Y = 0;
chart2.Frame = r2 ;

CoreGraphics.CGRect r3 = this.View.Frame;
r3.Height = r3.Height / 2 - 50;
r3.Width = r3.Width / 2;
r3.X = r3.Width;
r3.Y = 0;
chart3.Frame = r3 ;

// Adding Series and features for Chart 1
chart1.Series.Add (new Steema.TeeChart.Styles.Volume ());
chart1.Series [0].FillSampleValues ();
chart1.Aspect.View3D = false;
chart1.Axes.Bottom.Grid.Visible = false;
chart1.Legend.Visible = false;
chart1.Axes.Left.Visible = false;
chart1.Panel.Gradient.Visible = false;
chart1.Panel.Color = UIColor.Black.CGColor;
chart1.Walls.Back.Transparent = true;
chart1.Legend.Visible = false;
chart1.Axes.Bottom.Labels.Font.Color = UIColor.FromRGB (220, 220, 220).CGColor;

// Adding Series and features to the Chart 2
Steema.TeeChart.Styles.CircularGauge gauge1 = new Steema.TeeChart.Styles.CircularGauge ();
chart2.Series.Add (gauge1);
chart2.Axes.Left.Labels.Font.Size = 5;
gauge1.Frame.Width = 15;
gauge1.Ticks.VertSize = 3;
gauge1.Center.Shadow.Visible = false;
gauge1.Axis.AxisPen.Visible = false;
gauge1.FaceBrush.Gradient.Visible = false;
gauge1.FaceBrush.Color = UIColor.FromRGB(220,220,220).CGColor;
gauge1.Hand.Color = UIColor.FromRGB (255, 65, 56).CGColor;
gauge1.Hand.Gradient.Visible = false;
gauge1.Hand.Shadow.Visible = false;
gauge1.Axis.AxisPen.Visible = false;
gauge1.Value = 75;
gauge1.Ticks.VertSize = 3;
chart2.Panel.Gradient.Visible = false;
chart2.Panel.Color = UIColor.Black.CGColor;
chart2.Panel.MarginTop = 0;
chart2.Panel.MarginLeft = 0;
chart2.Panel.MarginBottom = 0;
chart2.Panel.MarginRight = 0;

// Adding Series and features to the Chart 3
Steema.TeeChart.Styles.CircularGauge gauge2 = new Steema.TeeChart.Styles.CircularGauge ();
chart3.Series.Add (gauge2);
chart3.Axes.Left.Labels.Font.Size = 5;
gauge2.Frame.Width = 15;
gauge2.Ticks.VertSize = 3;
gauge2.Axis.AxisPen.Visible = false;
gauge2.Center.Shadow.Visible = false;
gauge2.FaceBrush.Gradient.Visible = false;
gauge2.FaceBrush.Color = UIColor.FromRGB(220,220,220).CGColor;
gauge2.Hand.Color = UIColor.FromRGB (255, 65, 56).CGColor;
gauge2.Hand.Gradient.Visible = false;
gauge2.Hand.Shadow.Visible = false;
gauge2.Axis.AxisPen.Visible = false;
gauge2.Value = 50;
gauge2.Ticks.VertSize = 3;
chart3.Panel.Gradient.Visible = false;
chart3.Panel.Color = UIColor.Black.CGColor;
chart3.Panel.MarginTop = 0;
chart3.Panel.MarginLeft = 0;
chart3.Panel.MarginBottom = 0;
chart3.Panel.MarginRight = 0;

// Adding series and features for the Chart 4
chart4.Series.Add (new Steema.TeeChart.Styles.Line ());
chart4.Series.Add (new Steema.TeeChart.Styles.Line ());
chart4.Series.Add (new Steema.TeeChart.Styles.Line ());
chart4.Series [0].FillSampleValues (20);
chart4.Series [1].FillSampleValues (20);
chart4.Series [2].FillSampleValues (20);
chart4.Series [0].Marks.Visible = false;
chart4.Series [1].Marks.Visible = false;
chart4.Series [2].Marks.Visible = false;
(chart4.Series [0] as Steema.TeeChart.Styles.Line).LinePen.Width = 3;
(chart4.Series [1] as Steema.TeeChart.Styles.Line).LinePen.Width = 3;
(chart4.Series [2] as Steema.TeeChart.Styles.Line).LinePen.Width = 3;
chart4.Aspect.View3D = false;
chart4.Axes.Bottom.Increment = 3;
chart4.Panel.Gradient.Visible = false;
chart4.Panel.Color = UIColor.Black.CGColor;
chart4.Walls.Back.Transparent = true;
chart4.Legend.Visible = false;
chart4.Axes.Left.Visible = false;
chart4.Axes.Botto.Labels.Font.Color = UIColor.FomRGB (220, 220, 220.CGColor;

// Adding Chart views to the main View
this.View.AddSubview(chart1);
this.View.AddSubview(chart2);
this.View.AddSubview(chart3);
this.View.AddSubview(chart4);

// Setting general properties for alll the Charts
chart1.Header.Visible = false;
chart2.Header.Visible = false;
chart3.Header.Visible = false;
chart4.Header.Visible = false;

this.View.BackgroundColor = UIColor.Black;

// Adding logo to the App
imageview = new UIImageView (UIImage.FromBundle ("logo.png"));
CoreGraphics.CGRect rimage = new CoreGraphics.CGRect(95,this.View.Frame.Height-50,this.View.Frame.Width/2-30,50);

imageview.Frame = rimage;
this.View.AddSubview (imageview);
}

Before to try to cmpile and run the app, we’ll have to add the “logo.png” image at the “Resources” folder of our project.

Once this has been done, we can try to run our application, and the result should look like the following image :

TeeChartNET_IOS_Unified_3

 

You can download the source code of this example here.