Jaycee Evangelista
Jaycee Evangelista

Reputation: 1127

How to create Charts in Xamarin.Forms?

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));
}

Upvotes: 0

Views: 3317

Answers (3)

Xamarin charts provided by SciChart can be used in Xamarin Forms.

Check out the Xamarin Chart examples here:

enter image description 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

Upvotes: 1

George Papadakis
George Papadakis

Reputation: 1378

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

Upvotes: 5

Sanne
Sanne

Reputation: 427

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

Upvotes: 4

Related Questions