Important changes into the new TeeChart NET for Xamarin.Forms Release

We’ve just released a new TeeChart NET for Xamarin.Forms version 4.1.2018.01040.
If you’re a registered customer, you can download it directly trought the Customer Area page, in the other case, you can always download a Trial version at https://www.steema.com/downloads/forms or install it throught Nuget Package at : https://www.nuget.org/packages/Steema.TeeChart.NET.Xamarin.Forms.Eval/

This maintenance Release version includes important changes that should take in consideration. See below an explanation :

1) Now it’s easier to integrate a Chart into your APP, as the custom renderers and ChartView class is already integrated into the TeeChart NET for Xamarin.Forms assemblies. This means you do not have to add extra files to your new projects in order to use the Chart component.

Here the steps to add a Chart component into your APP :

– Create a Xamarin.Forms project.
– Add the TeeChart.PCL.dll assembly as reference to the PCL project.
– Add the TeeChart.PCL.dll and TeeChart.PCL.Android.dll assemblies to the PCL Android project.
– Add the TeeChart.PCL.dll and TeeChart.PCL.iOS.Unified.dll assemblies to the PCL iOS project.
– Add the TeeChart.PCL.dll and TeeChart.PCL.UWP46.dll assemblies to the PCL UWP project.

– Now you’ve two options :

1) Add the Chart component throught xaml code, at the xaml page. Code example :

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="<a href="http://xamarin.com/schemas/2014/forms" target="_blank" rel="noreferrer noopener">http://xamarin.com/schemas/2014/forms</a>"
xmlns:x="<a href="http://schemas.microsoft.com/winfx/2009/xaml" target="_blank" rel="noreferrer noopener">http://schemas.microsoft.com/winfx/2009/xaml</a>"
xmlns:local="clr-namespace:ChartViewIntegrated"
xmlns:charting="clr-namespace:Steema.TeeChart;assembly=TeeChart.PCL"
x:Class="ChartViewIntegrated.MainPage">

<Label Text="Welcome to Xamarin Forms!"
VerticalOptions="Center"
HorizontalOptions="Center"/>

<StackLayout x:Name="PageLayout">

<!-- /* Create TeeChart ChartView by using xaml code -->
<charting:ChartView x:Name="BarChart"
HeightRequest="300"
WidthRequest="450">
</charting:ChartView>

</StackLayout>
</ContentPage>

2) Add the Chart component via CSharp code, at the .cs code class. Code example :

/* Create ChartView by code at ContentPage */
ChartView BarChart = new ChartView();

BarChart.WidthRequest = 300;
BarChart.HeightRequest = 300;

Content = new StackLayout
{
Children =
{
BarChart
},
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
};

// Then you only have to start configuring the Chart via cs code, i.e :

BarChart.Chart.Series.Add(new Bar());
BarChart.Chart.Series[0].FillSampleValues(3);
BarChart.Chart.Panel.Gradient.Visible = false;
BarChart.Chart.Panel.Color = Color.Aquamarine;
BarChart.Chart.Invalidate();

– IMPORTANT! : Due to the way that Xamarin.Forms iOS works, it only looks at loaded assemblies, meaning that as TeeChart uses a custom ChartViewRenderer (now intregrated into the iOS assembly), in order that the renderer work, we’ll need to add the following line of code just before Xamarin.Forms.Init is called (normally in the AppDelegate.cs file). :

Steema.TeeChart.TChart.Init();

Remember, this is only required for the Xamarin.Forms iOS project.

You can find an example of use at the Steema Github page :
https://github.com/Steema/teechart-xamarin-forms-samples/tree/master/ChartViewIntegrated

Enjoy adding Charts to your Xamarin.Forms APPs.

 

Leave a Reply

Your email address will not be published. Required fields are marked *