From 7603deef0df79f5d034413aead3c7eebe005783e Mon Sep 17 00:00:00 2001 From: mjjo53 Date: Mon, 19 Jun 2017 19:22:33 +0900 Subject: [PATCH] =?UTF-8?q?Trend=20Chart=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataHandler.cs | 47 +++++++++++- MainForm.cs | 2 +- PanelTrendGraph.Designer.cs | 64 +++++++++++++++- PanelTrendGraph.cs | 145 +++++++++++++++++++++++++++++++++++- friction.csproj | 17 +++++ 5 files changed, 270 insertions(+), 5 deletions(-) diff --git a/DataHandler.cs b/DataHandler.cs index a921f41..c0056c4 100644 --- a/DataHandler.cs +++ b/DataHandler.cs @@ -22,7 +22,18 @@ namespace friction public float m_fDiffByVel; } - + public struct CHART + { + public float HUMIDITY; + public float TEMPERATURE; + public float RPN; + + override public string ToString() + { + return string.Format("Humi({0}) Temp({1}) RPN({2})", HUMIDITY, TEMPERATURE, RPN); + } + } + DataTable m_Data = new DataTable(); @@ -138,9 +149,41 @@ namespace friction m_ActiveColumns.Add(m_ColumnsNames[i]); } } + } + public void SetSelectedMaterial(string strSpring, string strTable) + { + m_strCurSpring = strSpring; + m_strCurTable = strTable; + } - //GetCalc("ABS", "ABS"); + public string GetCurSpring() + { + return m_strCurSpring; + } + + public string GetCurTable() + { + return m_strCurTable; + } + + public List GetHumidityChart(string strSpring, string strTable) + { + string strQuery = string.Format("[{0}]='{1}' and [{2}]='{3}'", m_ColumnMap["spring"], strSpring, m_ColumnMap["table"], strTable); + DataRow[] rows = m_Data.Select(strQuery); + + List result = new List(); + foreach(DataRow r in rows) + { + result.Add(new CHART + { + HUMIDITY = (float)r[m_ColumnMap["humidity"]], + TEMPERATURE = (float)r[m_ColumnMap["temp"]], + RPN = (float)r[m_ColumnMap["rpn"]], + }); + } + + return result; } diff --git a/MainForm.cs b/MainForm.cs index 59b6b0f..812c30b 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -30,7 +30,7 @@ namespace friction m_ResultPanel = new PanelResult(this); m_AnalysisPanel = new PanelAnalysis(this); m_RadarGraphPanel = new PanelRadarGraph(this); - m_TrendGraphPanel = new PanelTrendGraph(this); + m_TrendGraphPanel = new PanelTrendGraph(this, m_DataHandler); } private void OpenPanel(DockContent panel) diff --git a/PanelTrendGraph.Designer.cs b/PanelTrendGraph.Designer.cs index 8f87b0d..1e7e88c 100644 --- a/PanelTrendGraph.Designer.cs +++ b/PanelTrendGraph.Designer.cs @@ -28,23 +28,85 @@ /// private void InitializeComponent() { + this.trendChart = new LiveCharts.WinForms.CartesianChart(); + this.rbHumidity = new System.Windows.Forms.RadioButton(); + this.rbTemp = new System.Windows.Forms.RadioButton(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.groupBox1.SuspendLayout(); this.SuspendLayout(); // + // trendChart + // + this.trendChart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.trendChart.Location = new System.Drawing.Point(8, 59); + this.trendChart.Name = "trendChart"; + this.trendChart.Size = new System.Drawing.Size(742, 603); + this.trendChart.TabIndex = 0; + this.trendChart.Text = "trendChart"; + // + // rbHumidity + // + this.rbHumidity.Appearance = System.Windows.Forms.Appearance.Button; + this.rbHumidity.AutoSize = true; + this.rbHumidity.Checked = true; + this.rbHumidity.Location = new System.Drawing.Point(6, 19); + this.rbHumidity.Name = "rbHumidity"; + this.rbHumidity.Size = new System.Drawing.Size(64, 22); + this.rbHumidity.TabIndex = 1; + this.rbHumidity.TabStop = true; + this.rbHumidity.Text = "Humidity"; + this.rbHumidity.UseVisualStyleBackColor = true; + this.rbHumidity.CheckedChanged += new System.EventHandler(this.rbHumidity_CheckedChanged); + // + // rbTemp + // + this.rbTemp.Appearance = System.Windows.Forms.Appearance.Button; + this.rbTemp.AutoSize = true; + this.rbTemp.Location = new System.Drawing.Point(76, 20); + this.rbTemp.Name = "rbTemp"; + this.rbTemp.Size = new System.Drawing.Size(87, 22); + this.rbTemp.TabIndex = 1; + this.rbTemp.Text = "Temperature"; + this.rbTemp.UseVisualStyleBackColor = true; + this.rbTemp.CheckedChanged += new System.EventHandler(this.rbTemp_CheckedChanged); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.rbHumidity); + this.groupBox1.Controls.Add(this.rbTemp); + this.groupBox1.ForeColor = System.Drawing.SystemColors.ControlText; + this.groupBox1.Location = new System.Drawing.Point(8, 3); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(322, 50); + this.groupBox1.TabIndex = 2; + this.groupBox1.TabStop = false; + // // PanelTrendGraph // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(284, 261); + this.ClientSize = new System.Drawing.Size(762, 674); this.ControlBox = false; + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.trendChart); this.HideOnClose = true; this.Name = "PanelTrendGraph"; this.ShowHint = WeifenLuo.WinFormsUI.Docking.DockState.Document; this.TabText = "Trend Graph"; this.Text = "Trend Graph"; + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); this.ResumeLayout(false); } #endregion + + private LiveCharts.WinForms.CartesianChart trendChart; + private System.Windows.Forms.RadioButton rbHumidity; + private System.Windows.Forms.RadioButton rbTemp; + private System.Windows.Forms.GroupBox groupBox1; } } \ No newline at end of file diff --git a/PanelTrendGraph.cs b/PanelTrendGraph.cs index 5c5e46c..537f525 100644 --- a/PanelTrendGraph.cs +++ b/PanelTrendGraph.cs @@ -8,18 +8,161 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using WeifenLuo.WinFormsUI.Docking; +using LiveCharts; +using LiveCharts.Wpf; +using LiveCharts.WinForms; +using LiveCharts.Defaults; namespace friction { public partial class PanelTrendGraph : DockContent { MainForm m_Owner = null; + DataHandler m_DataHandler = null; - public PanelTrendGraph(MainForm owner) + public PanelTrendGraph(MainForm owner, DataHandler data) { InitializeComponent(); m_Owner = owner; + m_DataHandler = data; + + + + trendChart.AxisX.Add(new Axis + { + Title = "Humidity", + }); + + trendChart.AxisY.Add(new Axis + { + Title = "RPN", + MinValue = 0, + MaxValue = 10, + }); + + trendChart.LegendLocation = LegendLocation.Right; + + trendChart.DataClick += TrendChart_DataClick; + } + + private void TrendChart_DataClick(object sender, ChartPoint chartPoint) + { + } + + private void UpdateGraph() + { + var Chart = m_DataHandler.GetHumidityChart(m_DataHandler.GetCurSpring(), m_DataHandler.GetCurTable()); + + //ChartValues Points = new ChartValues(); + string strTitle = ""; + double dMin = 0; + double dMax = 0; + if (rbHumidity.Checked == true) + { + strTitle = "Humidity"; + + trendChart.AxisX[0].Title = strTitle; + + ChartValues[] Points = { + new ChartValues(), + new ChartValues(), + new ChartValues() }; + + foreach (var pnt in Chart) + { + if(pnt.TEMPERATURE < 0) + Points[0].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN)); + else if(pnt.TEMPERATURE > 30) + Points[2].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN)); + else + Points[1].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN)); + } + + System.Windows.Media.SolidColorBrush[] brushes = { + System.Windows.Media.Brushes.DodgerBlue.Clone(), + System.Windows.Media.Brushes.Green.Clone(), + System.Windows.Media.Brushes.IndianRed.Clone() }; + foreach (var brush in brushes) + brush.Opacity = 0.75; + + trendChart.Series = new SeriesCollection + { + new ScatterSeries + { + Title = "~ 0℃", + Values = Points[0], + Fill = brushes[0], + }, + new ScatterSeries + { + Title = "0℃ ~ 30℃", + Values = Points[1], + Fill = brushes[1], + }, + new ScatterSeries + { + Title = "30℃ ~", + Values = Points[2], + Fill = brushes[2], + }, + }; + + + dMin = Chart.Min(r => r.HUMIDITY - 1); + dMax = Chart.Max(r => r.HUMIDITY - 1); + } + else if(rbTemp.Checked == true) + { + strTitle = "Temperature"; + + trendChart.AxisX[0].Title = strTitle; + + ChartValues[] Points = { + new ChartValues(), + new ChartValues() }; + + foreach (var pnt in Chart) + { + if(pnt.HUMIDITY <= 60) + Points[0].Add(new ScatterPoint(pnt.TEMPERATURE, pnt.RPN, 2)); + else + Points[1].Add(new ScatterPoint(pnt.TEMPERATURE, pnt.RPN, 2)); + } + + trendChart.Series = new SeriesCollection + { + new ScatterSeries + { + Title = "~ 60%", + Values = Points[0], + Foreground = System.Windows.Media.Brushes.SkyBlue, + }, + new ScatterSeries + { + Title = "60% ~", + Values = Points[1], + Foreground = System.Windows.Media.Brushes.DarkBlue, + }, + }; + + dMin = Chart.Min(r => r.TEMPERATURE - 1); + dMax = Chart.Max(r => r.TEMPERATURE - 1); + } + + + trendChart.AxisX[0].MinValue = dMin; + trendChart.AxisX[0].MaxValue = dMax; + } + + private void rbHumidity_CheckedChanged(object sender, EventArgs e) + { + UpdateGraph(); + } + + private void rbTemp_CheckedChanged(object sender, EventArgs e) + { + UpdateGraph(); } } } diff --git a/friction.csproj b/friction.csproj index 0f74541..10f3bda 100644 --- a/friction.csproj +++ b/friction.csproj @@ -37,8 +37,23 @@ packages\EPPlus.4.1.0\lib\net40\EPPlus.dll True + + packages\LiveCharts.0.9.6\lib\net45\LiveCharts.dll + True + + + packages\LiveCharts.WinForms.0.9.6\lib\net45\LiveCharts.WinForms.dll + True + + + packages\LiveCharts.Wpf.0.9.6\lib\net45\LiveCharts.Wpf.dll + True + + + + @@ -48,6 +63,8 @@ + +