- TrendGraph에 trendline 추가

This commit is contained in:
2017-06-20 05:44:31 +09:00
parent 760ce6abc2
commit 9bf6a38f6d
5 changed files with 203 additions and 29 deletions

View File

@@ -12,6 +12,7 @@ using LiveCharts;
using LiveCharts.Wpf;
using LiveCharts.WinForms;
using LiveCharts.Defaults;
using System.Windows.Media;
namespace friction
{
@@ -49,6 +50,42 @@ namespace friction
Title = "RPN",
MinValue = 0,
MaxValue = 10,
Sections = new SectionsCollection
{
new AxisSection
{
Value = 5,
SectionWidth = 5,
Fill = new SolidColorBrush
{
Color = System.Windows.Media.Color.FromArgb(Theme.Red.A, Theme.Red.R, Theme.Red.G, Theme.Red.B),
Opacity = .75
}
},
new AxisSection
{
//Label = "Good",
Value = 3,
SectionWidth = 2,
Fill = new SolidColorBrush
{
Color = System.Windows.Media.Color.FromArgb(Theme.Yellow.A, Theme.Yellow.R, Theme.Yellow.G, Theme.Yellow.B),
Opacity = .75
}
},
new AxisSection
{
//Label = "Bad",
Value = 0,
SectionWidth = 3,
Fill = new SolidColorBrush
{
Color = System.Windows.Media.Color.FromArgb(Theme.Green.A, Theme.Green.R, Theme.Green.G, Theme.Green.B),
Opacity = .75
}
}
}
});
trendChart.LegendLocation = LegendLocation.Right;
@@ -93,20 +130,33 @@ namespace friction
new ChartValues<ScatterPoint>(),
new ChartValues<ScatterPoint>() };
var Values = new List<TrendLine.POINT>();
foreach (var pnt in Chart)
{
if(pnt.TEMPERATURE < 0)
Points[0].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN));
Points[0].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN, 2));
else if(pnt.TEMPERATURE > 30)
Points[2].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN));
Points[2].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN, 2));
else
Points[1].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN));
Points[1].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN, 2));
Values.Add(new TrendLine.POINT { X = pnt.HUMIDITY, Y = pnt.RPN });
}
Values.Sort((a, b) => (a.X == b.X) ? 0 : (a.X < b.X) ? -1 : 1);
TrendLine trendline = new TrendLine(Values);
ChartValues<ScatterPoint> TrendPoints = new ChartValues<ScatterPoint>();
TrendPoints.Add(new ScatterPoint(Values[0].X, trendline.GetY(Values[0].X)));
TrendPoints.Add(new ScatterPoint(Values[Values.Count / 2].X, trendline.GetY(Values[Values.Count / 2].X)));
TrendPoints.Add(new ScatterPoint(Values[Values.Count - 1].X, trendline.GetY(Values[Values.Count - 1].X)));
System.Windows.Media.SolidColorBrush[] brushes = {
System.Windows.Media.Brushes.DodgerBlue.Clone(),
System.Windows.Media.Brushes.Green.Clone(),
System.Windows.Media.Brushes.IndianRed.Clone() };
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;
@@ -131,6 +181,13 @@ namespace friction
Values = Points[2],
Fill = brushes[2],
},
new LineSeries
{
Title = "Trend",
Values = TrendPoints,
PointGeometry = DefaultGeometries.None,
StrokeThickness = 4,
},
};
@@ -146,6 +203,7 @@ namespace friction
ChartValues<ScatterPoint>[] Points = {
new ChartValues<ScatterPoint>(),
new ChartValues<ScatterPoint>() };
var Values = new List<TrendLine.POINT>();
foreach (var pnt in Chart)
{
@@ -153,8 +211,17 @@ namespace friction
Points[0].Add(new ScatterPoint(pnt.TEMPERATURE, pnt.RPN, 2));
else
Points[1].Add(new ScatterPoint(pnt.TEMPERATURE, pnt.RPN, 2));
Values.Add(new TrendLine.POINT { X = pnt.TEMPERATURE, Y = pnt.RPN });
}
Values.Sort((a, b) => (a.X == b.X) ? 0 : (a.X<b.X) ? -1 : 1);
TrendLine trendline = new TrendLine(Values);
ChartValues<ScatterPoint> TrendPoints = new ChartValues<ScatterPoint>();
TrendPoints.Add(new ScatterPoint(Values[0].X, trendline.GetY(Values[0].X)));
TrendPoints.Add(new ScatterPoint(Values[Values.Count / 2].X, trendline.GetY(Values[Values.Count / 2].X)));
TrendPoints.Add(new ScatterPoint(Values[Values.Count - 1].X, trendline.GetY(Values[Values.Count - 1].X)));
trendChart.Series = new SeriesCollection
{
new ScatterSeries
@@ -169,6 +236,13 @@ namespace friction
Values = Points[1],
Foreground = System.Windows.Media.Brushes.DarkBlue,
},
new LineSeries
{
Title = "Trend",
Values = TrendPoints,
PointGeometry = DefaultGeometries.None,
StrokeThickness = 4,
},
};
dMin = Chart.Min(r => r.TEMPERATURE - 1);