经过我们测试发现我们给C1LineChart UI 传递两类数据源,dataset(datatable) 或datareader,然后绑定X,Y就可以显示数据了。但是我们往UI传递的是含有实体类的泛型集合,泛型集合不包含列名,所有我们还得重新在UI把泛型集合制作成datatable,然后绑定X,Y。这样很奇怪,很麻烦。我们希望葡萄城可以针对此问题,增加控件属性,或者帮我们写一个方法,当我们传进去一个泛型集合后自动返回此集合对应的datatable。我们也正在写此方法。我们希望找到一个最好的解决方案。
protected void Button2_Click(object sender, EventArgs e)
{
C1.Web.Wijmo.Controls.C1Chart.LineChartSeries s = null;
s = new C1.Web.Wijmo.Controls.C1Chart.LineChartSeries();
List<Class1Entity> ListClass1Entity = new List<Class1Entity>();
Class1DAL class1DAL = new Class1DAL();
ListClass1Entity = class1DAL.SelectASPTESTTtrend(DropDownList1.Text, DropDownList2.Text);
DataTable dtzhkkl = new DataTable();
dtzhkkl.Columns.Add("REPORTDATE", typeof(string));
dtzhkkl.Columns.Add("REPORTHOUR", typeof(int));
dtzhkkl.Columns.Add("DATA", typeof(double));
dtzhkkl.Columns.Add("NAME", typeof(string));
DataTable dtxxzjpw = new DataTable();
dtxxzjpw.Columns.Add("REPORTDATE", typeof(string));
dtxxzjpw.Columns.Add("REPORTHOUR", typeof(int));
dtxxzjpw.Columns.Add("DATA", typeof(double));
dtxxzjpw.Columns.Add("NAME", typeof(string));
DataTable dtxkzjcl = new DataTable();
dtxkzjcl.Columns.Add("REPORTDATE", typeof(string));
dtxkzjcl.Columns.Add("REPORTHOUR", typeof(int));
dtxkzjcl.Columns.Add("DATA", typeof(double));
dtxkzjcl.Columns.Add("NAME", typeof(string));
for (int i = 0; i < ListClass1Entity.Count; i++)
{
if (ListClass1Entity.NAME == "综合块矿率")
{
DataRow dr = dtzhkkl.NewRow();
dr["REPORTDATE"] = ListClass1Entity.REPORTDATE;
dr["REPORTHOUR"] = ListClass1Entity.REPORTHOUR;
dr["DATA"] = ListClass1Entity.DATA;
dr["NAME"] = ListClass1Entity.NAME;
dtzhkkl.Rows.Add(dr);
}
if (ListClass1Entity.NAME == "选矿总精品位")
{
DataRow dr = dtxxzjpw.NewRow();
dr["REPORTDATE"] = ListClass1Entity.REPORTDATE;
dr["REPORTHOUR"] = ListClass1Entity.REPORTHOUR;
dr["DATA"] = ListClass1Entity.DATA;
dr["NAME"] = ListClass1Entity.NAME;
dtxxzjpw.Rows.Add(dr);
}
if (ListClass1Entity.NAME == "选矿总精产量")
{
DataRow dr = dtxkzjcl.NewRow();
dr["REPORTDATE"] = ListClass1Entity.REPORTDATE;
dr["REPORTHOUR"] = ListClass1Entity.REPORTHOUR;
dr["DATA"] = ListClass1Entity.DATA;
dr["NAME"] = ListClass1Entity.NAME;
dtxkzjcl.Rows.Add(dr);
}
}
C1LineChart5.DataSource = dtzhkkl;
C1.Web.Wijmo.Controls.C1Chart.C1ChartBinding cb = new C1.Web.Wijmo.Controls.C1Chart.C1ChartBinding();
cb.XField = "REPORTHOUR";
cb.YField = "DATA";
C1LineChart5.DataBindings.Add(cb);
C1LineChart5.DataBind();
C1LineChart4.DataSource = dtxxzjpw;
C1.Web.Wijmo.Controls.C1Chart.C1ChartBinding cb1 = new C1.Web.Wijmo.Controls.C1Chart.C1ChartBinding();
cb1.XField = "REPORTHOUR";
cb1.YField = "DATA";
C1LineChart4.DataBindings.Add(cb1);
C1LineChart4.DataBind();
C1LineChart3.DataSource = dtxkzjcl;
C1.Web.Wijmo.Controls.C1Chart.C1ChartBinding cb2 = new C1.Web.Wijmo.Controls.C1Chart.C1ChartBinding();
cb2.XField = "REPORTHOUR";
cb2.YField = "DATA";
C1LineChart3.DataBindings.Add(cb2);
C1LineChart3.DataBind();
}
}
将泛型集合转成对应datatable方法在网上找到了一个,测了一下也挺好用的,不用自己写了,就是利用反射技术。主要我们现在是用的三层架构+接口+工厂,我们往UI传递的都是含有实体类的泛型集合,再重新制作一个DATATABLE给控件,这样很奇怪。你们在研究研究吧,给点建议。 |
|