/// <summary> /// Opens a given CSV file containing date-time entries for a specific exercise and creates OxyPlot /// line and scatter series for which to graph. The axes for the graph are standard value (int/float) axes. /// </summary> /// <param name="file">Given a string file name, in this case a path /// for where the CSV file specific to which exercise you want to plot</param> /// <returns>Returns a plot model created above</returns> public PlotModel OpenDoubles(string file) { var doc = new CsvDocument(); doc.Load(file); var tmp = new PlotModel { Title = "Generated User Report" }; tmp.IsLegendVisible = false; tmp.PlotMargins = new OxyThickness(50, 0, 0, 40); for (int i = 1; i < doc.Headers.Length; i++) { var ls = new LineSeries { Title = doc.Headers[i] }; foreach (var item in doc.Items) { double x = ParseDouble(item[0]); double y = ParseDouble(item[i]); ls.Points.Add(new DataPoint(x, y)); } tmp.Series.Add(ls); } tmp.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = doc.Headers[0], TickStyle = TickStyle.Inside }); tmp.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = doc.Headers[1], TickStyle = TickStyle.Inside }); return(tmp); }
/// <summary> /// Opens a given CSV file containing date-time entries for a specific exercise and creates OxyPlot /// line and scatter series for which to graph. The axes for the graph are date-time axes for /// plotting data that is in date-time format. The axes headers correspond to columns in the CSV file /// and the items of those headers are added to the line/scatter series. /// </summary> /// <param name="file">Given a string file name, in this case a path /// for where the CSV file specific to which exercise you want to plot</param> /// <returns>Returns a plot model created above</returns> public PlotModel OpenTimes(string file) { var doc = new CsvDocument(); doc.Load(file); var tmp = new PlotModel { Title = "Exercise Duration Over Time" }; tmp.IsLegendVisible = false; tmp.PlotMargins = new OxyThickness(50, 0, 0, 40); for (int i = 1; i < doc.Headers.Length; i++) { var ls = new ScatterSeries { Title = doc.Headers[i] }; foreach (var item in doc.Items) { var t1 = TimeSpan.Parse(item[0]); var t2 = DateTime.Parse(item[i]); double x = DateTimeAxis.ToDouble(t2); double y = TimeSpanAxis.ToDouble(t1); ls.Points.Add(new ScatterPoint(x, y)); } tmp.Series.Add(ls); } /* Here we create the second plotting series. This is done because * because we want our plotted points to be connected which is done * by drawing a secondary line series instead of a scatter series. * This gives the desired effect of a point-connected graph. */ for (int i = 1; i < doc.Headers.Length; i++) { var ls = new LineSeries { Title = doc.Headers[i] }; foreach (var item in doc.Items) { var t1 = TimeSpan.Parse(item[0]); var t2 = DateTime.Parse(item[i]); double x = DateTimeAxis.ToDouble(t2); double y = TimeSpanAxis.ToDouble(t1); ls.Points.Add(new DataPoint(x, y)); } tmp.Series.Add(ls); } // This will be the Left Y Axis tmp.Axes.Add(new TimeSpanAxis { Position = AxisPosition.Left, Title = doc.Headers[0], TickStyle = TickStyle.Inside, }); // This will be the Bottom X Axis tmp.Axes.Add(new DateTimeAxis { Position = AxisPosition.Bottom, Title = doc.Headers[1], TickStyle = TickStyle.Inside, StringFormat = "MM/dd/yyyy" }); return(tmp); }