Is it possible to display an OxyPlot chart in a ViewCell?

ViliusVilius DKMember
edited July 2015 in Xamarin.Forms

I am using Xamarin.Forms. I have a TableView which contains my ViewCells. In one of the ViewCells I want to display a chart (using OxyPlot). However, I am not able to get any desired results. Below you can see my custom renderer for android, however it doesn't display anything. In the OxyPlot example it is done within onCreate() method in an activity, which allows using AddContentView(). Below is the example:

using OxyPlot.XamarinAndroid;
...

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

    var plotView = new PlotView (this);
    plotView.Model = CreatePlotModel();

    this.AddContentView (plotView,
        new ViewGroup.LayoutParams (ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent));
}

How would the implementation look like using the ViewCellRenderer? If it's not the way to go, please give me some guidelines as at the moment I do not have anything to follow. Please note, that I am able to add a TextView to be displayed within the cell. However, I get nothing when trying to pass PlotView to be displayed. Below you can see my custom renderer for my custom ViewCell class.

protected override Android.Views.View GetCellCore (
            Cell item,
            Android.Views.View convertView,
            Android.Views.ViewGroup parent,
            Android.Content.Context context
        )
        {
            var cell = (OeeHistoryCell)item;

            if (convertView == null)
            {
                convertView = new BaseCellView(Forms.Context);
            }

            var control = ((LinearLayout)convertView);

            var plotView = new PlotView(Forms.Context);
            plotView.Model = CreatePlotModel();

            control.SetMinimumHeight(500);
            control.SetBackgroundColor(Color.Green.ToAndroid());
            control.Orientation = Orientation.Vertical;

            control.AddView(plotView);

            return convertView;
        }
Sign In or Register to comment.