private void ValueLabelChangedHandler(object sender, EventArgs e) { ValueLabelsCollection vls = c1Chart1.ChartArea.AxisX.ValueLabels; string minMarker = "M1", maxMarker = "M2"; if (vls["M1"].NumericValue > vls["M2"].NumericValue) { minMarker = "M2"; maxMarker = "M1"; } float minValue = (float)vls[minMarker].NumericValue; float maxValue = (float)vls[maxMarker].NumericValue; string name = (string)zoneSelect.Items[3]; AlarmZone az = c1Chart1.ChartArea.PlotArea.AlarmZones[name]; int gi = az.GroupIndex; int si = az.PolygonData.SeriesIndex; ChartGroup cg = c1Chart1.ChartGroups[gi]; ChartDataSeries cds = cg.ChartData.SeriesList[si]; PointF[] pfs = (PointF[])cds.PointData.CopyDataOut(); int pmin = -1, pmax = -1; float minY = float.MaxValue, maxY = float.MinValue; for (int p = 0; p < pfs.Length; p++) { if (pmin < 0 && pfs[p].X >= minValue) { pmin = p; } if (pmax < 0 && pfs[p].X >= maxValue) { pmax = (pfs[p].X == maxValue) ? p : p - 1; break; } if (pmin >= 0) { if (pfs[p].Y < minY) { minY = pfs[p].Y; } if (pfs[p].Y > maxY) { maxY = pfs[p].Y; } } } az.NearExtent = pfs[pmin].X; az.FarExtent = pfs[pmax].X; az.UpperExtent = maxY; az.LowerExtent = minY; }
//set up Alarm Zones private void LoadZones() { c1Chart1.ChartArea.AxisX.GridMajor.Visible = false; c1Chart1.ChartArea.AxisY.GridMajor.Visible = false; c1Chart1.ChartArea.AxisX.GridMinor.Visible = false; c1Chart1.ChartArea.AxisY.GridMinor.Visible = false; double[] values = (double [])c1Chart1.ChartGroups.Group0.ChartData.SeriesList[0].Y.CopyDataOut(); Array.Sort(values); //get the bounds of each zone double[] ZoneBounds = new double[] { values[GetBoundingIndex(values, 0.95)], values[GetBoundingIndex(values, 0.75)], values[GetBoundingIndex(values, 0.25)], values[GetBoundingIndex(values, 0.05)] }; //add and show the alarm zones AlarmZonesCollection zones = c1Chart1.ChartArea.PlotArea.AlarmZones; zones.Clear(); for (int i = 0; i < 5; i++) { AlarmZone zone = zones.AddNewZone(); zone.Name = ZoneText[i]; zone.BackColor = ZoneColor[i]; zone.PatternStyle = patterns[i]; zone.PatternVisible = chkPatterns.Checked; if (i == 0) { zone.UpperExtent = c1Chart1.ChartArea.AxisY.Max; } else { zone.UpperExtent = zones[i - 1].LowerExtent; } if (i == 4) { zone.LowerExtent = c1Chart1.ChartArea.AxisY.Min; } else { zone.LowerExtent = ZoneBounds[i]; } zone.Visible = true; } }
private void UpdateZones() { if (c1Chart1.ChartArea.PlotArea.AlarmZones.Count == 0) { for (int i = 10; i < c1Chart1.ChartArea.AxisY.Max; i += 20) { AlarmZone az = c1Chart1.ChartArea.PlotArea.AlarmZones.AddNewZone(); az.LowerExtent = i; az.UpperExtent = i + 10; az.BackColor = Color.WhiteSmoke; az.Visible = true; } } }
private void c1Chart1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { AlarmZonesCollection zones = c1Chart1.ChartArea.PlotArea.AlarmZones; AlarmZone az = zones.AlarmZoneAtCoord(e.X, e.Y); if (az != null) { Cursor.Current = Cursors.Cross; c1Chart1.Header.Text = "Mouse is over " + az.Name; } else { Cursor.Current = Cursors.Default; c1Chart1.Header.Text = "-- Mouse is not over an AlarmZone --"; } }
public SensorLink(SensorCore source, AlarmZone target, IManager manager) : base(manager) { source.addLink(OnSensorTriggeredEvent); this.sensor = source; this.alarmZone = target; }
private void Form1_Load(object sender, System.EventArgs e) { Form1_Resize(null, null); c1Chart1.ChartArea.AxisY.SetMinMax(0, 30); // using the routine GetPoints defined above, create some // additional data and add it to the chart. PointF[] pfs = GetPoints(3, 201, 1, 5, 1, 7.5); ChartDataSeriesCollection cdsc = c1Chart1.ChartGroups[0].ChartData.SeriesList; ChartDataSeries cds = cdsc.AddNewSeries(); cds.PointData.CopyDataIn(pfs); cds.SymbolStyle.Shape = SymbolShapeEnum.None; // turn on all of the checked listbox items. for (int z = 0; z < zoneSelect.Items.Count; z++) { zoneSelect.SetItemChecked(z, true); } // create the alarm zones. AlarmZonesCollection azs = c1Chart1.ChartArea.PlotArea.AlarmZones; // add the rectangle AlarmZone az = azs.AddNewZone(); az.Name = (string)zoneSelect.Items[0]; az.BackColor = Color.FromArgb(100, Color.Red); az.Shape = AlarmZoneShapeEnum.Rectangle; az.UpperExtent = 20; az.LowerExtent = 16; az.FarExtent = 2.5; az.NearExtent = 1.5; az.Visible = true; // add the ellipse az = azs.AddNewZone(); az.BackColor = Color.FromArgb(100, Color.Blue); az.Shape = AlarmZoneShapeEnum.Ellipse; az.Name = (string)zoneSelect.Items[1]; az.UpperExtent = 24; az.LowerExtent = 16; az.FarExtent = 4.5; az.NearExtent = 3; az.Visible = true; // add a polygon defined by coordinates. Coordinates // are obtained using the GetPoints method defined above. az = azs.AddNewZone(); az.BackColor = Color.FromArgb(100, Color.Green); az.Shape = AlarmZoneShapeEnum.Polygon; az.Name = (string)zoneSelect.Items[2]; az.UpperExtent = 14; az.LowerExtent = 8; az.FarExtent = 4.5; az.NearExtent = 2.5; pfs = GetPoints(1, 15, az.NearExtent, az.FarExtent, az.LowerExtent, az.UpperExtent); az.PolygonData.PointData.CopyDataIn(pfs); az.Visible = true; // add a polygon az = azs.AddNewZone(); az.BackColor = Color.FromArgb(100, Color.Yellow); az.PatternStyle = HatchStyle.DiagonalBrick; az.PatternVisible = true; az.Shape = AlarmZoneShapeEnum.Rectangle; az.Name = (string)zoneSelect.Items[4]; az.UpperExtent = 24; az.LowerExtent = 24; az.FarExtent = 3; az.NearExtent = 3; az.MinHeight = 32; az.MinWidth = 32; az.Visible = true; // add another polygon defined by the DataSeries. az = azs.AddNewZone(); az.BackColor = Color.FromArgb(100, Color.Brown); az.Shape = AlarmZoneShapeEnum.Polygon; az.PolygonData.PolygonSource = PolygonSourceEnum.DataSeries; az.PolygonData.SeriesIndex = 4; az.Name = (string)zoneSelect.Items[3]; az.UpperExtent = 10; az.LowerExtent = 6; az.NearExtent = 1.15; az.FarExtent = 2.25; az.Visible = true; // Add a Header that will be updated to the current AlarmZone // under the cursor. c1Chart1.Header.Text = "-- Mouse is not over an AlarmZone --"; // now select the first alarmzone zoneSelect.SelectedIndex = 0; // Add some marker style ValueLabels. These will be used to // mark the Near and Far extents of the DataSeries AlarmZone Axis ax = c1Chart1.ChartArea.AxisX; ax.AnnoMethod = AnnotationMethodEnum.Mixed; ValueLabel vl = ax.ValueLabels.AddNewLabel(); vl.Appearance = ValueLabelAppearanceEnum.ArrowMarker; vl.Text = "M1"; vl.Color = Color.FromArgb(100, Color.Red); vl.GridLine = true; vl.Moveable = true; vl.NumericValue = az.NearExtent; vl.ValueChanged += new EventHandler(ValueLabelChangedHandler); //!!VBSubst AddHandler vl.ValueChanged, AddressOf ValueLabelChangedHandler vl.MarkerSize = 13; vl = ax.ValueLabels.AddNewLabel(); vl.Appearance = ValueLabelAppearanceEnum.ArrowMarker; vl.Text = "M2"; vl.Color = Color.FromArgb(100, Color.Red); vl.GridLine = true; vl.Moveable = true; vl.NumericValue = az.FarExtent; vl.ValueChanged += new EventHandler(ValueLabelChangedHandler); //!!VBSubst AddHandler vl.ValueChanged, AddressOf ValueLabelChangedHandler vl.MarkerSize = 13; // Call it to get markers and extensions recalculated. ValueLabelChangedHandler(null, null); // Add some instructions about how to use the markers. c1Chart1.Footer.Text = "Drag markers M1 and M2 along the X axis\n" + "to adjust the extents of the DataSeries sourced AlarmZone"; }
private void toolStripButton1_Click(object sender, EventArgs e) { if (r1.RadioChecked && (sjEnd.Value < sjBegin.Value)) { MessageBox.Show("结束时间应该比开始时间大!"); return; } c1Chart1.ChartGroups[0].ChartData.SeriesList.Clear(); int gaolu = 0; switch (this.toolStrip_gaolu.Text) { case "1高炉": gaolu = 1; break; case "2高炉": gaolu = 2; break; case "3高炉": gaolu = 3; break; case "4高炉": gaolu = 4; break; case "5高炉": gaolu = 5; break; case "6高炉": gaolu = 6; break; } // Add the data ChartData data = c1Chart1.ChartGroups[0].ChartData; ChartDataSeriesCollection series = data.SeriesList; double[] dy; double max; double min; LegendEnviroment.loadRSetting(out dy, out max, out min); c1Chart1.ChartArea.AxisY.Max = max; c1Chart1.ChartArea.AxisY.Min = min; Color[] dyColor = new Color[] { Color.FromArgb(255, 192, 192), Color.FromArgb(255, 255, 192), Color.FromArgb(192, 255, 192), Color.FromArgb(255, 255, 192), Color.FromArgb(255, 192, 192) }; string[] dyName = new string[] { "过大", "有点大", "正常", "有点小", "过小" }; //plot the student scores ChartDataSeries StuSeries = series.AddNewSeries(); StuSeries.Label = "Si(炉温)趋势"; StuSeries.LineStyle.Pattern = LinePatternEnum.Solid; StuSeries.LineStyle.Color = Color.DarkBlue; StuSeries.SymbolStyle.Shape = SymbolShapeEnum.Star; StuSeries.SymbolStyle.Color = Color.DarkRed; if (r1.RadioChecked) { c1Chart1.ChartArea.AxisX.AnnoFormat = FormatEnum.DateManual; c1Chart1.ChartArea.AxisX.AnnoFormatString = "MM/dd HH:mm"; c1Chart1.ChartArea.AxisX.AnnotationRotation = 0; DateTime[] siT; double[] si; LegendEnviroment.loadR(gaolu, sjBegin.Value, sjEnd.Value, out siT, out si); StuSeries.X.CopyDataIn(siT); StuSeries.Y.CopyDataIn(si); StuSeries = null; c1Chart1.Footer.Text = this.toolStrip_gaolu.Text + " " + this.sjBegin.Text + " ---- " + this.sjEnd.Text; DateTime[] ax = new DateTime[] { sjBegin.Value, sjEnd.Value }; for (int i = 0; i < 4; i++) { double[] ay1 = new double[] { dy[i], dy[i] }; StuSeries = series.AddNewSeries(); StuSeries.Label = "最大值"; StuSeries.LineStyle.Pattern = LinePatternEnum.Solid; StuSeries.LineStyle.Color = Color.Black; StuSeries.SymbolStyle.Shape = SymbolShapeEnum.None; StuSeries.SymbolStyle.Color = Color.DarkRed; StuSeries.X.CopyDataIn(ax); StuSeries.Y.CopyDataIn(ay1); StuSeries = null; } } else { c1Chart1.ChartArea.AxisX.AnnoFormat = FormatEnum.NumericGeneral; c1Chart1.ChartArea.AxisX.AnnotationRotation = 90; long[] siLuci; double[] si; LegendEnviroment.loadR(gaolu, toolStrip_Luci1.Text, toolStrip_Luci2.Text, out siLuci, out si); StuSeries.X.CopyDataIn(siLuci); StuSeries.Y.CopyDataIn(si); StuSeries = null; c1Chart1.Footer.Text = this.toolStrip_gaolu.Text + " " + this.toolStrip_Luci1.Text + " ---- " + this.toolStrip_Luci2.Text; long[] ax = new long[] { Convert.ToInt64(toolStrip_Luci1.Text), Convert.ToInt64(toolStrip_Luci2.Text) }; for (int i = 0; i < 4; i++) { double[] ay1 = new double[] { dy[i], dy[i] }; StuSeries = series.AddNewSeries(); StuSeries.Label = "最大值"; StuSeries.LineStyle.Pattern = LinePatternEnum.Solid; StuSeries.LineStyle.Color = Color.Black; StuSeries.SymbolStyle.Shape = SymbolShapeEnum.None; StuSeries.SymbolStyle.Color = Color.DarkRed; StuSeries.X.CopyDataIn(ax); StuSeries.Y.CopyDataIn(ay1); StuSeries = null; } } // Add and show the alarm zones AlarmZonesCollection zones = c1Chart1.ChartArea.PlotArea.AlarmZones; zones.Clear(); for (int i = 0; i < 5; i++) { AlarmZone zone = zones.AddNewZone(); zone.Name = dyName[i]; zone.BackColor = dyColor[i]; if (i == 0) { zone.UpperExtent = c1Chart1.ChartArea.AxisY.Max; } else { zone.UpperExtent = zones[i - 1].LowerExtent; } if (i == 4) { zone.LowerExtent = c1Chart1.ChartArea.AxisY.Min; } else { zone.LowerExtent = dy[i]; } zone.Visible = true; } }
private void toolStripButton1_Click(object sender, EventArgs e) { c1Chart1.ChartGroups[0].ChartData.SeriesList.Clear(); List <DateTime> dts = new List <DateTime>(); List <double> vs = new List <double>(); DateTime dt1 = DateTime.Now.AddDays(-1); DateTime dt2 = DateTime.Now; OracleConnection conn = new OracleConnection(Properties.Settings.Default.ConnectionString); conn.Open(); int gaolu = 0; switch (this.toolStrip_gaolu.Text) { case "1高炉": gaolu = 1; break; case "2高炉": gaolu = 2; break; case "3高炉": gaolu = 3; break; case "4高炉": gaolu = 4; break; case "5高炉": gaolu = 5; break; } string sql = "select zdsj,FESi from ddluci where zdsj>=:sjBegin and zdsj<=:sjEnd and gaolu=:gaolu"; OracleCommand siCmd = new OracleCommand(sql, conn); siCmd.Parameters.Add(":sjBegin", OracleType.DateTime).Value = this.sjBegin.Value; siCmd.Parameters.Add(":sjEnd", OracleType.DateTime).Value = this.sjEnd.Value; siCmd.Parameters.Add(":gaolu", OracleType.Int32).Value = gaolu; OracleDataReader dr = siCmd.ExecuteReader(); while (dr.Read()) { dts.Add(dr.GetDateTime(0)); vs.Add(dr.GetDouble(1)); } dr.Close(); conn.Close(); c1Chart1.Header.Text = this.toolStrip_gaolu.Text + " " + this.sjBegin.Text + "--" + this.sjEnd.Text + "Si(炉温)趋势"; // Add the data ChartData data = c1Chart1.ChartGroups[0].ChartData; ChartDataSeriesCollection series = data.SeriesList; //plot the student scores ChartDataSeries StuSeries = series.AddNewSeries(); StuSeries.Label = "Si(炉温)趋势"; StuSeries.LineStyle.Pattern = LinePatternEnum.Solid; StuSeries.LineStyle.Color = Color.DarkBlue; StuSeries.SymbolStyle.Shape = SymbolShapeEnum.Star; StuSeries.SymbolStyle.Color = Color.DarkRed; StuSeries.X.CopyDataIn(dts.ToArray()); StuSeries.Y.CopyDataIn(vs.ToArray()); StuSeries = null; DateTime[] ax = new DateTime[] { dts[0], dts[dts.Count - 1] }; double[] ay1 = new double[] { 0.7, 0.7 }; double[] ay2 = new double[] { 0.4, 0.4 }; StuSeries = series.AddNewSeries(); StuSeries.Label = "最大值"; StuSeries.LineStyle.Pattern = LinePatternEnum.Solid; StuSeries.LineStyle.Color = Color.Black; StuSeries.SymbolStyle.Shape = SymbolShapeEnum.None; StuSeries.SymbolStyle.Color = Color.DarkRed; StuSeries.X.CopyDataIn(ax); StuSeries.Y.CopyDataIn(ay1); StuSeries = null; StuSeries = series.AddNewSeries(); StuSeries.Label = "最小值"; StuSeries.LineStyle.Pattern = LinePatternEnum.Solid; StuSeries.LineStyle.Color = Color.Black; StuSeries.SymbolStyle.Shape = SymbolShapeEnum.None; StuSeries.SymbolStyle.Color = Color.DarkRed; StuSeries.X.CopyDataIn(ax); StuSeries.Y.CopyDataIn(ay2); StuSeries = null; // Add and show the alarm zones AlarmZonesCollection zones = c1Chart1.ChartArea.PlotArea.AlarmZones; zones.Clear(); AlarmZone zone1 = zones.AddNewZone(); AlarmZone zone2 = zones.AddNewZone(); AlarmZone zone3 = zones.AddNewZone(); zone1.Name = "大值区"; zone1.BackColor = Color.Aqua; zone1.UpperExtent = c1Chart1.ChartArea.AxisY.Max; zone1.LowerExtent = 0.7; zone1.Visible = true; zone2.Name = "正常"; zone2.BackColor = Color.Beige; zone2.UpperExtent = 0.7; zone2.LowerExtent = 0.4; zone2.Visible = true; zone3.Name = "小值区"; zone3.BackColor = Color.Aqua; zone3.UpperExtent = 0.4; zone3.LowerExtent = c1Chart1.ChartArea.AxisY.Min; zone3.Visible = true; }
//set up Alarm Zone shapes private void LoadShapes() { c1Chart1.ChartArea.AxisX.GridMajor.Visible = true; c1Chart1.ChartArea.AxisY.GridMajor.Visible = true; c1Chart1.ChartArea.AxisX.GridMinor.Visible = true; c1Chart1.ChartArea.AxisY.GridMinor.Visible = true; double[] values = (double[])c1Chart1.ChartGroups.Group0.ChartData.SeriesList[0].Y.CopyDataOut(); Array.Sort(values); //create the alarm zones. AlarmZonesCollection azs = c1Chart1.ChartArea.PlotArea.AlarmZones; azs.Clear(); //add the rectangle AlarmZone az = azs.AddNewZone(); az.Name = "Rectangle"; az.BackColor = ZoneColor[2]; az.Shape = AlarmZoneShapeEnum.Rectangle; az.PatternStyle = patterns[2]; az.PatternVisible = chkPatterns.Checked; az.UpperExtent = values[GetBoundingIndex(values, 0.65)]; az.LowerExtent = values[GetBoundingIndex(values, 0.45)]; az.FarExtent = 3; az.NearExtent = 2; az.Visible = true; //add the ellipse az = azs.AddNewZone(); az.BackColor = ZoneColor[0]; az.Shape = AlarmZoneShapeEnum.Ellipse; az.PatternStyle = patterns[0]; az.PatternVisible = chkPatterns.Checked; az.Name = "Ellipse"; az.UpperExtent = values[GetBoundingIndex(values, .95)]; az.LowerExtent = values[GetBoundingIndex(values, 0.75)]; az.FarExtent = 5; az.NearExtent = 4; az.Visible = true; //add a polygon defined by coordinates. Coordinates //are obtained using the GetPoints method defined above. PointF[] pfs = GetPoints(3, 201, 1, 5, 1, 7.5); az = azs.AddNewZone(); az.BackColor = ZoneColor[4]; az.Shape = AlarmZoneShapeEnum.Polygon; az.PatternStyle = patterns[4]; az.PatternVisible = chkPatterns.Checked; az.Name = "Polygon"; az.UpperExtent = values[GetBoundingIndex(values, 0.4)]; az.LowerExtent = values[GetBoundingIndex(values, 0.1)]; az.FarExtent = 2.75; az.NearExtent = 0.5; pfs = GetPoints(1, 15, az.NearExtent, az.FarExtent, az.LowerExtent, az.UpperExtent); az.PolygonData.PointData.CopyDataIn(pfs); az.Visible = true; }
private void toolStripButton1_Click(object sender, EventArgs e) { if (sjEnd.Value < sjBegin.Value) { MessageBox.Show("结束时间应该比开始时间大!"); return; } int gaolu = 0; switch (this.toolStrip_gaolu.Text) { case "1#大烧": gaolu = 7; break; case "2#大烧": gaolu = 8; break; } c1Chart1.ChartGroups[0].ChartData.SeriesList.Clear(); ChartData data = c1Chart1.ChartGroups[0].ChartData; ChartDataSeriesCollection series = data.SeriesList; double[] dy1; //double[] dy2; double max; double min; LegendEnviroment.loadCanShuSetting(gaolu, "烧结P", out dy1, out max, out min); c1Chart1.ChartArea.AxisY.Max = max; c1Chart1.ChartArea.AxisY.Min = min; Color[] dyColor = new Color[] { Color.FromArgb(255, 192, 192), Color.FromArgb(255, 255, 192), Color.FromArgb(192, 255, 192) }; string[] dyName = new string[] { "过大", "正常", "过小" }; //plot the student scores ChartDataSeries StuSeries = series.AddNewSeries(); StuSeries.Label = "烧结矿P趋势"; StuSeries.LineStyle.Pattern = LinePatternEnum.Solid; StuSeries.LineStyle.Color = Color.DarkBlue; StuSeries.SymbolStyle.Shape = SymbolShapeEnum.Star; StuSeries.SymbolStyle.Color = Color.DarkRed; c1Chart1.ChartArea.AxisX.AnnoFormat = FormatEnum.DateManual; c1Chart1.ChartArea.AxisX.AnnoFormatString = "MM/dd HH:mm"; c1Chart1.ChartArea.AxisX.AnnotationRotation = 0; DateTime[] sT; double[] s; LegendEnviroment.loadshaojie(gaolu, "P", sjBegin.Value, sjEnd.Value, out sT, out s); StuSeries.X.CopyDataIn(sT); StuSeries.Y.CopyDataIn(s); StuSeries = null; DateTime[] ax = new DateTime[] { sjBegin.Value, sjEnd.Value }; for (int i = 0; i < 2; i++) { double[] ay1 = new double[] { dy1[i], dy1[i] }; StuSeries = series.AddNewSeries(); StuSeries.Label = i.ToString(); StuSeries.LineStyle.Pattern = LinePatternEnum.Solid; StuSeries.LineStyle.Color = Color.Black; StuSeries.SymbolStyle.Shape = SymbolShapeEnum.None; StuSeries.SymbolStyle.Color = Color.DarkRed; StuSeries.X.CopyDataIn(ax); StuSeries.Y.CopyDataIn(ay1); StuSeries = null; } double[] zoney = new double[] { dy1[0], dy1[1] }; // Add and show the alarm zones AlarmZonesCollection zones = c1Chart1.ChartArea.PlotArea.AlarmZones; zones.Clear(); for (int i = 0; i < 3; i++) { AlarmZone zone = zones.AddNewZone(); zone.Name = dyName[i]; zone.BackColor = dyColor[i]; if (i == 0) { zone.UpperExtent = c1Chart1.ChartArea.AxisY.Max; } else { zone.UpperExtent = zones[i - 1].LowerExtent; } if (i == 2) { zone.LowerExtent = c1Chart1.ChartArea.AxisY.Min; } else { zone.LowerExtent = zoney[i]; } zone.Visible = true; } }
public void addAlarmZone(AlarmZone alarmZone) { dictAlarmZones.Add(alarmZone.Id, alarmZone); }
private void Form1_Load(object sender, System.EventArgs e) { // Size the form to fit any screen this.ClientSize = new Size(600, 400); // Center the form this.CenterToParent(); // Fill the form client area with the chart c1Chart1.Dock = DockStyle.Fill; // Get the data arrays and data. int[] StudentScores = this.GetStudentPointTotals(); int[] StudentNumbers = (int[])Array.CreateInstance(typeof(int), StudentScores.Length); int nStudents = StudentScores.Length; int i; for (i = 0; i < nStudents; i++) { StudentNumbers[i] = i; } // Get the statistics double mean = FindMean(StudentScores); double stddev = FindStdDev(StudentScores, mean); // Set up the header c1Chart1.Header.Text = "Student Scores and Grades"; c1Chart1.Header.Style.Font = new Font("Tahoma", 18, FontStyle.Bold); // Set the background color c1Chart1.Style.BackColor = Color.FromArgb(128, 192, 150); // Clear the existing data c1Chart1.ChartGroups[0].ChartData.SeriesList.Clear(); // Add the data ChartData data = c1Chart1.ChartGroups[0].ChartData; ChartDataSeriesCollection series = data.SeriesList; //plot the student scores ChartDataSeries StuSeries = series.AddNewSeries(); StuSeries.Label = "raw scores"; StuSeries.LineStyle.Pattern = LinePatternEnum.None; StuSeries.LineStyle.Color = c1Chart1.Style.BackColor; StuSeries.SymbolStyle.Shape = SymbolShapeEnum.Star; StuSeries.SymbolStyle.Color = Color.DarkRed; StuSeries.X.CopyDataIn(StudentNumbers); StuSeries.Y.CopyDataIn(StudentScores); StuSeries = null; // mean + 2 s LinePatternEnum [] LinePatterns = new LinePatternEnum[] { LinePatternEnum.Dash, LinePatternEnum.DashDot, LinePatternEnum.Solid, LinePatternEnum.DashDotDot, LinePatternEnum.Dot }; for (i = 2; i >= -2; i--) { ChartDataSeries StatSeries = series.AddNewSeries(); double [] xd = new double [] { 0, nStudents }; double [] yd = new double [] { mean + i * stddev, mean + i * stddev }; StatSeries.X.CopyDataIn(xd); StatSeries.Y.CopyDataIn(yd); StatSeries.SymbolStyle.Shape = SymbolShapeEnum.None; StatSeries.LineStyle.Pattern = LinePatterns[i + 2]; StatSeries.LineStyle.Color = Color.Black; StatSeries.LineStyle.Thickness = 1; if (i > 0) { StatSeries.Label = "m+" + i.ToString() + "s"; } else if (i < 0) { StatSeries.Label = "m" + i.ToString() + "s"; } else { StatSeries.Label = "mean"; StatSeries.LineStyle.Thickness = 2; StatSeries.LineStyle.Pattern = LinePatternEnum.Solid; } } // box the plot area c1Chart1.ChartArea.PlotArea.Boxed = true; // Show the legend c1Chart1.Legend.Visible = true; // Set the Axis titles c1Chart1.ChartArea.AxisX.Text = "Student Number"; c1Chart1.ChartArea.AxisY.Text = "Student Accumulated Points"; // sort the student scores so they can be analyzed Array.Sort(StudentScores); // Define each of the letter grades string [] GradeLetter = new String[] { "A", "B", "C", "D", "F" }; // Get the bounds of each letter grade // At most 95% of the students will not get an A // At most 75% of the students will not get a B or higher // At most 25% of the students will not get a C or higher // At most 5% of the students will not get a D or higher int [] GradeBounds = new int[] { StudentScores[GetBoundingIndex(StudentScores, 0.95)], StudentScores[GetBoundingIndex(StudentScores, 0.75)], StudentScores[GetBoundingIndex(StudentScores, 0.25)], StudentScores[GetBoundingIndex(StudentScores, 0.05)] }; // get the color codes for each grade Color [] GradeColor = new Color[] { Color.FromArgb(128, 128, 225), Color.FromArgb(128, 255, 128), Color.FromArgb(255, 228, 128), Color.FromArgb(55, 228, 228), Color.FromArgb(255, 192, 192) }; // Add the chart labels. They will be positioned later ChartLabels labels = c1Chart1.ChartLabels; labels.DefaultLabelStyle.BackColor = c1Chart1.Style.BackColor; labels.DefaultLabelStyle.Font = new Font("Courier New", 16, FontStyle.Bold); C1.Win.C1Chart.Label lab = null; for (i = 0; i < 5; i++) { lab = labels.LabelsCollection.AddNewLabel(); lab.Text = GradeLetter[i]; lab.Style.BackColor = GradeColor[i]; lab.AttachMethod = AttachMethodEnum.Coordinate; lab.Visible = true; } // Below are calculations and settings that depend upon auto // positioning of the chart. The auto positions are only // calculated during rendering of the chart. Force the // chart to be rendered so the chart element positions are // calculated. // Force calculation of chart element positions c1Chart1.GetImage(); // Add and show the alarm zones AlarmZonesCollection zones = c1Chart1.ChartArea.PlotArea.AlarmZones; for (i = 0; i < 5; i++) { AlarmZone zone = zones.AddNewZone(); zone.Name = GradeLetter[i]; zone.BackColor = GradeColor[i]; if (i == 0) { zone.UpperExtent = c1Chart1.ChartArea.AxisY.Max; } else { zone.UpperExtent = zones[i - 1].LowerExtent; } if (i == 4) { zone.LowerExtent = c1Chart1.ChartArea.AxisY.Min; } else { zone.LowerExtent = GradeBounds[i]; } zone.Visible = true; } PositionLegends(); }
private async Task LoadFromDatabase() { ZoneGuardConfigContextFactory factory = new ZoneGuardConfigContextFactory(); using (ZoneGuardConfigContext context = factory.CreateDbContext()) { /*************************************************************** * * Load Sensors * ***************************************************************/ List <ThingDAL> things = await context.Thing .Where <ThingDAL>(t => t.ThingType == ThingType.Sensor) .Include(p => p.Parameters) .ToListAsync <ThingDAL>(); foreach (ThingDAL thing in things) { Console.WriteLine(thing.Name); ConfigSensor configSensor = ZoneGuardConfigContextFactory.CreateThingFromDAL <ConfigSensor>(thing); Console.WriteLine(configSensor.toJSON()); //TODO:: More Dynamic addMQTTSensor(new SensorMQTT(configSensor, this), true); addProxySensor(new SensorProxy(configSensor, this), false); } /*************************************************************** * * Load AlarmZones * ***************************************************************/ List <AlarmZoneDAL> alarmZones = await context.AlarmZone .Include(az => az.Sensors) .ThenInclude(pa => pa.Thing) .ToListAsync <AlarmZoneDAL>(); foreach (AlarmZoneDAL zone in alarmZones) { ConfigAlarmZone configAlarmZone = ZoneGuardConfigContextFactory.CreateConfigAlarmZoneFromDAL(zone); AlarmZone alarmZone = new AlarmZone(configAlarmZone, this); alarmManager.addAlarmZone(alarmZone); /* * //if (zone.Enabled == 1) * { * Console.WriteLine("Creating Alarm Zone {0}", zone.Name); * foreach (AlarmZoneThingDAL sensor in zone.Sensors) * { * SensorCore sensorProxy = getSensorByName(sensor.Thing.Name); * SensorLink sensorLink = new SensorLink(sensorProxy, alarmZone, this); * * * //ConfigLink configLink = new ConfigLink(); * * //SensorProxy sensorProxy = new SensorProxy(configSensor, this); * //HEST * //alarmZone.addSensor(sensorProxy); * //if (sensor.Enabled == 1) * //{ * // Console.WriteLine(" Adding Sensor '{0}'", sensor.Thing.Name); * // } * * } * }*/ } } }