日期:2014-05-20  浏览次数:20914 次

WebChartControl数据绑定问题
我使用的是DXperience的图标控件WebChartControl,现在对其数据绑定这一环节不甚了解,看到它也拥有datasource,所以推断出它也可以进行数据绑定。可是研究半天也没有结果,望有用过的达人能给出我一段数据绑定的源码,不要太复杂,说明怎么绑定字段就好。

数据源我给出,从DX官网下的

  private DataTable CreateChartData() {
  // Create an empty table.
  DataTable table = new DataTable("Table1");

  // Add three columns to the table.
  table.Columns.Add("Month", typeof(String));
  table.Columns.Add("Section", typeof(String));
  table.Columns.Add("Value", typeof(Int32));

  // Add data rows to the table.
  table.Rows.Add(new object[] { "Jan", "Section1", 10 });
  table.Rows.Add(new object[] { "Jan", "Section2", 20 });
  table.Rows.Add(new object[] { "Feb", "Section1", 20 });
  table.Rows.Add(new object[] { "Feb", "Section2", 30 });
  table.Rows.Add(new object[] { "March", "Section1", 15 });
  table.Rows.Add(new object[] { "March", "Section2", 25 });

  return table;
  }

------解决方案--------------------
在页面上放一个sqldatasource or Orcaledatasource,然后把这个datasource绑定到WebChartControl控件。
当然connectionstring和sql语句事先都要写好,sqldatasource or Orcaledatasource里面要用到。connectionstring可以通过Web.Config设置好。
------解决方案--------------------
ChartDirector
http://www.advsofteng.com/gallery.html
有源码,自己找一下
------解决方案--------------------
Web的不清楚,
好象不是Web的可以这样:
Series series1 = new Series("series1", ViewType.Pie);
this.chartcontro.Series.Add(series1);
series1.DataSource = CreateChartData();
series1.ArgumentScaleType = ScaleType.Qualitative;//
series1.ArgumentDataMember = "Month";
series1.ValueScaleType = ScaleType.Numerical;
series1.ValueDataMembers.AddRange(new string[] { "Value" });
this.Controls.Add(this.chartcontrol);
this.chartcontrol.Dock = DockStyle.Fill;

------解决方案--------------------
<%@ page language="C#"%>
<%@ import namespace="System.Data"%>
<%@ register tagprefix="web" namespace="WebChart" assembly="WebChart"%>
<script runat="server">
void Page_Load(object o, EventArgs e) {
CreateChart();
}
 
void CreateChart() 
{
PieChart chart = new PieChart();
chart.DataSource = GetDataSet().Tables[0].DefaultView;
chart.DataXValueField = "Title";
chart.DataYValueField = "Price";
chart.DataLabels.Visible = true;
chart.DataLabels.ForeColor = System.Drawing.Color.Blue;
//也可以指定每个对象的颜色
//chart.Colors = new Color[] { Color.Red, Color.Blue, Color.Yellow, Color.Cyan, Color.Black, Color.RosyBrown,Color.Green,Color.Pink,Color.Purple,Color.GreenYellow};
chart.Shadow.Visible = true;
chart.DataBind();
chart.Explosion = 10;
ChartControl1.Charts.Add(chart);
ChartControl1.RedrawChart();
}
 
DataSet GetDataSet() 
{
DataSet ds = new DataSet();
DataTable table = ds.Tables.Add("My Table");
table.Columns.Add(new DataColumn("Title"));
table.Columns.Add(new DataColumn("Price", typeof(int)));
 
Random rnd = new Random();
for (int i = 0; i < 10; i++) 
{
DataRow row = table.NewRow();