日期:2014-05-17  浏览次数:20814 次

Chart 控件用法,求实例代码,在线等。50分全给你!
chart 控件求实例代码。


我刚在VS2008上面添加了chart控件。

但是不会用 拉上去之后 不会写代码 不会灵活用。

谁来指点? 你想要70分,写上简单的代码 实际点的分全给你。



------解决方案--------------------
微软Chart控件导学--从头开始
------解决方案--------------------
简单示例,
 <asp:Chart ID="Chart1" runat="server" Height="400px" Width="500px">
<Series>
<asp:Series Name="Series1" ChartType="Column" ChartArea="ChartArea1">
</asp:Series>
<asp:Series Name="Series2" ChartType="Column" ChartArea="ChartArea1">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
</asp:ChartArea>
</ChartAreas>
</asp:Chart>

后台代码:

protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = default(DataTable);
dt = CreateDataTable();

//设置图表的数据源
Chart1.DataSource = dt;

//设置图表Y轴对应项
Chart1.Series[0].YValueMembers = "Volume1";
Chart1.Series[1].YValueMembers = "Volume2";

//设置图表X轴对应项
Chart1.Series[0].XValueMember = "Date";

//绑定数据
Chart1.DataBind();
}
private DataTable CreateDataTable()
{
//Create a DataTable as the data source of the Chart control
DataTable dt = new DataTable();

//Add three columns to the DataTable
dt.Columns.Add("Date");
dt.Columns.Add("Volume1");
dt.Columns.Add("Volume2");

DataRow dr;

//Add rows to the table which contains some random data for demonstration
dr = dt.NewRow();
dr["Date"] = "Jan";
dr["Volume1"] = 3731;
dr["Volume2"] = 4101;
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["Date"] = "Feb";
dr["Volume1"] = 6024;
dr["Volume2"] = 4324;
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["Date"] = "Mar";
dr["Volume1"] = 4935;
dr["Volume2"] = 2935;
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["Date"] = "Apr";
dr["Volume1"] = 4466;
dr["Volume2"] = 5644;
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["Date"] = "May";
dr["Volume1"] = 5117;
dr["Volume2"] = 5671;
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["Date"] = "Jun";
dr["Volume1"] = 3546;
dr["Volume2"] = 4646;
dt.Rows.Add(dr);

return dt;
}
------解决方案--------------------
http://topic.csdn.net/u/20101020/17/83ba4f85-9747-4b2e-9021-eec4ea1c19e9.html
------解决方案--------------------
引用以后,将chart放到工具箱中,方法:右键工具箱下面,然后添加,找到chart,加进来,就可以当控件拖动到界面上了。然后下面写代码,很简单,你摸索下就好,可惜我的例子丢了。