Quantcast
Viewing all articles
Browse latest Browse all 76418

Getting an Exception while using Xamarin.Forms.Labs.Charting

I'm using the following code for displaying the bar chart and Line chart in single chart

using System;
using Xamarin.Forms;
using Xamarin.Forms.Labs.Charting.Controls;

namespace BarChart
{
public class BarChartExample : ContentPage
{
public BarChartExample ()
{
Series firstBarSeries = new Series
{
Color = Color.Red,
Type = ChartType.Bar
};
firstBarSeries.Points.Add(new DataPoint() { Label = "Jan", Value = 25});
firstBarSeries.Points.Add(new DataPoint() { Label = "Feb", Value = 40});
firstBarSeries.Points.Add(new DataPoint() { Label = "March", Value = 45});

        Series secondBarSeries = new Series
        {
            Color = Color.Blue,
            Type = ChartType.Bar
        };
        secondBarSeries.Points.Add(new DataPoint() { Label = "Jan",   Value = 30 });
        secondBarSeries.Points.Add(new DataPoint() { Label = "Feb",   Value = 35 });
        secondBarSeries.Points.Add(new DataPoint() { Label = "March", Value = 40 });

        Series lineSeries = new Series
        {
            Color = Color.Green,
            Type = ChartType.Line
        };
        lineSeries.Points.Add(new DataPoint() { Label = "Jan",   Value = 27.5 });
        lineSeries.Points.Add(new DataPoint() { Label = "Feb",   Value = 37.5 });
        lineSeries.Points.Add(new DataPoint() { Label = "March", Value = 42.5 });

        Chart chart = new Chart()
        {
            Color = Color.White,
            WidthRequest = 450,
            HeightRequest = 750,
            Spacing = 10
        };
        chart.Series.Add(firstBarSeries);
        chart.Series.Add(secondBarSeries);
        chart.Series.Add(lineSeries);

        Content = chart;
    }
}

}

Getting the Exception : An exception was thrown by the type initializer for Xamarin.Forms.Labs.Charting.Controls.Series ---> System.MissingMethodException: Method 'BindableProperty.Create' not found.

I have added reference Xamarin.Forms.Labs.Charting in Droid Project.

and added new Xamarin.Forms.Labs.Charting.Droid.Controls.ChartRenderer (); in MainActivity.cs

Please correct me..


Viewing all articles
Browse latest Browse all 76418

Trending Articles