169 lines
3.7 KiB
C#
169 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
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, 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<ScatterPoint> Points = new ChartValues<ScatterPoint>();
|
|
string strTitle = "";
|
|
double dMin = 0;
|
|
double dMax = 0;
|
|
if (rbHumidity.Checked == true)
|
|
{
|
|
strTitle = "Humidity";
|
|
|
|
trendChart.AxisX[0].Title = strTitle;
|
|
|
|
ChartValues<ScatterPoint>[] Points = {
|
|
new ChartValues<ScatterPoint>(),
|
|
new ChartValues<ScatterPoint>(),
|
|
new ChartValues<ScatterPoint>() };
|
|
|
|
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<ScatterPoint>[] Points = {
|
|
new ChartValues<ScatterPoint>(),
|
|
new ChartValues<ScatterPoint>() };
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|