最前面的话:Smobiler是一个在VS环境中使用.Net语言来开发APP的开发平台,也许比Xamarin更方便
一、目标样式
我们要实现上图中的效果,需要如下的操作:
1.从工具栏上的”Smobiler Components”拖动一个PieChart控件到窗体界面上
2.修改PieChart的属性
a.CenterText属性
在表中间显示文字“1236.00 消费金额”,如图1
b.DefaultColors属性
打开集合编辑器,并点击添加,如图2、图3
图1 | 图2 | 图3 |
c.Load事件(添加数据)
VB:
Private Sub TestChart2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim matTable As New DataTable
matTable.Columns.Add("XMember", GetType(String))
matTable.Columns.Add("YMember", GetType(Integer))
For i As Integer = 1 To 4 Step 1
Dim row As DataRow = matTable.NewRow
matTable.Rows.Add(row)
Next
matTable.Rows(0)("XMember") = "餐饮"
matTable.Rows(1)("XMember") = "住宿"
matTable.Rows(2)("XMember") = "长途"
matTable.Rows(3)("XMember") = "通讯"
matTable.Rows(0)("YMember") = 740.0
matTable.Rows(1)("YMember") = 280.0
matTable.Rows(2)("YMember") = 147.0
matTable.Rows(3)("YMember") = 69.0
Me.PieChart1.DataSource = matTable
Me.PieChart1.DataBind()
End Sub
C#:
private void TestChart2_Load(object sender, EventArgs e)
{
DataTable matTable = new DataTable();
matTable.Columns.Add("XMember", typeof(string));
matTable.Columns.Add("YMember", typeof(int));
for (int i = 1; i <= 4; i += 1)
{
DataRow row = matTable.NewRow();
matTable.Rows.Add(row);
}
matTable.Rows[0]["XMember"] = "餐饮";
matTable.Rows[1]["XMember"] = "住宿";
matTable.Rows[2]["XMember"] = "长途";
matTable.Rows[3]["XMember"] = "通讯";
matTable.Rows[0]["YMember"] = 740.0;
matTable.Rows[1]["YMember"] = 280.0;
matTable.Rows[2]["YMember"] = 147.0;
matTable.Rows[3]["YMember"] = 69.0;
this.PieChart1.DataSource = matTable;
this.PieChart1.DataBind();
}
d.XAxisLabelMember属性
绑定X轴的值,如图4
e.YAxisLabelMember属性
绑定Y轴的值,如图5
图4 | 图5 |
二、手机效果显示