每个工作轮班 C# .NET WindowsForm 客户端控件的生产摘要图表
Chart With Production Summary for each work-Shift C# .NET WindowsForm Client Control
这是我第一次post来这里,我的英语不是很好,但我会努力的。
我需要制作这样的图表
The chart that im trying to recreate
基于由结构如下的 SQL 查询填充的数据表:
Result of The query that i need to chart
现在我想出了这个很有效的想法,但我正在为它的某些方面而苦苦挣扎:
What i have come up with
我只需要显示查询结果中存在的 x 值,但由于它们是日期时间值,所以当我将每个点添加到图表中时,图表的 x 轴向我显示每个点的线性时间刻度一天中的时间不仅是我添加到图表中的点。
这是主要问题,
另一个问题是,当显示太多值时,我需要能够使用鼠标滚轮水平滚动图表以查看所有其他值。
先谢谢大家希望我已经把所有的信息都写出来了,无论如何如果你们需要的话我可以给你们更多
tysm
我现在附上对该主题感兴趣的所有代码:
(设计师)
namespace GRAPHICOBJECTS
{
partial class GRAFTREND
{
/// <summary>
/// Variabile di progettazione necessaria.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Pulire le risorse in uso.
/// </summary>
/// <param name="disposing">ha valore true se le risorse gestite devono essere eliminate, false in caso contrario.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Codice generato da Progettazione componenti
/// <summary>
/// Metodo necessario per il supporto della finestra di progettazione. Non modificare
/// il contenuto del metodo con l'editor di codice.
/// </summary>
private void InitializeComponent()
{
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series();
this.CHART = new System.Windows.Forms.DataVisualization.Charting.Chart();
this.button1 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.CHART)).BeginInit();
this.SuspendLayout();
//
// CHART
//
this.CHART.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(175)))), ((int)(((byte)(175)))), ((int)(((byte)(175)))));
chartArea1.AxisX.Enabled = System.Windows.Forms.DataVisualization.Charting.AxisEnabled.True;
chartArea1.AxisX.Interval = 1D;
chartArea1.AxisX.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount;
chartArea1.AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Hours;
chartArea1.AxisX.IsLabelAutoFit = false;
chartArea1.AxisX.LabelStyle.Angle = 90;
chartArea1.AxisX.LabelStyle.Format = "dd/MM HH:mm";
chartArea1.AxisX.LabelStyle.Interval = 0D;
chartArea1.AxisX.LabelStyle.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Hours;
chartArea1.AxisX2.Interval = 1D;
chartArea1.AxisX2.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount;
chartArea1.AxisX2.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Hours;
chartArea1.AxisX2.IsLabelAutoFit = false;
chartArea1.AxisX2.LabelStyle.Angle = 90;
chartArea1.AxisX2.LabelStyle.Format = "dd/MM HH:mm";
chartArea1.AxisX2.LabelStyle.Interval = 0D;
chartArea1.AxisX2.LabelStyle.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Hours;
chartArea1.Name = "ChartArea1";
this.CHART.ChartAreas.Add(chartArea1);
this.CHART.Location = new System.Drawing.Point(1, 0);
this.CHART.Name = "CHART";
this.CHART.RightToLeft = System.Windows.Forms.RightToLeft.No;
series1.ChartArea = "ChartArea1";
series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn;
series1.IsVisibleInLegend = false;
series1.Name = "S2";
series1.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.DateTime;
series2.ChartArea = "ChartArea1";
series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn;
series2.IsVisibleInLegend = false;
series2.Name = "S1";
series2.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.DateTime;
this.CHART.Series.Add(series1);
this.CHART.Series.Add(series2);
this.CHART.Size = new System.Drawing.Size(1012, 350);
this.CHART.TabIndex = 1;
this.CHART.Text = "CHART";
//
// button1
//
this.button1.Location = new System.Drawing.Point(3, 352);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(58, 43);
this.button1.TabIndex = 2;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// GRAFTREND
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.button1);
this.Controls.Add(this.CHART);
this.Name = "GRAFTREND";
this.Size = new System.Drawing.Size(1015, 398);
this.Load += new System.EventHandler(this.UserControl2_Load);
((System.ComponentModel.ISupportInitialize)(this.CHART)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataVisualization.Charting.Chart CHART;
private System.Windows.Forms.Button button1;
}
}
(现在我的 Sql 使用我的 Drawchart 函数请求查询)
private void button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GetStatisticalData_ShiftGraph";
cmd.Parameters.AddWithValue("@DataStartSH", "2021-09-01 06:00:00.000");
cmd.Parameters.AddWithValue("@DataEndSH", "2021-09-02 06:00:00.000");
cmd.Parameters.AddWithValue("@RecipeName", "TEST");
cmd.Parameters.AddWithValue("@LineN", 1);
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
NRecord = da.Fill(dt);
GraphicFunctions.DrawChart(this.CHART, dt, "TimeShift", "Rejected", Color.Yellow, "TimeShift", "Good", Color.LightGreen);
this.CHART.Series["S1"].IsValueShownAsLabel = true;
this.CHART.Series["S2"].IsValueShownAsLabel = true;
this.CHART.DataManipulator.InsertEmptyPoints(1, IntervalType.Days, "S1");
this.CHART.DataManipulator.InsertEmptyPoints(1, IntervalType.Days, "S2");
}
(现在是我的函数)
public static void DrawChart(Chart ObjChart,DataTable DTable, string xColumnS1, string yColumnS1,Color ColorS1, string xColumnS2, string yColumnS2, Color ColorS2)
{
double PointsCount;
try
{
ObjChart.DataSource = DTable;
ObjChart.Series["S1"].XValueMember = xColumnS1;
ObjChart.Series["S1"].YValueMembers = yColumnS1;
ObjChart.Series["S2"].Enabled = true;
ObjChart.Series["S2"].XValueMember = xColumnS2;
ObjChart.Series["S2"].YValueMembers = yColumnS2;
ObjChart.DataBind();
PointsCount = ObjChart.Series["S1"].Points.Count;
for (int i = 0; i <= PointsCount - 1; i++) ObjChart.Series["S1"].Points[i].Color = ColorS1;
PointsCount = ObjChart.Series["S2"].Points.Count;
for (int i = 0; i <= PointsCount - 1; i++) ObjChart.Series["S2"].Points[i].Color = ColorS2;
}
catch (System.Exception ex)
{
throw ex;
}
}
我已经解决了这个问题,为了让每个数据列都有一个 X 值点,我需要使用设置(对于每个系列)索引两个系列中的所有值:
series10.IsXValueIndexed = true;
有关 Microsoft 帮助的更多信息:
这是我第一次post来这里,我的英语不是很好,但我会努力的。
我需要制作这样的图表
The chart that im trying to recreate
基于由结构如下的 SQL 查询填充的数据表:
Result of The query that i need to chart
现在我想出了这个很有效的想法,但我正在为它的某些方面而苦苦挣扎:
What i have come up with
我只需要显示查询结果中存在的 x 值,但由于它们是日期时间值,所以当我将每个点添加到图表中时,图表的 x 轴向我显示每个点的线性时间刻度一天中的时间不仅是我添加到图表中的点。 这是主要问题,
另一个问题是,当显示太多值时,我需要能够使用鼠标滚轮水平滚动图表以查看所有其他值。
先谢谢大家希望我已经把所有的信息都写出来了,无论如何如果你们需要的话我可以给你们更多
tysm
我现在附上对该主题感兴趣的所有代码: (设计师)
namespace GRAPHICOBJECTS
{
partial class GRAFTREND
{
/// <summary>
/// Variabile di progettazione necessaria.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Pulire le risorse in uso.
/// </summary>
/// <param name="disposing">ha valore true se le risorse gestite devono essere eliminate, false in caso contrario.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Codice generato da Progettazione componenti
/// <summary>
/// Metodo necessario per il supporto della finestra di progettazione. Non modificare
/// il contenuto del metodo con l'editor di codice.
/// </summary>
private void InitializeComponent()
{
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series();
this.CHART = new System.Windows.Forms.DataVisualization.Charting.Chart();
this.button1 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.CHART)).BeginInit();
this.SuspendLayout();
//
// CHART
//
this.CHART.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(175)))), ((int)(((byte)(175)))), ((int)(((byte)(175)))));
chartArea1.AxisX.Enabled = System.Windows.Forms.DataVisualization.Charting.AxisEnabled.True;
chartArea1.AxisX.Interval = 1D;
chartArea1.AxisX.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount;
chartArea1.AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Hours;
chartArea1.AxisX.IsLabelAutoFit = false;
chartArea1.AxisX.LabelStyle.Angle = 90;
chartArea1.AxisX.LabelStyle.Format = "dd/MM HH:mm";
chartArea1.AxisX.LabelStyle.Interval = 0D;
chartArea1.AxisX.LabelStyle.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Hours;
chartArea1.AxisX2.Interval = 1D;
chartArea1.AxisX2.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount;
chartArea1.AxisX2.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Hours;
chartArea1.AxisX2.IsLabelAutoFit = false;
chartArea1.AxisX2.LabelStyle.Angle = 90;
chartArea1.AxisX2.LabelStyle.Format = "dd/MM HH:mm";
chartArea1.AxisX2.LabelStyle.Interval = 0D;
chartArea1.AxisX2.LabelStyle.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Hours;
chartArea1.Name = "ChartArea1";
this.CHART.ChartAreas.Add(chartArea1);
this.CHART.Location = new System.Drawing.Point(1, 0);
this.CHART.Name = "CHART";
this.CHART.RightToLeft = System.Windows.Forms.RightToLeft.No;
series1.ChartArea = "ChartArea1";
series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn;
series1.IsVisibleInLegend = false;
series1.Name = "S2";
series1.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.DateTime;
series2.ChartArea = "ChartArea1";
series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn;
series2.IsVisibleInLegend = false;
series2.Name = "S1";
series2.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.DateTime;
this.CHART.Series.Add(series1);
this.CHART.Series.Add(series2);
this.CHART.Size = new System.Drawing.Size(1012, 350);
this.CHART.TabIndex = 1;
this.CHART.Text = "CHART";
//
// button1
//
this.button1.Location = new System.Drawing.Point(3, 352);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(58, 43);
this.button1.TabIndex = 2;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// GRAFTREND
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.button1);
this.Controls.Add(this.CHART);
this.Name = "GRAFTREND";
this.Size = new System.Drawing.Size(1015, 398);
this.Load += new System.EventHandler(this.UserControl2_Load);
((System.ComponentModel.ISupportInitialize)(this.CHART)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataVisualization.Charting.Chart CHART;
private System.Windows.Forms.Button button1;
}
}
(现在我的 Sql 使用我的 Drawchart 函数请求查询)
private void button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GetStatisticalData_ShiftGraph";
cmd.Parameters.AddWithValue("@DataStartSH", "2021-09-01 06:00:00.000");
cmd.Parameters.AddWithValue("@DataEndSH", "2021-09-02 06:00:00.000");
cmd.Parameters.AddWithValue("@RecipeName", "TEST");
cmd.Parameters.AddWithValue("@LineN", 1);
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
NRecord = da.Fill(dt);
GraphicFunctions.DrawChart(this.CHART, dt, "TimeShift", "Rejected", Color.Yellow, "TimeShift", "Good", Color.LightGreen);
this.CHART.Series["S1"].IsValueShownAsLabel = true;
this.CHART.Series["S2"].IsValueShownAsLabel = true;
this.CHART.DataManipulator.InsertEmptyPoints(1, IntervalType.Days, "S1");
this.CHART.DataManipulator.InsertEmptyPoints(1, IntervalType.Days, "S2");
}
(现在是我的函数)
public static void DrawChart(Chart ObjChart,DataTable DTable, string xColumnS1, string yColumnS1,Color ColorS1, string xColumnS2, string yColumnS2, Color ColorS2)
{
double PointsCount;
try
{
ObjChart.DataSource = DTable;
ObjChart.Series["S1"].XValueMember = xColumnS1;
ObjChart.Series["S1"].YValueMembers = yColumnS1;
ObjChart.Series["S2"].Enabled = true;
ObjChart.Series["S2"].XValueMember = xColumnS2;
ObjChart.Series["S2"].YValueMembers = yColumnS2;
ObjChart.DataBind();
PointsCount = ObjChart.Series["S1"].Points.Count;
for (int i = 0; i <= PointsCount - 1; i++) ObjChart.Series["S1"].Points[i].Color = ColorS1;
PointsCount = ObjChart.Series["S2"].Points.Count;
for (int i = 0; i <= PointsCount - 1; i++) ObjChart.Series["S2"].Points[i].Color = ColorS2;
}
catch (System.Exception ex)
{
throw ex;
}
}
我已经解决了这个问题,为了让每个数据列都有一个 X 值点,我需要使用设置(对于每个系列)索引两个系列中的所有值:
series10.IsXValueIndexed = true;
有关 Microsoft 帮助的更多信息: