我正在尝试创建一个与TeeChart集成的MonoDroid应用程序,我想有一个活动来保存图表和一些其他组件,如文本视图、按钮等
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>
我使用了测试面板。AddView(tChart1);但那里什么都没有显示,我如何将图表放在MealChartPanel线性布局中?
谢谢,
这是因为您需要指定图表维度。您可以设置绝对像素尺寸或使用LayoutParams,例如:
testpanel.AddView(tChart1, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent));