Search code examples
xamarin.androidteechart

TeeChart for Monodroid


I am trying to create an MonoDroid application integrated with TeeChart, i want to have an activity to hold a chart, and some other components, like textview, button, etc. Here is the code,

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

            SetContentView(Resource.Layout.Test);
            var testpanel = FindViewById<LinearLayout>(Resource.Id.MealChartPanel);

            Steema.TeeChart.TChart tChart1 = new Steema.TeeChart.TChart(this);

            Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar();
            tChart1.Series.Add(bar1);

            bar1.Add(3, "Pears", Color.Red);
            bar1.Add(4, "Apples", Color.Blue);
            bar1.Add(2, "Oranges", Color.Green);
            Steema.TeeChart.Themes.BlackIsBackTheme theme = new Steema.TeeChart.Themes.BlackIsBackTheme(tChart1.Chart);
            theme.Apply();

            testpanel.AddView(tChart1);
        }

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
  <LinearLayout
     android:id="@+id/MealChartPanel"
     android:layout_width="fill_parent"
     android:layout_height="100dip"
     android:layout_marginLeft="5dip"
     android:layout_marginRight="5dip">
  </LinearLayout>
</LinearLayout>

i used testpanel.AddView(tChart1); but nothing shows up there, how can i put the chart in the MealChartPanel linearlayout?

thanks,


Solution

  • That's because you need to specify the chart dimensions. You can either set absolute pixel dimensions or use LayoutParams, for example:

      testpanel.AddView(tChart1, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent));