给你一个例子
 private void button1_Click(object sender, EventArgs e)
        {    
            chart1.DataSource = GetData();
            // Set series members names for the X and Y values
            chart1.Series["Series1"].XValueMember = "Time";
            chart1.Series["Series1"].YValueMembers = "City";            chart1.Series["Series2"].XValueMember = "Time";
            chart1.Series["Series2"].YValueMembers = "Count";            // Data bind to the selected data source
            chart1.DataBind();
            // Set series chart type
            chart1.Series["Series1"].ChartType = SeriesChartType.Line;
            chart1.Series["Series2"].ChartType = SeriesChartType.Spline;
            // Set point labels
            chart1.Series["Series1"].IsValueShownAsLabel = true;
            chart1.Series["Series2"].IsValueShownAsLabel = true;
            // Enable X axis margin
            chart1.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = true;
            // Enable 3D, and show data point er lines
            //chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
            chart1.Series["Series1"]["ShowMarkerLines"] = "True";
            chart1.Series["Series2"]["ShowMarkerLines"] = "True";        }  private DataTable GetData()
        {
            DataTable tableInfo = new DataTable();            DataColumn dctime = new DataColumn("Time", Type.GetType("System.String"));
            DataColumn dcCity = new DataColumn("City", Type.GetType("System.String"));
            DataColumn dcCount = new DataColumn("Count", Type.GetType("System.Int32"));
            tableInfo.Columns.Add(dctime);
            tableInfo.Columns.Add(dcCity);
            tableInfo.Columns.Add(dcCount);
            DataRow dr = tableInfo.NewRow();
            dr["Time"] = "1:00";
            dr["City"] = "10";
            dr["Count"] = "15";
            tableInfo.Rows.Add(dr);
            DataRow dr1 = tableInfo.NewRow();
            dr1["Time"] = "2:00";
            dr1["City"] = "12";
            dr1["Count"] = "19";
            tableInfo.Rows.Add(dr1);
            DataRow dr2 = tableInfo.NewRow();
            dr2["Time"] = "3:00";
            dr2["City"] = "13";
            dr2["Count"] = "25";
            tableInfo.Rows.Add(dr2);
            DataRow dr3 = tableInfo.NewRow();
            dr3["Time"] = "4:00";
            dr3["City"] = "14";
            dr3["Count"] = "10";
            tableInfo.Rows.Add(dr3);            DataRow dr4 = tableInfo.NewRow();
            dr4["Time"] = "5:00";
            dr4["City"] = "15";
            dr4["Count"] = "11";
            tableInfo.Rows.Add(dr4);            DataRow dr5 = tableInfo.NewRow();
            dr5["Time"] = "6:00";
            dr5["City"] = "16";
            dr5["Count"] = "17";
            tableInfo.Rows.Add(dr5);            DataRow dr6 = tableInfo.NewRow();
            dr6["Time"] = "7:00";
            dr6["City"] = "17";
            dr6["Count"] = "20";
            tableInfo.Rows.Add(dr6);            DataRow dr7 = tableInfo.NewRow();
            dr7["Time"] = "8:00";
            dr7["City"] = "12";
            dr7["Count"] = "13";
            tableInfo.Rows.Add(dr7);
            return tableInfo;
        }

解决方案 »

  1.   

    @wind_cloud2011              我主要不知道该怎么实时更新数据啊   你这样的话数据绑定死的   我现在也是先这么写的     朋友说用list好像比table好点     不过还是不会
      

  2.   

    你可以绑定数据源啊
    private void zkButton1_Click(object sender, EventArgs e)
    {
    Random rand = new Random();
    var list = new List<ChartTestData>();
    int i = 0;
    while (i < 30)
    {
    list.Add(new ChartTestData(i.ToString(), rand.Next(0, 100), rand.Next(0, 100)));
    i++;
    }
    this.bindingSource1.DataSource = list;
    this.Chart.DataBind();
    }
    public class ChartTestData
    {
    public string name { get; set; }
    public decimal value1 { get; set; }
    public decimal value2 { get; set; } public ChartTestData()
    { }
    public ChartTestData(string name, decimal value1, decimal value2)
    {
    this.name = name;
    this.value1 = value1;
    this.value2 = value2;
    }
    }
      

  3.   

    看看这样操作行嘛
         新建一个集合保存输入的数据;
         在窗体中新建一个PANNEL,在paint事件中画曲线;
         若需要伸缩画面,画画坐标、数值,经过比例因子计算后,再在画布上显示。