How to create Charts in Xamarin.Forms? - xamarin

I tried creating a Chart in Xamarin.Forms but I wasn't able to show it. I also want to know where am I gonna put this code. Is it in .xaml or in .xaml.cs?
I'm just a beginner in using Xamarin so maybe someone can help me.
This is the code that I to use.
using BarChart;
...
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
var data = new [] { 1f, 2f, 4f, 8f, 16f, 32f };
var chart = new BarChartView (this) {
ItemsSource = Array.ConvertAll (data, v => new BarModel { Value = v })
};
AddContentView (chart, new ViewGroup.LayoutParams (
ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent));
}

There isn't really any Charting Control that comes with Xamarin.Forms. Syncfusion which offers great Charting Controls for Xamarin.Forms come with a community license which offers them for free.
Here is a full example by Xamarin using SyncFusion Chart Controls

I presume this code is in your mainactivty right now, but when working with Xamarin Forms the UI portion is not create there. It is created in the Shared code.
If you really want to use Xamarin forms I would recommend the following steps:
First follow this to get started with and understanding how to use Xamarin Forms : https://developer.xamarin.com/guides/xamarin-forms/getting-started/introduction-to-xamarin-forms/
And then Oxyplot (this is a charting libary for Xamarin Forms): https://github.com/conceptdev/xamarin-forms-samples/tree/master/OxyPlotDemo

Xamarin charts provided by SciChart can be used in Xamarin Forms.
Check out the Xamarin Chart examples here:
While SciChart is a native Xamarin.iOS and Xamarin.Android chart control, it can be used in Xamarin Forms as per this FAQ.
Disclosure: I am the tech lead on the Xamarin Charts project

Related

Xamarin Forms Custom Page Renderer Data Bindings

I'm developing a Xamarin Forms application and I have implemented an IOS custom renderer for a content page.
I generate the page from laying out the native controls programmatically where ListEntry is a subclass of UITextField.
ListEntry entry = new ListEntry(control, new CGRect(x, y, width, height));
entry.BackgroundColor = UIColor.Blue;
view.AddSubview(entry);
I have been using two way data binding to hook up my Xamarin Form content pages to view models but I'm not sure how I go about doing this with custom renderers and native controls. I'm looking for a little guidance on the best way to approach this?
Thanks

Xamarin Forms with native Android Toolbar

We currently have an app designed in Xamarin NativeUI (shared code and Xamarin.Android, Xamarin.UWP etc) are in the process deciding whether Xamain.Forms is mature enough to transition to.
One of my core concerns is that we have a very customized actionbar/toolbar that makes use of Android inbuilt handling of automatically moving items to overflow based on screen size, having overflow menus and submenus, custom controls in place of icons+text.
I have managed to get custom controls and hardcoded overflow items. But I'm not sure if the rest is possible without going native. And if we do need to go native I'm not sure how you would then use Xamarin.Forms and then have a Xamarin.Android ActionBar.
Another fun thinig to add to the equation is that we have to support Android 4.3 so that means using the support library actionbar.
Apologies, the question is a bit rambling but can be broken into 2 specifics:
1) With Xamarin.Forms can items move to or from overflow in toolbar automatically based on screen size available in similar fashion to Android native toolbar?
2) If using Xamarin.Forms can you use a toolbar defined in Xamarin.Android? How?
In addition to #Steve Chadbourne's answer, it's really important to know what page control are you using in PCL of your XF project, if you open the MainActivity.cs file in client android project, you can find by default it codes like this:
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
}
As you can see, there is defined Toolbar which you can find in the Resources/layout folder in client Android project:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
This Toolbar is used by default within some page type control in XF, for example NavigationPage.
For native control of XF, I think it's possible that you didn't notice that Xamarin.Forms.ToolbarItem. It is also rendered like Toolbar and you can set the Order property to ToolbarItem to specify the item to be displayed on primary, secondary or default toolbar surfaces.
For custom renderers, it's possible that you can refer to this blog: Xamarin Forms - ContentPage with SearchBar in the Navigation bar.
Don't know which is the best choice for you, but I want to explain to your two questions. XF is like a UI toolkit, all controls it has are created based on the native SDK, means all controls are renderered as a matching native control so it can be used in native platform. So if a XF control is rendered as Toolbar in Android platform, the behavior should be the same as normal Toolbar in native Android, BUT like we customize the renderers, when the XF control is created, many properties are hard coded in its code, which may have effect the result here. If you meet such problem, I suggest to read the open source on Github.
For your last question:
If using Xamarin.Forms can you use a toolbar defined in Xamarin.Android? How?
You can either using custom renderers or directly modify the code in Toolbar.axml in native client Android project.
This should be possible in Xamarin Forms using a custom renderer.
You are one step ahead in that you understand what you want to do and how to do it in Xamarin Native.
Here is an overview on custom renderers.
Here is a link to a very basic navigation page custom renderer for Android. You should be able to expand it to include the native Android code you require.
Be aware that you probably need to override NavigationPageRenderer if you are using app compat to support earlier versions of Android.

Create bottom toolbar using xamarin form for android and iOS

There are good numbers of post of this but not of them are simple one. One of them is below one which is look simple https://developer.xamarin.com/recipes/ios/content_controls/navigation_controller/add_a_nav_bar_bottom_toolbar/
I am new to xamarin and currently using xamarin form to develope an cross plate form app. It looks above example is using xamarin native not xamarin form? Can same example will work for xamarin form? Or for this kind of UI manipulation xamarin native is better than xamarin form. As i am new to xamarin, should i focus on xamarin native instead of xamarin form for serious app development.
Thanks,
#paul
Please click here for Bottom Navigation Bar for Xamarin Forms.
This will look like below:
You could build it on your own with a ControlTemplate.
No CustomRenderer is needed.
https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/templates/control-templates/creating/

Is there any teritory chart control available on xamarin forms / xamarin android

We are trying to present territory map view with different controls in android and iOS platform using xamarin.forms or Xamarin Native. Is there any map control avaialble to present territory map view in xamarin forms?
It looks like Syncfusion has something similar to what you want in their Maps

Skia view element in xamarin.forms

I'm trying to draw new elements/images via the new skiasharp library for xamarin forms.
I got the samples working but they only change the full content page with the new canvas.
So my question would be how to implement a single view which can be placed in any place in another content page. Does anyone have experiences with skia?
How do I choose the canvas? Do I have to overwrite an existing Image or similar?
Thanks for you help.
Sure, and there is a view which you are looking for: SkiaView.
It inherited from Xamarin.Forms.View and contains some properties such as HeightRequest or Scale.
I suppose you are interested in these classes:
SkiaView
ISkiaViewController
iOS - SkiaViewRenderer
iOS - NativeSkiaView
Android - SkiaViewRenderer
Android - NativeSkiaView
EDIT:
Finally there is a NuGet package with Xamarin.Forms support: SkiaSharp.Views.Forms 1.54.1-beta1. Samples are available in SkiaSharp repository.

Resources