/// <summary> /// Converts movements to a graphical line and polygon /// </summary> /// <param name="results"></param> /// <param name="color"></param> /// <param name="label"></param> /// <returns></returns> public static LineAndPolygon ConvertResultsToMovementLineAndPolygon(float[] results, Color color, string label) { // Create the Line var chartLine = new ChartPrimitive(); chartLine.Color = color; chartLine.Label = label; chartLine.ShowInLegend = true; chartLine.HitTest = true; for (int monthNo = 0; monthNo < results.Length; ++monthNo) { chartLine.AddSmoothHorizontalBar(new Point(monthNo + .5f, results[monthNo])); } // Create the polygon ChartPrimitive polygon = ChartUtilities.ChartLineToBaseLinedPolygon(chartLine); color.A = (byte)(alpha * color.A); polygon.Color = color; polygon.ShowInLegend = false; polygon.HitTest = false; return(new LineAndPolygon(chartLine, polygon)); }
/// <summary> /// Copy constructor. Deep copies the ChartPrimitive passed in. /// </summary> /// <param name="chartPrimitive"></param> protected ChartPrimitive(ChartPrimitive chartPrimitive) : this() { if (chartPrimitive == null) { return; } color = chartPrimitive.Color; label = chartPrimitive.Label; filled = chartPrimitive.Filled; showInLegend = chartPrimitive.ShowInLegend; hitTest = chartPrimitive.HitTest; lineThickness = chartPrimitive.LineThickness; dashed = chartPrimitive.Dashed; Points = chartPrimitive.points; CalculateGeometry(); }
//GetPlotRectangle /// <summary> /// Converts a ChartLine object to a ChartPolygon object that has /// one edge along the bottom Horizontal base line in the plot. /// </summary> /// <param name="chartLine"></param> /// <returns></returns> public static ChartPrimitive ChartLineToBaseLinedPolygon(ChartPrimitive chartLine) { ChartPrimitive chartPolygon = chartLine != null?chartLine.Clone() : new ChartPrimitive(); if (chartPolygon.Points.Count > 0) { Point firstPoint = chartPolygon.Points[0]; firstPoint.Y = 0; Point lastPoint = chartPolygon.Points[chartPolygon.Points.Count - 1]; lastPoint.Y = 0; chartPolygon.InsertPoint(firstPoint, 0); chartPolygon.AddPoint(lastPoint); } chartPolygon.Filled = true; return(chartPolygon); }
/// <summary> /// Gets ChartLines and ChartPolygons for the population line, and /// the target line. /// </summary> /// <param name="populationLine"></param> /// <param name="results"></param> /// <param name="color"></param> /// <param name="label"></param> /// <returns></returns> public static LineAndPolygon ConvertResultsToTargetLineAndPolygon(ChartPrimitive populationLine, float[] results, Color color, string label) { // Calculate Target Primitives var targetLine = new ChartPrimitive(); targetLine.Color = color; targetLine.Dashed = true; targetLine.Label = label + " Target"; targetLine.ShowInLegend = false; targetLine.HitTest = true; if (populationLine.Points.Count == results.Length) { for (int monthNo = 0; monthNo < results.Length; monthNo += 2) { targetLine.AddPoint(new Point(monthNo * .5f, results[monthNo])); targetLine.AddPoint(new Point(monthNo * .5f + 1f, results[monthNo + 1])); } } else { for (int monthNo = 0; monthNo < results.Length; ++monthNo) { targetLine.AddPoint(new Point(monthNo, results[monthNo])); targetLine.AddPoint(new Point(monthNo + 1f, results[monthNo])); } } ChartPrimitive targetPolygon = ChartUtilities.LineDiffToPolygon(populationLine, targetLine); color.A = (byte)(alpha * color.A); targetPolygon.Color = color; targetPolygon.Dashed = true; targetPolygon.ShowInLegend = false; targetLine.HitTest = false; return(new LineAndPolygon(targetLine, targetPolygon)); }
/// <summary> /// Takes two lines and creates a polyon between them /// </summary> /// <param name="baseLine"></param> /// <param name="topLine"></param> /// <returns></returns> public static ChartPrimitive LineDiffToPolygon(ChartPrimitive baseLine, ChartPrimitive topLine) { var polygon = new ChartPrimitive(); if (baseLine != null && topLine != null) { IList <Point> baseLinePoints = baseLine.Points; IList <Point> topLinePoints = topLine.Points; for (int pointNo = baseLinePoints.Count - 1; pointNo >= 0; --pointNo) { polygon.AddPoint(baseLinePoints[pointNo]); } for (int pointNo = 0; pointNo < topLinePoints.Count; ++pointNo) { polygon.AddPoint(topLinePoints[pointNo]); } } polygon.Filled = true; return(polygon); }
/// <summary> /// Converts movements to a graphical line and polygon /// </summary> /// <param name="results"></param> /// <param name="color"></param> /// <param name="label"></param> /// <returns></returns> public static LineAndPolygon ConvertResultsToMovementLineAndPolygon(float[] results, Color color, string label) { // Create the Line var chartLine = new ChartPrimitive(); chartLine.Color = color; chartLine.Label = label; chartLine.ShowInLegend = true; chartLine.HitTest = true; for (int monthNo = 0; monthNo < results.Length; ++monthNo) { chartLine.AddSmoothHorizontalBar(new Point(monthNo + .5f, results[monthNo])); } // Create the polygon ChartPrimitive polygon = ChartUtilities.ChartLineToBaseLinedPolygon(chartLine); color.A = (byte) (alpha*color.A); polygon.Color = color; polygon.ShowInLegend = false; polygon.HitTest = false; return new LineAndPolygon(chartLine, polygon); }
/// <summary> /// Gets ChartLines and ChartPolygons for the population line, and /// the target line. /// </summary> /// <param name="populationLine"></param> /// <param name="results"></param> /// <param name="color"></param> /// <param name="label"></param> /// <returns></returns> public static LineAndPolygon ConvertResultsToTargetLineAndPolygon(ChartPrimitive populationLine, float[] results, Color color, string label) { // Calculate Target Primitives var targetLine = new ChartPrimitive(); targetLine.Color = color; targetLine.Dashed = true; targetLine.Label = label + " Target"; targetLine.ShowInLegend = false; targetLine.HitTest = true; if (populationLine.Points.Count == results.Length) { for (int monthNo = 0; monthNo < results.Length; monthNo += 2) { targetLine.AddPoint(new Point(monthNo*.5f, results[monthNo])); targetLine.AddPoint(new Point(monthNo*.5f + 1f, results[monthNo + 1])); } } else { for (int monthNo = 0; monthNo < results.Length; ++monthNo) { targetLine.AddPoint(new Point(monthNo, results[monthNo])); targetLine.AddPoint(new Point(monthNo + 1f, results[monthNo])); } } ChartPrimitive targetPolygon = ChartUtilities.LineDiffToPolygon(populationLine, targetLine); color.A = (byte) (alpha*color.A); targetPolygon.Color = color; targetPolygon.Dashed = true; targetPolygon.ShowInLegend = false; targetLine.HitTest = false; return new LineAndPolygon(targetLine, targetPolygon); }
/// <summary> /// Converts population level to a line and polygon /// </summary> /// <param name="results"></param> /// <param name="color"></param> /// <param name="label"></param> /// <returns></returns> public static LineAndPolygon ConvertResultsToPopulationLineAndPolygon(float[] results, Color color, string label) { var populationLine = new ChartPrimitive(); populationLine.Color = color; populationLine.Label = label; populationLine.ShowInLegend = true; populationLine.HitTest = true; for (int monthNo = 0; monthNo < results.Length; monthNo += 2) { populationLine.AddPoint(new Point(monthNo * .5f, results[monthNo])); populationLine.AddPoint(new Point(monthNo * .5f + 1f, results[monthNo + 1])); } ChartPrimitive populationPolygon = ChartUtilities.ChartLineToBaseLinedPolygon(populationLine); color.A = (byte)(alpha * color.A); populationPolygon.Color = color; populationPolygon.ShowInLegend = false; populationPolygon.HitTest = false; return(new LineAndPolygon(populationLine, populationPolygon)); }
/// <summary> /// Copy constructor. Deep copies the ChartPrimitive passed in. /// </summary> /// <param name="chartPrimitive"></param> protected ChartPrimitive(ChartPrimitive chartPrimitive) : this() { if (chartPrimitive == null) return; color = chartPrimitive.Color; label = chartPrimitive.Label; filled = chartPrimitive.Filled; showInLegend = chartPrimitive.ShowInLegend; hitTest = chartPrimitive.HitTest; lineThickness = chartPrimitive.LineThickness; dashed = chartPrimitive.Dashed; Points = chartPrimitive.points; CalculateGeometry(); }
public LiveFlightLogDataProvider(XYLineChart positionChart, XYLineChart accelerometerChart, XYLineChart heightChart) { _positionChart = positionChart; _accelerometerChart = accelerometerChart; _heightChart = heightChart; #region Position Top View setup _positionChart.UniformScaling = true; _positionChart.Title = "Position Top View"; _positionChart.XAxisLabel = "X [m]"; _positionChart.YAxisLabel = "Z [m]"; _estimatedGraph = new ChartPrimitive { Filled = false, Dashed = false, ShowInLegend = true, LineThickness = 1.5, HitTest = true, Color = Colors.Navy, Label = "Estimated" }; _blindEstimatedGraph = new ChartPrimitive { Filled = false, Dashed = false, ShowInLegend = true, LineThickness = 1.5, HitTest = true, Color = Colors.LightBlue, Label = "Blind estimated" }; _trueGraph = new ChartPrimitive { Filled = false, Dashed = false, ShowInLegend = true, LineThickness = 1.5, HitTest = true, Color = Colors.DarkRed, Label = "True" }; _observedGraph = new ChartPrimitive { Filled = false, Dashed = false, ShowInLegend = true, LineThickness = 1.5, HitTest = true, Color = Colors.Orange, Label = "GPS" }; #endregion #region Height Data setup _heightChart.Title = "Height data"; _heightChart.XAxisLabel = "Time [s]"; _heightChart.YAxisLabel = "Altitude [m]"; _helicopterHeightGraph = new ChartPrimitive { Filled = false, Dashed = false, ShowInLegend = true, LineThickness = 1.5, HitTest = true, Color = Colors.DarkRed, Label = "True" }; _estimatedHelicopterHeightGraph = new ChartPrimitive { Filled = false, Dashed = false, ShowInLegend = true, LineThickness = 1.5, HitTest = true, Color = Colors.Navy, Label = "Estimated" }; _groundHeightGraph = new ChartPrimitive { Filled = false, Dashed = false, ShowInLegend = true, LineThickness = 1.5, HitTest = true, Color = Colors.DarkGray, Label = "Ground" }; #endregion #region Acceleration Data setup _accelerometerChart.Title = "Accelerometer data"; _accelerometerChart.XAxisLabel = "Time [s]"; _accelerometerChart.YAxisLabel = "Acceleration [m/s²]"; _accelForwardGraph = new ChartPrimitive { Filled = false, Dashed = false, ShowInLegend = true, LineThickness = 1.5, HitTest = true, Color = Colors.Navy, Label = "Accel forward" }; _accelRightGraph = new ChartPrimitive { Filled = false, Dashed = false, ShowInLegend = true, LineThickness = 1.5, HitTest = true, Color = Colors.DarkRed, Label = "Accel right" }; _accelUpGraph = new ChartPrimitive { Filled = false, Dashed = false, ShowInLegend = true, LineThickness = 1.5, HitTest = true, Color = Colors.Orange, Label = "Accel up" }; #endregion }
private static void AppendLineXZ(ChartPrimitive graph, Vector3 plot) { AppendLine(graph, plot.X, plot.Z); }
/// <summary> /// Converts population level to a line and polygon /// </summary> /// <param name="results"></param> /// <param name="color"></param> /// <param name="label"></param> /// <returns></returns> public static LineAndPolygon ConvertResultsToPopulationLineAndPolygon(float[] results, Color color, string label) { var populationLine = new ChartPrimitive(); populationLine.Color = color; populationLine.Label = label; populationLine.ShowInLegend = true; populationLine.HitTest = true; for (int monthNo = 0; monthNo < results.Length; monthNo += 2) { populationLine.AddPoint(new Point(monthNo*.5f, results[monthNo])); populationLine.AddPoint(new Point(monthNo*.5f + 1f, results[monthNo + 1])); } ChartPrimitive populationPolygon = ChartUtilities.ChartLineToBaseLinedPolygon(populationLine); color.A = (byte) (alpha*color.A); populationPolygon.Color = color; populationPolygon.ShowInLegend = false; populationPolygon.HitTest = false; return new LineAndPolygon(populationLine, populationPolygon); }
/// <summary> /// Takes two lines and creates a polyon between them /// </summary> /// <param name="baseLine"></param> /// <param name="topLine"></param> /// <returns></returns> public static ChartPrimitive LineDiffToPolygon(ChartPrimitive baseLine, ChartPrimitive topLine) { var polygon = new ChartPrimitive(); if (baseLine != null && topLine != null) { IList<Point> baseLinePoints = baseLine.Points; IList<Point> topLinePoints = topLine.Points; for (int pointNo = baseLinePoints.Count - 1; pointNo >= 0; --pointNo) { polygon.AddPoint(baseLinePoints[pointNo]); } for (int pointNo = 0; pointNo < topLinePoints.Count; ++pointNo) { polygon.AddPoint(topLinePoints[pointNo]); } } polygon.Filled = true; return polygon; }
/// <summary> /// Adds a set of lines to the chart for test purposes /// </summary> /// <param name="xyLineChart"></param> public static void AddTestLines(XYLineChart xyLineChart) { if (xyLineChart == null) { return; } // Add test Lines to demonstrate the control xyLineChart.Primitives.Clear(); double limit = 5; double increment = .01; // Create 3 normal lines var lines = new ChartPrimitive[3]; for (int lineNo = 0; lineNo < 3; ++lineNo) { var line = new ChartPrimitive(); // Label the lines line.Filled = true; line.Dashed = false; line.ShowInLegend = false; line.AddPoint(0, 0); // Draw 3 sine curves for (double x = 0; x < limit + increment * .5; x += increment) { line.AddPoint(x, Math.Cos(x * Math.PI - lineNo * Math.PI / 1.5)); } line.AddPoint(limit, 0); // Add the lines to the chart xyLineChart.Primitives.Add(line); lines[lineNo] = line; } // Set the line colors to Red, Green, and Blue lines[0].Color = Color.FromArgb(90, 255, 0, 0); lines[1].Color = Color.FromArgb(90, 0, 180, 0); lines[2].Color = Color.FromArgb(90, 0, 0, 255); for (int lineNo = 0; lineNo < 3; ++lineNo) { var line = new ChartPrimitive(); // Label the lines line.Label = "Test Line " + (lineNo + 1); line.ShowInLegend = true; line.HitTest = true; line.LineThickness = 1.5; // Draw 3 sine curves for (double x = 0; x < limit + increment * .5; x += increment) { line.AddPoint(x, Math.Cos(x * Math.PI - lineNo * Math.PI / 1.5)); } // Add the lines to the chart xyLineChart.Primitives.Add(line); lines[lineNo] = line; } // Set the line colors to Red, Green, and Blue lines[0].Color = Colors.Red; lines[1].Color = Colors.Green; lines[2].Color = Colors.Blue; xyLineChart.Title = "Test Chart Title"; xyLineChart.XAxisLabel = "Test Chart X Axis"; xyLineChart.YAxisLabel = "Test Chart Y Axis"; xyLineChart.RedrawPlotLines(); }
private void setupChart() { XYLineChart chart = new XYLineChart(); chart.Height = 126; chart.Width = 486; chart.RenderTransformOrigin = new Point(0.5,0.5); // Add test Lines to demonstrate the control chart.Primitives.Clear(); // Create 3 normal lines ChartPrimitive[] lines = new ChartPrimitive[3]; for (int lineNo = 0; lineNo < 3; ++lineNo) { ChartPrimitive line = new ChartPrimitive(); // Label the lines //line.Label = "Test Line " + (lineNo + 1); line.ShowInLegend = true; //line.HitTest = true; line.LineThickness = 1.5; // Draw 3 sine curves //for (double x = 0; x < limit + increment * .5; x += increment) //{ // line.AddPoint(x, 1); //} //line.AddPoint(0, 1); // Add the lines to the chart chart.Primitives.Add(line); lines[lineNo] = line; } // Set the line colors to Red, Green, and Blue lines[0].Label = "TrainingRate"; lines[1].Label = "AvgTrainMSE"; lines[2].Label = "AvgTestMSE"; lines[0].AddPoint(0, 2); lines[0].AddPoint(33, 2); lines[1].AddPoint(0, 1.5); lines[1].AddPoint(33, 1.5); lines[2].AddPoint(0, 1); lines[2].AddPoint(33, 1); lines[0].Color = Colors.Red; lines[1].Color = Colors.Green; lines[2].Color = Colors.Blue; chart.Title = "TrainingParameters"; chart.XAxisLabel = "TrainingEpoch"; chart.YAxisLabel = "Value"; chart.RedrawPlotLines(); lines[0].Points.Clear(); lines[1].Points.Clear(); lines[2].Points.Clear(); //lines[0].AddPoint(0, 0); //lines[1].AddPoint(0, 0); //lines[2].AddPoint(0, 0); //_xyLineChart = chart; Chart = chart; }
/// <summary> /// Handles the SelectionChanged event of the cmbGraphStat control. /// Calculates and displays the player's performance graph for the newly selected stat. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e"> /// The <see cref="SelectionChangedEventArgs" /> instance containing the event data. /// </param> private void cmbGraphStat_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (cmbGraphStat.SelectedIndex == -1 || cmbTeam.SelectedIndex == -1 || cmbPlayer.SelectedIndex == -1 || _pbsList.Count < 1) { return; } var cp = new ChartPrimitive(); double i = 0; string propToGet = cmbGraphStat.SelectedItem.ToString(); propToGet = propToGet.Replace('3', 'T'); propToGet = propToGet.Replace('%', 'p'); double sum = 0; double games = 0; foreach (PlayerBoxScore pbs in _pbsList) { i++; double value = Convert.ToDouble(typeof (PlayerBoxScore).GetProperty(propToGet).GetValue(pbs, null)); if (!double.IsNaN(value)) { if (propToGet.Contains("p")) { value = Convert.ToDouble(Convert.ToInt32(value*1000))/1000; } cp.AddPoint(i, value); games++; sum += value; } } cp.Label = cmbGraphStat.SelectedItem.ToString(); cp.ShowInLegend = false; chart.Primitives.Clear(); if (cp.Points.Count > 0) { double average = sum/games; var cpavg = new ChartPrimitive(); for (int j = 1; j <= i; j++) { cpavg.AddPoint(j, average); } cpavg.Color = Color.FromRgb(0, 0, 100); cpavg.Dashed = true; cpavg.ShowInLegend = false; chart.Primitives.Add(cpavg); chart.Primitives.Add(cp); } chart.RedrawPlotLines(); var cp2 = new ChartPrimitive(); cp2.AddPoint(1, 0); cp2.AddPoint(i, 1); chart.Primitives.Add(cp2); chart.ResetPanAndZoom(); }
public void AddToComparison(FlightLog flightLog, Color graphColor, string label, double thickness) { var posGraph = new ChartPrimitive { Filled = false, Dashed = false, ShowInLegend = true, LineThickness = thickness, HitTest = true, Color = graphColor, Label = label }; var altitudeGraph = new ChartPrimitive { Filled = false, Dashed = false, ShowInLegend = true, LineThickness = thickness, HitTest = true, Color = graphColor, Label = label }; _positionChart.Primitives.Add(posGraph); _heightChart.Primitives.Add(altitudeGraph); if (_comparisonIsEmpty) _heightChart.Primitives.Add(_groundHeightGraph); // _waypointMarkers = new ChartMarkerSet(_waypointGraph) // { // Stroke = Colors.Black, // Fill = Color.FromArgb(150, 255, 255, 0), // Size = 20, // StrokeWidth = 1, // }; // // _positionChart.MarkerSets.Add(_waypointMarkers); foreach (var snapshot in flightLog.Plots) { AppendLineXZ(posGraph, snapshot.True.Position); AppendLine(altitudeGraph, snapshot.Time.TotalSeconds, snapshot.True.Position.Y); if (_comparisonIsEmpty) AppendLine(_groundHeightGraph, snapshot.Time.TotalSeconds, snapshot.GroundAltitude); } // foreach (Waypoint waypoint in flightLog.Waypoints) // { // _waypointMarkers.AddPoint(new ChartPoint("", // new Point(waypoint.Position.X, waypoint.Position.Z))); // } RenderAndSetScale(flightLog.Plots.Last().Time); _comparisonIsEmpty = false; }
private void updateGraph() { if (cmbGraphStat.SelectedIndex == -1 || cmbTeam.SelectedIndex == -1 || cmbGraphInterval.SelectedIndex == -1) { clearGraph(); return; } var intervalItem = cmbGraphInterval.SelectedItem.ToString(); var yearlyRows = _dtYea.Rows.Cast<DataRow>().Where(dr => dr[0].ToString().StartsWith("Season")).ToList(); var monthlyStats = MainWindow.SplitTeamStats[_curts.ID].Where(pair => pair.Key.StartsWith("M ")).ToList(); var orderedBSEList = _bseList.OrderBy(bse => bse.BS.GameDate).ToList(); Intervals interval; int count; switch (intervalItem) { case "Every Game": interval = Intervals.EveryGame; count = orderedBSEList.Count; break; case "Monthly": interval = Intervals.Monthly; count = monthlyStats.Count; break; case "Yearly": interval = Intervals.Yearly; count = yearlyRows.Count; break; default: throw new ArgumentOutOfRangeException(); } if (count < 2) { clearGraph(); return; } var propToGet = cmbGraphStat.SelectedItem.ToString(); propToGet = propToGet.Replace('3', 'T'); propToGet = propToGet.Replace('%', 'p'); propToGet = propToGet.Replace("TO", "TOS"); double sum = 0; double games = 0; chart.Primitives.Clear(); var cp = new ChartPrimitive { Label = cmbGraphStat.SelectedItem.ToString(), ShowInLegend = false }; switch (interval) { case Intervals.EveryGame: for (var i = 0; i < count; i++) { var bse = orderedBSEList[i]; bse.BS.PrepareForDisplay(_tst, _curts.ID); var isTeamAway = bse.BS.Team1ID == _curts.ID; var propToGetFinal = propToGet; if (propToGet == "PF") { propToGetFinal = isTeamAway ? "PTS1" : "PTS2"; } else if (propToGet == "PA") { propToGetFinal = isTeamAway ? "PTS2" : "PTS1"; } else { propToGetFinal += (isTeamAway ? 1 : 2).ToString(); } var value = bse.BS.GetValue<TeamBoxScore, double>(propToGetFinal); if (double.IsNaN(value)) { continue; } if (propToGet.Contains("p")) { value = Convert.ToDouble(Convert.ToInt32(value * 1000)) / 1000; } cp.AddPoint(i + 1, value); games++; sum += value; } break; case Intervals.Monthly: monthlyStats = monthlyStats.OrderBy(ms => ms.Key).ToList(); if (TeamStatsHelper.TotalsToPerGame.ContainsKey(propToGet)) { propToGet = TeamStatsHelper.TotalsToPerGame[propToGet]; } for (var i = 0; i < count; i++) { var ts = monthlyStats[i].Value; ts.CalcMetrics(new TeamStats()); var tsr = new TeamStatsRow(ts); var value = tsr.GetValue<double>(propToGet); if (double.IsNaN(value)) { continue; } if (propToGet.Contains("p")) { value = Convert.ToDouble(Convert.ToInt32(value * 1000)) / 1000; } cp.AddPoint(i + 1, value); games++; sum += value; } break; case Intervals.Yearly: if (TeamStatsHelper.TotalsToPerGame.ContainsKey(propToGet)) { propToGet = TeamStatsHelper.TotalsToPerGame[propToGet]; } for (var i = 0; i < count; i++) { var ts = new TeamStats(); createTeamStatsFromDataRow(ref ts, _dtYea.Rows.Cast<DataRow>().ToList()[i]); ts.CalcMetrics(new TeamStats()); var tsr = new TeamStatsRow(ts); var value = tsr.GetValue<TeamStatsRow, double>(propToGet); if (double.IsNaN(value)) { continue; } if (propToGet.Contains("p")) { value = Convert.ToDouble(Convert.ToInt32(value * 1000)) / 1000; } cp.AddPoint(i + 1, value); games++; sum += value; } break; default: throw new ArgumentOutOfRangeException(); } if (cp.Points.Count > 0) { chart.Primitives.Add(cp); } if (chart.Primitives.Count > 0 && chart.Primitives.Sum(p => p.Points.Count) > 1) { //var average = sum / games; if (TeamStatsHelper.TotalsToPerGame.ContainsKey(propToGet)) { propToGet = TeamStatsHelper.TotalsToPerGame[propToGet]; } double average; switch (interval) { case Intervals.EveryGame: case Intervals.Monthly: average = _curTSR.GetValue<double>(propToGet); break; case Intervals.Yearly: var ts = new TeamStats(); createTeamStatsFromDataRow(ref ts, _dtYea.Rows.Cast<DataRow>().ToList().Last()); ts.CalcMetrics(new TeamStats()); var tsr = new TeamStatsRow(ts); average = tsr.GetValue<double>(propToGet); break; default: throw new ArgumentOutOfRangeException(); } var cpavg = new ChartPrimitive(); for (var i = 0; i < count; i++) { cpavg.AddPoint(i + 1, average); } cpavg.Color = Color.FromRgb(0, 0, 100); cpavg.Dashed = true; cpavg.ShowInLegend = false; var cp2 = new ChartPrimitive(); cp2.AddPoint(chart.Primitives.First().Points.First().X, 0); cp2.AddPoint(chart.Primitives.Last().Points.Last().X, 1); chart.Primitives.Add(cpavg); chart.RedrawPlotLines(); chart.Primitives.Add(cp2); } else { chart.RedrawPlotLines(); var cp2 = new ChartPrimitive(); cp2.AddPoint(1, 0); cp2.AddPoint(2, 1); chart.Primitives.Add(cp2); } chart.ResetPanAndZoom(); }
//GetPlotRectangle /// <summary> /// Converts a ChartLine object to a ChartPolygon object that has /// one edge along the bottom Horizontal base line in the plot. /// </summary> /// <param name="chartLine"></param> /// <returns></returns> public static ChartPrimitive ChartLineToBaseLinedPolygon(ChartPrimitive chartLine) { ChartPrimitive chartPolygon = chartLine != null ? chartLine.Clone() : new ChartPrimitive(); if (chartPolygon.Points.Count > 0) { Point firstPoint = chartPolygon.Points[0]; firstPoint.Y = 0; Point lastPoint = chartPolygon.Points[chartPolygon.Points.Count - 1]; lastPoint.Y = 0; chartPolygon.InsertPoint(firstPoint, 0); chartPolygon.AddPoint(lastPoint); } chartPolygon.Filled = true; return chartPolygon; }
private static void AppendLine(ChartPrimitive graph, double x, float y) { graph.AddPoint(new Point(x, y)); if (graph.Points.Count > MaxPlots) graph.Points.RemoveAt(0); }
/// <summary> /// Adds a set of lines to the chart for test purposes /// </summary> /// <param name="xyLineChart"></param> public static void AddTestLines(XYLineChart xyLineChart) { if (xyLineChart == null) return; // Add test Lines to demonstrate the control xyLineChart.Primitives.Clear(); double limit = 5; double increment = .01; // Create 3 normal lines var lines = new ChartPrimitive[3]; for (int lineNo = 0; lineNo < 3; ++lineNo) { var line = new ChartPrimitive(); // Label the lines line.Filled = true; line.Dashed = false; line.ShowInLegend = false; line.AddPoint(0, 0); // Draw 3 sine curves for (double x = 0; x < limit + increment*.5; x += increment) { line.AddPoint(x, Math.Cos(x*Math.PI - lineNo*Math.PI/1.5)); } line.AddPoint(limit, 0); // Add the lines to the chart xyLineChart.Primitives.Add(line); lines[lineNo] = line; } // Set the line colors to Red, Green, and Blue lines[0].Color = Color.FromArgb(90, 255, 0, 0); lines[1].Color = Color.FromArgb(90, 0, 180, 0); lines[2].Color = Color.FromArgb(90, 0, 0, 255); for (int lineNo = 0; lineNo < 3; ++lineNo) { var line = new ChartPrimitive(); // Label the lines line.Label = "Test Line " + (lineNo + 1); line.ShowInLegend = true; line.HitTest = true; line.LineThickness = 1.5; // Draw 3 sine curves for (double x = 0; x < limit + increment*.5; x += increment) { line.AddPoint(x, Math.Cos(x*Math.PI - lineNo*Math.PI/1.5)); } // Add the lines to the chart xyLineChart.Primitives.Add(line); lines[lineNo] = line; } // Set the line colors to Red, Green, and Blue lines[0].Color = Colors.Red; lines[1].Color = Colors.Green; lines[2].Color = Colors.Blue; xyLineChart.Title = "Test Chart Title"; xyLineChart.XAxisLabel = "Test Chart X Axis"; xyLineChart.YAxisLabel = "Test Chart Y Axis"; xyLineChart.RedrawPlotLines(); }
private void updateGraph() { if (cmbGraphStat.SelectedIndex == -1 || cmbGraphInterval.SelectedIndex == -1 || cmbTeam.SelectedIndex == -1 || cmbPlayer.SelectedIndex == -1) { clearGraph(); return; } var intervalItem = cmbGraphInterval.SelectedItem.ToString(); var yearlyStats = _yearlyPSRList.Where(psr => psr.Type.StartsWith("Season ")).ToList(); var monthlyStats = MainWindow.SplitPlayerStats[_psr.ID].Where(pair => pair.Key.StartsWith("M ")).ToList(); int count; Intervals interval; switch (intervalItem) { case "Every Game": interval = Intervals.EveryGame; count = _pbsListWithOut.Count; break; case "Monthly": interval = Intervals.Monthly; count = monthlyStats.Count; break; case "Yearly": interval = Intervals.Yearly; count = yearlyStats.Count; break; default: throw new ArgumentOutOfRangeException(); } if (count < 2) { clearGraph(); return; } var propToGet = cmbGraphStat.SelectedItem.ToString(); propToGet = propToGet.Replace('3', 'T'); propToGet = propToGet.Replace('%', 'p'); propToGet = propToGet.Replace("TO", "TOS"); double sum = 0; double games = 0; chart.Primitives.Clear(); var cp = new ChartPrimitive { Label = cmbGraphStat.SelectedItem.ToString(), ShowInLegend = false }; switch (interval) { case Intervals.EveryGame: var orderedPBSList = _pbsListWithOut.OrderBy(pbs => pbs.RealDate).ToList(); for (var i = 0; i < orderedPBSList.Count; i++) { var pbs = orderedPBSList[i]; if (pbs.IsOut) { if (cp.Points.Count > 0) { chart.Primitives.Add(cp.CustomClone()); cp = new ChartPrimitive { Label = cmbGraphStat.SelectedItem.ToString(), ShowInLegend = false }; } continue; } var value = Convert.ToDouble(typeof(PlayerBoxScore).GetProperty(propToGet).GetValue(pbs, null)); if (double.IsNaN(value)) { continue; } if (propToGet.Contains("p")) { value = Convert.ToDouble(Convert.ToInt32(value * 1000)) / 1000; } cp.AddPoint(i + 1, value); games++; sum += value; } break; case Intervals.Monthly: case Intervals.Yearly: if (interval == Intervals.Monthly) { monthlyStats = monthlyStats.OrderBy(ms => ms.Key).ToList(); } if (PlayerStatsHelper.TotalsToPerGame.ContainsKey(propToGet)) { propToGet = PlayerStatsHelper.TotalsToPerGame[propToGet]; } for (var i = 0; i < count; i ++) { var ps = interval == Intervals.Monthly ? monthlyStats[i].Value : new PlayerStats(yearlyStats[i]); if (ps.Totals[PAbbrT.GP] == 0) { if (cp.Points.Count > 0) { chart.Primitives.Add(cp.CustomClone()); cp = new ChartPrimitive { Label = cmbGraphStat.SelectedItem.ToString(), ShowInLegend = false }; } continue; } var dummyTs = new TeamStats(); ps.CalcMetrics(dummyTs, dummyTs, dummyTs, GmScOnly: true); var psr = new PlayerStatsRow(ps, calcRatings: false); var value = psr.GetValue<double>(propToGet); if (double.IsNaN(value)) { continue; } if (propToGet.Contains("p")) { value = Convert.ToDouble(Convert.ToInt32(value * 1000)) / 1000; } cp.AddPoint(i + 1, value); games++; sum += value; } break; default: throw new ArgumentOutOfRangeException(); } if (cp.Points.Count > 0) { chart.Primitives.Add(cp.CustomClone()); } if (chart.Primitives.Count > 0 && chart.Primitives.Sum(p => p.Points.Count) > 1) { if (PlayerStatsHelper.TotalsToPerGame.ContainsKey(propToGet)) { propToGet = PlayerStatsHelper.TotalsToPerGame[propToGet]; } double average; switch (interval) { case Intervals.EveryGame: case Intervals.Monthly: average = _psr.GetValue<double>(propToGet); break; case Intervals.Yearly: average = _yearlyPSRList.Last().GetValue<double>(propToGet); break; default: throw new ArgumentOutOfRangeException(); } //var average = sum / games; var cpavg = new ChartPrimitive(); for (var i = 0; i < count; i++) { cpavg.AddPoint(i + 1, average); } cpavg.Color = Color.FromRgb(0, 0, 100); cpavg.Dashed = true; cpavg.ShowInLegend = false; var cp2 = new ChartPrimitive(); cp2.AddPoint(chart.Primitives.First().Points.First().X, 0); cp2.AddPoint(chart.Primitives.Last().Points.Last().X, 1); chart.Primitives.Add(cpavg); chart.RedrawPlotLines(); chart.Primitives.Add(cp2); } else { chart.RedrawPlotLines(); var cp2 = new ChartPrimitive(); cp2.AddPoint(1, 0); cp2.AddPoint(2, 1); chart.Primitives.Add(cp2); } chart.ResetPanAndZoom(); }