显示所有相同标签的水平范围栏标签

cs7cruho  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(222)

我正在用c#构建一个连接到mysql数据库的范围条形图。问题是图表中的所有条形图都显示相同的标签,而它们应该具有不同的值。我不明白为什么。我应该创建不同的系列吗?我做错什么了?我对此进行了研究,但不幸的是,我很难找到解决办法。这是我的密码:

private void LoadChartData()
    {
        var s = new Series();
        s.ChartType = SeriesChartType.RangeBar;

        chart1.Series.Clear();
        chart1.Series.Add(s);

        s.SetCustomProperty("PixelPointWidth", "25");

        chart1.Series[0].YValueType = ChartValueType.DateTime;
        chart1.ChartAreas[0].AxisY.LabelStyle.Format = "yyyy-MM-dd";
        chart1.ChartAreas[0].AxisY.Interval = 1;
        chart1.ChartAreas[0].AxisY.IntervalType = DateTimeIntervalType.Days;
        chart1.ChartAreas[0].AxisY.IntervalOffset = 1;

        chart1.Series[0].XValueType = ChartValueType.String;
        chart1.ChartAreas[0].AxisY.Minimum = minDate.ToOADate();
        chart1.ChartAreas[0].AxisY.Maximum = maxDate.ToOADate();

        ConnectionStringSettings conSettings = ConfigurationManager.ConnectionStrings["shopmanagerConnectionString1"];
        MySqlConnection con = new MySqlConnection(conSettings.ToString());
        MySqlCommand cmd = new MySqlCommand(@"select * from shopmanager.planning;", con);
        MySqlDataReader myReader;
        try
        {
            con.Open();
            myReader = cmd.ExecuteReader();

            while (myReader.Read())
            {
                //check if machine is "en attente"
                string notPlanned;
                notPlanned = myReader.GetString("machine_name");
                if(notPlanned == "En attente")
                {
                    return;
                }
                else
                {
                    s.Label = myReader.GetString("project_number") + " " + myReader.GetString("part_name");
                    s.LabelForeColor = Color.Black;
                    s["LabelStyle"] = "Left";

                    var start_date = myReader.GetDateTime("predicted_start_date");
                    var predicted_finish_date = myReader.GetDateTime("predicted_delivery");
                    var machine = myReader.GetString("machine_name");

                    s.Points.AddXY(machine, start_date, predicted_finish_date); 
                }
            }
            cmd.Parameters.Clear();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        con.Close();

    }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题