public void addStation(int code) { var s = stations.Find(x => x.code == code); if (s == null) { StationMonthly sm = new StationMonthly(code); stations.Add(sm); } }
private void multiMonthLineGraph(StationMonthly sm) { ZedGraphControl zgc = new ZedGraphControl(); MasterPane master = zgc.MasterPane; master.Rect = new RectangleF(0, 0, 2400, 600); master.PaneList.Clear(); master.Title.IsVisible = true; master.Title.Text = sm.code.ToString(); master.Margin.All = 10; master.Legend.IsVisible = false; GraphPane pane1 = new GraphPane(); pane1.Legend.IsVisible = true; pane1.YAxis.Title.Text = "n records"; pane1.XAxis.Title.Text = "cumulative months"; //find the first month and year of all monthlytotals //generate yaxis titles int startYear = 0; int startMonth = 0; sm.firstMonth(ref startYear, ref startMonth); int endYear = 0; int endMonth = 0; sm.lastMonth(ref endYear, ref endMonth); DateTime startDate = new DateTime(); if (startYear != 10000) { startDate = new DateTime(startYear, startMonth, 1); } DateTime endDate = new DateTime(); if (endYear != 0) { endDate = new DateTime(endYear, endMonth, 1); } int monthsSpan = (int)Math.Round((endDate - startDate).Days / 30.0, 1); foreach (VariableMonthly vm in sm.variablesMonthly) { Color col; switch (vm.variableName) { case "VV": col = Color.Red; break; case "DV": col = Color.DodgerBlue; break; case "NUB": col = Color.ForestGreen; break; case "RS": col = Color.BlueViolet; break; case "TS": col = Color.Red; break; case "HR": col = Color.LawnGreen; break; case "PR": col = Color.Orchid; break; default: col = Color.Black; break; } List <double> xvalues = new List <double>(); List <double> yvalues = new List <double>(); for (int m = 0; m <= monthsSpan + 1; m++) { xvalues.Add(m); yvalues.Add(0); } List <MonthValue> monthlyvalues = new List <MonthValue>(); foreach (MonthTotal mt in vm.monthlytotals) { if (mt.month == 0 || mt.year == 0) { continue; } DateTime date = new DateTime(mt.year, mt.month, 1); int datediff = (int)Math.Round((date - startDate).TotalDays / 30.0, 1); if (vm.interval == 10) { yvalues[datediff] = mt.total / 6; } else { yvalues[datediff] = mt.total; } } double[] x = xvalues.ToArray(); double[] y = yvalues.ToArray(); LineItem myCurve = new LineItem(vm.variableName, x, y, col, SymbolType.None, 3.0f); pane1.CurveList.Add(myCurve); } master.Add(pane1); // Refigure the axis ranges for the GraphPanes zgc.AxisChange(); // Layout the GraphPanes using a default Pane Layout Bitmap b = new Bitmap(600, 1200); using (Graphics g = Graphics.FromImage(b)) { master.SetLayout(g, PaneLayout.SingleColumn); } master.GetImage().Save(@"D:\WORK\piloto\Climate\monthlyGraphs\" + sm.code.ToString() + ".jpeg", System.Drawing.Imaging.ImageFormat.Jpeg); }