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

时间:2018-10-03 12:15:01

标签: c# mysql charts

我正在用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();

    }

enter image description here

0 个答案:

没有答案