如何通过单击C#中Form1的按钮操作从Form1访问Form2的图表属性

时间:2017-02-27 10:28:40

标签: c# charts

我是这个语言的新手,所以请帮我解决我的问题。我想打电话给frmDrawGraph表格的图表。我称之为。

   private void btnDrawGraph_Click(object sender, EventArgs e)
    {
        CreatGraph();
        frmDrawGraph frmDrawGraph1 = new frmDrawGraph();
        frmDrawGraph1.Show();
    }
    public void CreatGraph()
    {
        var raw_txt = System.IO.File.ReadAllLines(@"C:\\Users\\rms000\\Desktop\\2017.01.20\\modified App\\CSVFile\\BC_ACP__24_02_2017_13_56_40_.csv");
        System.Data.DataTable dt = new System.Data.DataTable();
        dt.Columns.Add("TimeOf ");
        dt.Columns.Add("Cell1_Voltage");
        dt.Columns.Add("Cell1_Current");
        DataTable myData = raw_txt.Skip(1)
                  .Select(x =>
                  {
                      var row = dt.NewRow();
                      row.SetField<string>("TimeOf", x.Split(',')[0]);
                      row.SetField<string>("Cell1_Voltage", x.Split(',')[8]);
                      row.SetField<string>("Cell1_Current", x.Split(',')[9]);
                      return row;
                  }).CopyToDataTable();
        chart1.Series.Add("Voltage");
        chart1.Series.Add("Current");
        chart1.Series["Time"].XValueMember = "TimeOf";
        chart1.Series["Voltage"].YValueMembers = "Cell1_Voltage";
        chart1.Series["Current"].YValueMembers = "Cell1_Current";
        chart1.DataSource = myData;
        chart1.DataBind();
    }

0 个答案:

没有答案