XamarinAndroidGettingStarted

From Steema Software Reference Wiki
Jump to: navigation, search

Net android.png

Getting started with TeeChart for Xamarin.Android

It’s been some time now since TeeChart for Xamarin.Android was released in August 2012, following the path Xamarin started laying down about one year before. While Xamarin has made huge progress during this time, the corresponding TeeChart version has also evolved and improved correspondingly. If you are reading this, you have probably already got started with Xamarin.Android. We will avoid the Xamarin product details and focus on using TeeChart on them. Xamarin Studio After creating a new blank Android application, the easiest and fastest way is by using the TeeChart version in the Xamarin Component Store. Here’s a Xamarin guide on how to use it. Let’s apply that to TeeChart now. In an Android application, choose Project > Edit Components > Open Component Store (or Get More Components). This will load the component store for you:

ComponentStore.jpg

In the image above, you can see the TeeChart Charting Library as the 5th overall option. You can also find it in the Libraries category or find it with the given search option. Anyway, selecting the TeeChart Charting Library takes you to this screen:

TeeChartComponentStore1.jpg

Besides the product info, getting started link, license, etc. there are two green buttons. They will let you either evaluate the component or purchase it. A couple of things to comment on here. First, the evaluation version is fully functional and the only limitation you’ll experience with it is a watermark over the charts. Secondly,the evaluation and registered versions are also available at www.steema.com. Later on I will explain how to use the components outside the Component Store but now let’s continue with that. To do so I’ll choose the Try button option. After agreeing to the licensing terms, this will add the TeeChart for Xamarin.Android trial version to your project, as an item in the Components folder and also as a TeeChart.Android.dll assembly reference in the References folder. The “references” part is all we will have to take care of to use TeeChart.Android.dll from outside the Component Store. The TeeChart entry in the Components list will also open the corresponding tab in Xamarin Studio’s main window:

TeeChartProjectComponents.jpg

The aforementioned TeeChart tab has 3 sub tabs: Getting Sarted, Samples and Assemblies. Actually, those names are self-explanatory. The first one contains some basic information and code snippets to get you started quickly on developing Android applications with TeeChart. The second one includes sample projects for iOS and Android. The third tab contains information about the assemblies included with the component and their version. Prior to starting to develop our own application, we will try with the Android example by pressing the corresponding button in the Samples tab. Doing so will add the MonoAndroidDemo project to our solution. The example project comes with a reference to the TeeChart.Android.dll we have chosen (trial or registered) and is ready to run on your emulator or device of choice. Now, back to the Getting Started tab, there’s a little Android code snippet which we can copy and paste at the OnCreate method in our Activity:

       protected override void OnCreate (Bundle bundle)
       {
           base.OnCreate (bundle);

Steema.TeeChart.TChart tChart1 = new Steema.TeeChart.TChart(this); Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(); tChart1.Series.Add(bar1); bar1.Add(3, "Pears", Color.Red); bar1.Add(4, "Apples", Color.Blue); bar1.Add(2, "Oranges", Color.Green); Steema.TeeChart.Themes.BlackIsBackTheme theme = new Steema.TeeChart.Themes.BlackIsBackTheme(tChart1.Chart); theme.Apply(); SetContentView(tChart1); }

So now we have our first TeeChart for Xamarin.Android application ready to go.

GettingStartedSample.png

Let me explain what those lines of code exactly mean. We start creating a TChart object, the basic object of the component set, which is the chart container. A Bar series comes after, it’s created and added to the chart component. After that, some bars are added to the bar series: Y values, text labels and bar colors. Afterwards a chart theme is created and applied to the chart to change the overall aspect. Finally, the chart component is added to fill the parent view entirely. Getting a chart into your Android application is as simple as that. If you are no not using the Xamarin Component Store because you are using a TeeChart.Android.dll downloaded directly from Steema it wouldn’be that tmuch different. You just have to manually browse for TeeChart.Android.dll in your hard drive at the References folder in your project: References > right mouse button -> Edit References > .Net Assembly. Here you’ll need to browse for the assembly in your disk and add it to the project.

ManualReference.jpg

Changing from the trial version assembly from the Component Store to the registered version I have on my computer, I now get the same example but without the evaluation watermark.

GettingStartedSampleRegistered.png

Visual Studio There are no substantial differences on the basics of creating Android projects in Xamarin Studio and Visual Basic. As Xamarin explains in the Components Walkthrough article, Component Store is being used the same way in Visual Studio. A Component is added to each project. From there you can access the store with your Xamarin license credentials. Also, manually adding the assembly references to your project works very much the same way.

Summary

Now that you know how to use TeeChart in your C# Android applications, you are all good to start representing your data graphically in Android with C#. TeeChart for Xamarin.Android installers for Windows and Mac OSX, supplied by Steema Software, include some more demos, help files and a number of tutorials completing a wide range of TeeCharting aspects. Also, at the Steema Support forums for registered customers, you’ll find a huge number of questions with examples covering almost all aspects of TeeChart. Non-registered users can post their technical inquiries at StackOverflow tagged with "TeeChart" and the platform/language. If you are a native Java Android developer, Steema Software also has a native component for you, TeeChart Java for Android. Those targeting Android from Embarcadero IDEs, can use the TeeChart VCL/FMX version.