// // Plot total crimes by area: // private void plotTotalCrimesByAreaToolStripMenuItem_Click(object sender, EventArgs e) { // // let's use a separate window to show the graph: // FormPlot plot = new FormPlot(); // // Compute and plot total # of crimes by each area: // string filename = this.txtDBFile.Text; BusinessTier.Business biztier; biztier = new BusinessTier.Business(filename); if (biztier.OpenCloseConnection() == false) { MessageBox.Show("error"); return; } Dictionary <int, long> stats = biztier.GetTotalsByArea(); // // We have the data, now let's setup and plot in the chart // on the other form: // plot.chart1.Series.Clear(); // configure chart: var series1 = new CHART.Series { Name = "Total Crimes", Color = System.Drawing.Color.Blue, IsVisibleInLegend = true, IsXValueIndexed = true, ChartType = CHART.SeriesChartType.Line }; plot.chart1.Series.Add(series1); plot.chart1.ChartAreas[0].AxisX.Interval = 5; // now plot (x, y) coordinates: foreach (int area in stats.Keys) { int x = area; long y = stats[area]; series1.Points.AddXY(x, y); } // // All set, show the window to the user --- note that if user // does not close window, it will be closed automatically when // this main window exits. // plot.Text = "** Total Crimes by Area **"; plot.Location = new System.Drawing.Point(20, 20); // top-left: plot.Show(); }
// // Plot total crimes by month: // private void plotTotalCrimesByMonthToolStripMenuItem_Click(object sender, EventArgs e) { // // let's use a separate window to show the graph: // FormPlot plot = new FormPlot(); // // Compute and plot total # of crimes by each area: // string filename = this.txtDBFile.Text; BusinessTier.Business biztier; biztier = new BusinessTier.Business(filename); if (biztier.OpenCloseConnection() == false) { MessageBox.Show("error"); return; } Dictionary <int, long> stats = biztier.GetTotalsByMonth(); // // We have the data, now let's setup and plot in the chart // on the other form: // plot.chart1.Series.Clear(); // configure chart: var series1 = new CHART.Series { Name = "Total Crimes", Color = System.Drawing.Color.Blue, IsVisibleInLegend = true, ChartType = CHART.SeriesChartType.Line }; plot.chart1.Series.Add(series1); // now plot (x, y) coordinates: string[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct","Nov", "Dec" }; foreach (int month in stats.Keys) { int x = month; long y = stats[month]; var point = new CHART.DataPoint(x, y); point.Label = months[x - 1]; series1.Points.Add(point); } // // All set, show the window to the user --- note that if user // does not close window, it will be closed automatically when // this main window exits. // plot.Text = "** Total Crimes by Month **"; plot.Location = new System.Drawing.Point(40, 40); // top-left: plot.Show(); }