public double gistogram(double[] gran, DataGridView dataGridView1, ZedGraphControl zed, Func <double, double> f, int n) { GraphPane panel = zed.GraphPane; panel.CurveList.Clear(); PointPairList g_list = new PointPairList(); node itl = this.head; int i = 0; int num = 0; double d = 0.0; double x = itl.data; double a = x; double b = x; double ff, fff; while (itl != null) { x = itl.data; if ((x < gran[i]) && (itl.next != null)) { num++; itl = itl.next; } else { if (itl.next == null) { itl = itl.next; } b = gran[i]; fff = num / (n * (b - a)); ff = f((b + a) / 2.0); if (d < Math.Abs(fff - ff)) { d = Math.Abs(fff - ff); } g_list.Add(a, 0); g_list.Add(a, fff); g_list.Add(b, fff); g_list.Add(b, 0); dataGridView1.Rows.Add(); dataGridView1.Rows[i].Cells[0].Value = (b + a) / 2.0; dataGridView1.Rows[i].Cells[1].Value = ff; dataGridView1.Rows[i].Cells[2].Value = fff; a = b; num = 0; i++; } } LineItem Curve = panel.AddCurve("Гистограмма", g_list, Color.Red, SymbolType.None); zed.AxisChange(); zed.Invalidate(); return(d); }
private void button3_Click(object sender, EventArgs e) { EraseGraph(); CreateGraph(); panel3.Controls.Clear(); /*Label label13 = new Label(); * Label label14 = new Label(); * label13.Font = label14.Font = new System.Drawing.Font("宋体", 15.75F, System.Drawing.FontStyle.Bold); * label13.ForeColor = label14.ForeColor = Color.Red; * label13.Location = new System.Drawing.Point(100, 30); * label14.Location = new System.Drawing.Point(900, 30); * label13.AutoSize = label14.AutoSize = true; * panel3.Controls.Add(label13); * panel3.Controls.Add(label14);*/ ZedGraphControl zed3 = new ZedGraphControl(); zed3.Width = panel3.Width; zed3.Height = panel3.Height; //读取数据 int datalength = WaterLeak.get_DataLength(); double[] dataA = WaterLeak.get_DataA(); double[] dataB = WaterLeak.get_DataB(); double dataA_avg = WaterLeak.get_DataA_Avg(); double dataB_avg = WaterLeak.get_DataB_Avg(); if (比较ToolStripMenuItem.Checked == true) { byte[] A = data_A; byte[] B = data_B; int[] m = new int[2 * datalength]; int j; int k = 0; for (int i = 0; i < 2 * datalength; i++) { if (A[i] != B[i]) { j = i; m[k] = j; k++; } } int index = 0; for (int i = 0; i < 2 * datalength; i++) { if (m[i] == 0) { index = i; } } int[] n = new int[index]; for (int i = 0; i < index; i++) { n[i] = m[i]; } MessageBox.Show("" + index); } //处理数据,采用均方差算法 if (算术平均ToolStripMenuItem.Checked == true) { progressBar1.Value = 0; int j = 0; double MINC = 0; int bias = 5000; int w = 5000; double[] C = new double[2 * bias]; for (int i = -bias; i < bias; i++) { C[i + bias] = 0; for (int k = w; k < datalength - w; k++) { C[i + bias] += Math.Abs(dataA[k + i] - dataB[k]); //曼哈顿距离 } if (i == -bias) { MINC = C[0]; } else if (C[bias + i] < MINC) { j = i; MINC = C[bias + i]; } Application.DoEvents(); progressBar1.Value = (i + bias) * 50 / bias; } progressBar1.Value += 1; //进度条 double w_avg; w_avg = 0; for (int i = 0; i < 2 * bias; i++) { w_avg += C[i] / (2 * bias); } for (int i = 0; i < 2 * bias; i++) { C[i] = (C[i] - w_avg) / w_avg; } panel3.Controls.Add(zed3); GraphPane Pane = zed3.GraphPane; /*Pane.Title = "偏差结果"; * Pane.XAxis.Title = ""; * Pane.YAxis.Title = "";*/ PointPairList list1 = new PointPairList(); for (int i = 0; i < 2 * bias; i++) { list1.Add(i, C[i]); } LineItem myCurve1 = Pane.AddCurve("Porsche", list1, Color.Blue, SymbolType.None); zed3.AxisChange(); //计算漏水点位置 double positon = (WaterLeak.get_PipelineLength() + WaterLeak.get_WaveNumber() * j / (1000 * WaterLeak.get_CaptureRate())) / 2; /*label14.Text = "漏水点距离A探头" + positon.ToString() + "米!"; * * //显示标注数据 * if (j > 0) * label13.Text = "A探头滞后B探头" + j.ToString("G") + "个基点!"; * if (j < 0) * label13.Text = "A探头超前B探头" + (-j).ToString() + "个基点!"; * if (j == 0) * label13.Text = "A探头与B探头无偏移!";*/ //显示基点 textBoxOffSet.Text = j.ToString(); //保存参数 WaterLeak.set_dataC_factor(500); WaterLeak.set_dataC_shift(100); WaterLeak.set_Bias(bias); WaterLeak.set_Min_Position(j); WaterLeak.set_Min_Value(MINC); WaterLeak.set_DataC(C); } //if (LMSToolStripMenuItem.Checked == true) //{ // progressBar1.Value = 0; // MatlabClass mat = new MatlabClass(); // MWNumericArray dataA_m = new MWNumericArray(1, datalength, dataA); // MWNumericArray dataB_m = new MWNumericArray(1, datalength, dataB); // MWArray M_m = 100; // MWArray mu_m = 0.00001; // MWArray W_m = mat.my_LMS(dataA_m, dataB_m, M_m, mu_m); // Array W = ((MWNumericArray)W_m).ToArray(); // int M = ((MWNumericArray)M_m).ToScalarInteger(); // int W_length = W.Length; // int d = 0; // double temp = Convert.ToDouble(W.GetValue(0, 0)); // for (int i = 1; i < W_length; i++) // { // if (temp < Convert.ToDouble(W.GetValue(i, 0))) // { // temp = Convert.ToDouble(W.GetValue(i, 0)); // d = i - 2 * M; // } // } // panel3.Controls.Add(zed3); // GraphPane Pane = zed3.GraphPane; // Pane.Title = "偏差结果"; // Pane.XAxis.Title = ""; // Pane.YAxis.Title = ""; // PointPairList list = new PointPairList(); // for (int i = 0; i < W_length; i++) // { // list.Add(i - 2 * M, Convert.ToDouble(W.GetValue(i, 0))); // } // LineItem myCurve = Pane.AddCurve("Porsche", list, Color.Blue, SymbolType.None); // zed3.AxisChange(); // //计算漏水点位置 // double positon = (WaterLeak.get_PipelineLength() + WaterLeak.get_WaveNumber() * d / (1000 * WaterLeak.get_CaptureRate())) / 2; // label14.Text = "漏水点距离A探头" + positon.ToString() + "米!"; // //显示标注数据 // if (d > 0) // label13.Text = "A探头滞后B探头" + d.ToString("G") + "个基点!"; // if (d < 0) // label13.Text = "A探头超前B探头" + (-d).ToString() + "个基点!"; // if (d == 0) // label13.Text = "A探头与B探头无偏移!"; //} if (广义互相关ToolStripMenuItem.Checked == true) { DateTime startDT = System.DateTime.Now; progressBar1.Value = 0; int len = 262144; double[] A = new double[len]; double[] B = new double[len]; for (int i = 0; i < len; i++) { A[i] = dataA[i]; B[i] = dataB[i]; } CrossCorrelation ccorr = new CrossCorrelation(); double[] R = ccorr.Rxy(A, B); int R_length = R.Length; Position p = new Position(); int location = p.max(R); int d = location - R_length / 2; panel3.Controls.Add(zed3); GraphPane Pane = zed3.GraphPane; /*Pane.Title = "互相关系数"; * Pane.XAxis.Title = ""; * Pane.YAxis.Title = "";*/ PointPairList list = new PointPairList(); for (int i = 0; i < R_length; i++) { list.Add(i, R[i]); } LineItem myCurve = Pane.AddCurve("Porsche", list, Color.Blue, SymbolType.None); zed3.AxisChange(); //计算漏水点位置 double positon = (WaterLeak.get_PipelineLength() + WaterLeak.get_WaveNumber() * d / (1000 * WaterLeak.get_CaptureRate())) / 2; /*label14.Text = "漏水点距离A探头" + positon.ToString() + "米!"; * //显示标注数据 * if (d > 0) * label13.Text = "A探头滞后B探头" + d.ToString("G") + "个基点!"; * if (d < 0) * label13.Text = "A探头超前B探头" + (-d).ToString() + "个基点!"; * if (d == 0) * label13.Text = "A探头与B探头无偏移!";*/ //显示基点 textBoxOffSet.Text = d.ToString(); DateTime endDT = System.DateTime.Now; TimeSpan time = endDT.Subtract(startDT); //MessageBox.Show(time.TotalMilliseconds.ToString() + "ms"); } //if (互功率谱ToolStripMenuItem.Checked == true) //{ // progressBar1.Value = 0; // MatlabClass mat = new MatlabClass(); // MWNumericArray dataA_m = new MWNumericArray(1, datalength, dataA); // MWNumericArray dataB_m = new MWNumericArray(1, datalength, dataB); // MWArray datalength_m = datalength; // MWArray R_m = mat.my_xcorrPow(dataA_m, dataB_m); // Array R = ((MWNumericArray)R_m).ToArray(); // int R_length = R.Length; // int d = 0; // double temp = Convert.ToDouble(R.GetValue(0, 0)); // for (int i = 1; i < R_length; i++) // { // if (temp < Convert.ToDouble(R.GetValue(0, i))) // { // temp = Convert.ToDouble(R.GetValue(0, i)); // d = i - datalength + 1; // } // } // panel3.Controls.Add(zed3); // GraphPane Pane = zed3.GraphPane; // Pane.Title = "偏差结果"; // Pane.XAxis.Title = ""; // Pane.YAxis.Title = ""; // PointPairList list = new PointPairList(); // for (int i = 0; i < R_length; i++) // { // list.Add(i - datalength + 1, Convert.ToDouble(R.GetValue(0, i))); // } // LineItem myCurve = Pane.AddCurve("Porsche", list, Color.Blue, SymbolType.None); // zed3.AxisChange(); // //计算漏水点位置 // double positon = (WaterLeak.get_PipelineLength() + WaterLeak.get_WaveNumber() * d / (1000 * WaterLeak.get_CaptureRate())) / 2; // label14.Text = "漏水点距离A探头" + positon.ToString() + "米!"; // //显示标注数据 // if (d > 0) // label13.Text = "A探头滞后B探头" + d.ToString("G") + "个基点!"; // if (d < 0) // label13.Text = "A探头超前B探头" + (-d).ToString() + "个基点!"; // if (d == 0) // label13.Text = "A探头与B探头无偏移!"; //} //int bias = 5000; //int w = 2500; //double[] C = new double[bias]; //double minc = 0; //int d = 0; //int n = 5;//计算次数 //int sp = datalength / n;//每次计算的间隔 //int[] T = new int[n];//时延点数 //double[] S = new double[n];//离A点距离 //DataTable dt = new DataTable(); //dt.Columns.Add("A探头超前点数", typeof(int)); //dt.Columns.Add("漏水点离A探头距离", typeof(double)); //for (int m = 0; m < n; m++) //{ // for (int i = 0 + m * sp; i < bias + m * sp; i++) // { // C[i - m * sp] = 0; // for (int j = w + m * sp; j < w + bias + m * sp; j++) // { // C[i - m * sp] += Math.Abs(dataA[i + j - w - m * sp] - dataB[j]); // } // if (i == 0) minc = C[0]; // else if (C[i - m * sp] < minc) // { // d = i - m * sp; // minc = C[i - m * sp]; // } // } // T[m] = w - d; // S[m] = 500 - (double)T[m] / 10; // DataRow dr = dt.NewRow(); // dr[0] = T[m].ToString(); // dr[1] = S[m].ToString(); // dt.Rows.Add(dr); // Application.DoEvents(); // progressBar1.Value = (m - 1) * 100 / n; //} //dataGridView1.DataSource = dt; //dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; /* * * //处理数据,采用LMS算法 * //初始化 * int M=1000; * float mu = (float)0.1; * float[] en = new float[datalength]; * for (int i = 0; i < datalength; i++) * en[i] = 0; * double[] w = new double[M]; * for (int i = 0; i < M; i++) * w[i] = 0; * float y; * //迭代运算 * for (int k = M - 1; k < datalength; k++) * { * y=0; * for (int i = 0; i < M; i++) * y += (float)(w[i]) * dataB[k - i]; * if (double.IsNaN(y)) y = 0; * en[k] =dataA[k] - y; * * for (int i = 0; i < M; i++) * { * w[i] = w[i] + 2 * mu * en[k] * dataB[k - i]; * if (double.IsNaN(w[i])) w[i] = 0; * // w[i] = Math.Round(w[i], 6); * } * * progressBar1.Value = (k-M) * 100 / (datalength - M-1); * * Application.DoEvents(); * * } * * * float w_avg; * w_avg = 0; * for (int i = 0; i < M; i++) * w_avg += (float)w[i]; * * w_avg /= M; * // w_avg = Math.Round(w_avg, 6); * * // w[0] = Math.Round(w[0], 10); * textBox1.Text = w[0].ToString("G"); */ }
public void CreatePpdGraph(ZedGraphControl zg, IList <string> projectInfoLines, IEnumerable <ProteinBenchmark> benchmarks, IList <Color> graphColors, int decimalPlaces, Protein protein, bool calculateBonus) { Debug.Assert(zg != null); try { // get a reference to the GraphPane GraphPane myPane = zg.GraphPane; // Clear the bars myPane.CurveList.Clear(); // Clear the bar labels myPane.GraphObjList.Clear(); // Clear the XAxis Project Information myPane.XAxis.Title.Text = String.Empty; // If no Project Information, get out if (projectInfoLines.Count == 0) { return; } // Scale YAxis In Thousands? bool inThousands = false; // Create the bars for each benchmark int i = 0; foreach (ProteinBenchmark benchmark in benchmarks) { double minimumFrameTimePPD = 0; double averageFrameTimePPD = 0; if (protein != null) { minimumFrameTimePPD = GetPPD(benchmark.MinimumFrameTime, protein, calculateBonus); averageFrameTimePPD = GetPPD(benchmark.AverageFrameTime, protein, calculateBonus); } if (minimumFrameTimePPD >= 1000 || averageFrameTimePPD >= 1000) { inThousands = true; } var yPoints = new double[2]; yPoints[0] = Math.Round(minimumFrameTimePPD, decimalPlaces); yPoints[1] = Math.Round(averageFrameTimePPD, decimalPlaces); CreateBar(i, myPane, benchmark.OwningSlotName, yPoints, graphColors); i++; } // Create the bar labels BarItem.CreateBarLabels(myPane, true, String.Empty, zg.Font.Name, zg.Font.Size, Color.Black, true, false, false); // Set the Titles myPane.Title.Text = "HFM.NET - Client Benchmarks"; var sb = new StringBuilder(); for (i = 0; i < projectInfoLines.Count - 2; i++) { sb.Append(projectInfoLines[i]); sb.Append(" "); } sb.Append(projectInfoLines[i]); myPane.XAxis.Title.Text = sb.ToString(); myPane.YAxis.Title.Text = "PPD"; // Draw the X tics between the labels instead of at the labels myPane.XAxis.MajorTic.IsBetweenLabels = true; // Set the XAxis labels var labels = new[] { "Min. Frame Time", "Avg. Frame Time" }; myPane.XAxis.Scale.TextLabels = labels; // Set the XAxis to Text type myPane.XAxis.Type = AxisType.Text; // Don't show YAxis.Scale as 10^3 myPane.YAxis.Scale.MagAuto = false; // Set the YAxis Steps if (inThousands) { myPane.YAxis.Scale.MajorStep = 1000; myPane.YAxis.Scale.MinorStep = 500; } else { myPane.YAxis.Scale.MajorStep = 100; myPane.YAxis.Scale.MinorStep = 10; } // Fill the Axis and Pane backgrounds myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 90F); myPane.Fill = new Fill(Color.FromArgb(250, 250, 255)); } finally { // Tell ZedGraph to refigure the // axes since the data have changed zg.AxisChange(); // Refresh the control zg.Refresh(); } }
/** * Initialise ZedGraph */ private void CreateGraph(ZedGraphControl zgc) { GraphPane myPane = zgc.GraphPane; myPane.Title.Text = "Weather Reports"; myPane.XAxis.Title.Text = "Time"; myPane.YAxis.Title.Text = "Relative Humidity, %"; myPane.Y2Axis.Title.Text = "Temperature"; PointPairList hList = new PointPairList(); PointPairList tList = new PointPairList(); PointPairList pList = new PointPairList(); // Generate a red curve with diamond symbols, and "Humidity" in the legend LineItem myCurve = myPane.AddCurve("Humidity", hList, s.humidColor, SymbolType.Diamond); // Fill the symbols with white myCurve.Symbol.Fill = new Fill(Color.White); myCurve.Symbol.Size = 2; // Generate a blue curve with circle symbols, and "Temperature" in the legend myCurve = myPane.AddCurve("Temperature", tList, s.tempColor, SymbolType.Circle); // Fill the symbols with white myCurve.Symbol.Fill = new Fill(Color.White); // Associate this curve with the Y2 axis myCurve.IsY2Axis = true; myCurve.Symbol.Size = 2; // Generate a green curve with square symbols, and "Pressure" in the legend myCurve = myPane.AddCurve("Pressure", pList, s.preColor, SymbolType.Diamond); // Fill the symbols with white myCurve.Symbol.Fill = new Fill(Color.White); // Associate this curve with the second Y axis myCurve.YAxisIndex = 1; myCurve.Symbol.Size = 2; // Show the x axis grid myPane.XAxis.MajorGrid.IsVisible = true; // Make the Y axis scale red myPane.YAxis.Scale.FontSpec.FontColor = s.humidColor; myPane.YAxis.Title.FontSpec.FontColor = s.humidColor; // turn off the opposite tics so the Y tics don't show up on the Y2 axis myPane.YAxis.MajorTic.IsOpposite = false; myPane.YAxis.MinorTic.IsOpposite = false; // Don't display the Y zero line myPane.YAxis.MajorGrid.IsZeroLine = false; // Align the Y axis labels so they are flush to the axis myPane.YAxis.Scale.Align = AlignP.Inside; // Enable the Y2 axis display myPane.Y2Axis.IsVisible = true; // Make the Y2 axis scale blue myPane.Y2Axis.Scale.FontSpec.FontColor = s.tempColor; myPane.Y2Axis.Title.FontSpec.FontColor = s.tempColor; // turn off the opposite tics so the Y2 tics don't show up on the Y axis myPane.Y2Axis.MajorTic.IsOpposite = false; myPane.Y2Axis.MinorTic.IsOpposite = false; // Display the Y2 axis grid lines myPane.Y2Axis.MajorGrid.IsVisible = true; // Align the Y2 axis labels so they are flush to the axis myPane.Y2Axis.Scale.Align = AlignP.Inside; // Create a second Y Axis, green YAxis yAxis3 = new YAxis("WindSpeed , RPM"); myPane.YAxisList.Add(yAxis3); yAxis3.Scale.FontSpec.FontColor = s.preColor; yAxis3.Title.FontSpec.FontColor = s.preColor; //yAxis3.Color = s.pressure; // turn off the opposite tics so the Y2 tics don't show up on the Y axis yAxis3.MajorTic.IsInside = false; yAxis3.MinorTic.IsInside = false; yAxis3.MajorTic.IsOpposite = false; yAxis3.MinorTic.IsOpposite = false; // Align the Y2 axis labels so they are flush to the axis yAxis3.Scale.Align = AlignP.Inside; // Fill the axis background with a gradient myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f); myPane.XAxis.Type = AxisType.Date; myPane.XAxis.Scale.Format = "HH:mm"; yAxis3.Scale.MajorStep = 1; yAxis3.Scale.MinorStep = 0.1; myPane.Y2Axis.Scale.MajorStep = 0.5; myPane.Y2Axis.Scale.MinorStep = 0.1; //myPane.YAxis.Scale.MajorStep = 1; //myPane.YAxis.Scale.MinorStep = 0.1; //myPane.XAxis.Scale.MajorStep = 10; //myPane.XAxis.Scale.MinGrace = 0.05; zgc.AxisChange(); }
public void CreateScatterplot(ZedGraphControl zgc, double[][] graph) { GraphPane myPane = zgc.GraphPane; myPane.CurveList.Clear(); // Set the titles myPane.Title.Text = "Scatter Plot"; myPane.XAxis.Title.Text = "X"; myPane.YAxis.Title.Text = "Y"; PointPairList list1 = new PointPairList(); PointPairList list2 = new PointPairList(); PointPairList list3 = new PointPairList(); for (int i = 0; i < graph.GetLength(0); i++) { double x = graph[i][0], y = graph[i][1], z = graph[i][2]; if (z == 1.0) { list1.Add(x, y); } if (z == 2.0) { list2.Add(x, y); } if (z == 3.0) { list3.Add(x, y); } } // Add the curve LineItem myCurve = myPane.AddCurve("G1", list1, Color.Blue, SymbolType.Diamond); myCurve.Line.IsVisible = false; myCurve.Symbol.Border.IsVisible = false; myCurve.Symbol.Fill = new Fill(Color.Blue); myCurve = myPane.AddCurve("G2", list2, Color.Green, SymbolType.Diamond); myCurve.Line.IsVisible = false; myCurve.Symbol.Border.IsVisible = false; myCurve.Symbol.Fill = new Fill(Color.Green); myCurve = myPane.AddCurve("G3", list3, Color.Orange, SymbolType.Diamond); myCurve.Line.IsVisible = false; myCurve.Symbol.Border.IsVisible = false; myCurve.Symbol.Fill = new Fill(Color.Orange); myCurve = myPane.AddCurve("M", new PointPairList(), Color.Black, SymbolType.Diamond); myCurve.Line.IsVisible = false; myCurve.Symbol.Border.IsVisible = false; myCurve.Symbol.Fill = new Fill(Color.Black); // Fill the background of the chart rect and pane //myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f); //myPane.Fill = new Fill(Color.White, Color.SlateGray, 45.0f); myPane.Fill = new Fill(Color.WhiteSmoke); zgc.AxisChange(); zgc.Invalidate(); }
public void DrawGraph(ZedGraphControl graph) { graph.Invalidate(); graph.Refresh(); graph.AxisChange(); }
public void createPane(ZedGraphControl zgc) { myPane = zgc.GraphPane; //设置图标标题和x、y轴标题 if (server.form1.comboBox1.Text == "BPM") { myPane.YAxis.Title.Text = "脉搏/BPM"; myPane.Title.Text = "BPM变化曲线"; } else if (server.form1.comboBox1.Text == "体温") { myPane.YAxis.Title.Text = "体温/℃"; myPane.Title.Text = "体温变化曲线"; } else { return; } myPane.XAxis.Title.Text = "时间/t"; //更改标题的字体 FontSpec myFont = new FontSpec("Arial", 20, Color.Red, false, false, false); myPane.Title.FontSpec = myFont; myPane.XAxis.Title.FontSpec = myFont; myPane.YAxis.Title.FontSpec = myFont; // 造一些数据,PointPairList里有数据对x,y的数组 // Y轴数据 DataTable table = frm.frmBrowseGraph(); for (int i = 0; i < table.Rows.Count; i++) { int x = i; DataRow row = table.Rows[i]; //传递给每个Row Double value = Convert.ToDouble(row[server.form1.comboBox1.Text]);; //取值 list.Add(x, value); //添加一组数据 } // 用list生产一条曲线,标注是 filedPosition/filedUserAccount myLine = myPane.AddCurve(server.form1.cbPatient.Text, list, Color.Red, SymbolType.Star); //填充图表颜色 myPane.Fill = new Fill(Color.White, Color.FromArgb(200, 200, 255), 45.0f); //以上生成的图标X轴为数字,下面将转换为日期的文本 string[] labels = new string[table.Rows.Count]; for (int i = 0; i < table.Rows.Count; i++) { DataRow row = table.Rows[i]; //传递给每个Row labels[i] = Convert.ToString(row["时间"]); } oldRowsCount = table.Rows.Count; myPane.XAxis.Scale.TextLabels = labels; //X轴文本取值 myPane.XAxis.Type = AxisType.Text; //X轴类型 //画到zedGraphControl1控件中,此句必加 zgc.AxisChange(); zgc.Refresh(); timer1.Enabled = true; }
public void CreateChart(ZedGraphControl zgc, List <OverViewDataDto> list) { zgc.GraphPane.CurveList.Clear(); zgc.GraphPane.GraphObjList.Clear(); GraphPane myPane = zgc.GraphPane; // Set the titles and axis labels myPane.Title.Text = "掘金难度"; myPane.XAxis.Title.IsVisible = false; myPane.YAxis.Title.IsVisible = false; FontSpec myFont = new FontSpec("宋体", 20, Color.Gray, false, false, false); myPane.Title.FontSpec = myFont; myPane.XAxis.Title.FontSpec = myFont; myPane.YAxis.Title.FontSpec = myFont; myPane.Legend.FontSpec = myFont; list = list.OrderBy(o => o.Date).ToList(); string[] labels = new string[list.Count]; PointPairList list1 = new PointPairList(); for (int i = 0; i < list.Count; i++) { var dto = list[i]; try { var showx = dto.Date.Substring(0, 4) + "-" + dto.Date.Substring(4, 2) + "-" + dto.Date.Substring(6, 2); labels[i] = showx; } catch { labels[i] = dto.Date; } double x = i; double y1 = dto.AllMakeMoneyScore / dto.AllMakeMoney; list1.Add(x, y1); } // Generate a red curve with diamond symbols, and "Velocity" in the legend LineItem myCurve = myPane.AddCurve("难度", list1, Color.Red, SymbolType.Diamond); // Fill the symbols with white myCurve.Symbol.Fill = new Fill(Color.White); // Show the x axis grid myPane.XAxis.MajorGrid.IsVisible = true; myPane.XAxis.Scale.TextLabels = labels; //X轴文本取值 myPane.XAxis.Type = AxisType.Text; //X轴类型 // Make the Y axis scale red myPane.YAxis.Scale.FontSpec.FontColor = Color.Red; myPane.YAxis.Title.FontSpec.FontColor = Color.Red; // turn off the opposite tics so the Y tics don't show up on the Y2 axis // Align the Y axis labels so they are flush to the axis myPane.YAxis.Scale.Align = AlignP.Inside; // Fill the axis background with a gradient myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f); zgc.AxisChange(); }
public void CreateChart(ZedGraphControl zgc) { zgc.GraphPane.CurveList.Clear(); zgc.GraphPane.GraphObjList.Clear(); GraphPane myPane = zgc.GraphPane; // Set the titles and axis labels myPane.Title.Text = "代系数增长图"; myPane.XAxis.Title.Text = "代数"; myPane.YAxis.Title.Text = "代系数"; FontSpec myFont = new FontSpec("宋体", 20, Color.Gray, false, false, false); myPane.Title.FontSpec = myFont; myPane.XAxis.Title.FontSpec = myFont; myPane.YAxis.Title.FontSpec = myFont; myPane.Legend.FontSpec = myFont; var MaxGeneration = (int)numericUpDown_max_generation.Value; string[] labels = new string[MaxGeneration]; PointPairList list1 = new PointPairList(); for (int i = 0; i < MaxGeneration; i++) { labels[i] = i.ToString(); double x = i; double y1 = ComputeGenerationCoefficient(i); list1.Add(x, y1); } // Generate a red curve with diamond symbols, and "Velocity" in the legend LineItem myCurve = myPane.AddCurve("代系数", list1, Color.Red, SymbolType.Diamond); // Fill the symbols with white myCurve.Symbol.Fill = new Fill(Color.White); // Show the x axis grid myPane.XAxis.MajorGrid.IsVisible = true; myPane.XAxis.Scale.TextLabels = labels; //X轴文本取值 myPane.XAxis.Type = AxisType.Text; //X轴类型 // Make the Y axis scale red myPane.YAxis.Scale.FontSpec.FontColor = Color.Red; myPane.YAxis.Title.FontSpec.FontColor = Color.Red; // turn off the opposite tics so the Y tics don't show up on the Y2 axis // Align the Y axis labels so they are flush to the axis myPane.YAxis.Scale.Align = AlignP.Inside; // Fill the axis background with a gradient myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f); zgc.AxisChange(); zgc.Refresh(); zgc.AxisChange(); }
/// <summary> /// Обновить график /// </summary> public void resetGraph() { zedgraph.AxisChange(); zedgraph.Invalidate(); }
public void CreatePane(ZedGraphControl zgc, List <OverViewDataDto> list) { zgc.GraphPane.CurveList.Clear(); zgc.GraphPane.GraphObjList.Clear(); GraphPane myPane = zgc.GraphPane; //设置图标标题和x、y轴标题 myPane.Title.Text = "掘金池总额变化"; myPane.XAxis.Title.IsVisible = false; myPane.YAxis.Title.IsVisible = false; //更改标题的字体 FontSpec myFont = new FontSpec("宋体", 20, Color.Gray, false, false, false); myPane.Title.FontSpec = myFont; myPane.XAxis.Title.FontSpec = myFont; myPane.YAxis.Title.FontSpec = myFont; myPane.Legend.FontSpec = myFont; list = list.OrderBy(o => o.Date).ToList(); string[] labels = new string[list.Count]; PointPairList list1 = new PointPairList(); PointPairList list2 = new PointPairList(); for (int i = 0; i < list.Count; i++) { var dto = list[i]; try { var showx = dto.Date.Substring(0, 4) + "-" + dto.Date.Substring(4, 2) + "-" + dto.Date.Substring(6, 2); labels[i] = showx; } catch { labels[i] = dto.Date; } double x = i; double y1 = dto.AllMakeMoney; double y2 = dto.AllMakeMoneyScore; list1.Add(x, y1); list2.Add(x, y2); } // 用list1生产一条曲线 LineItem myCurve = myPane.AddCurve("掘金池总额", list1, Color.Red, SymbolType.Circle); LineItem myCurve2 = myPane.AddCurve("掘金分", list2, Color.Blue, SymbolType.Circle); //填充图表颜色 myPane.Fill = new Fill(Color.White, Color.FromArgb(200, 200, 255), 45.0f); myPane.XAxis.Scale.TextLabels = labels; //X轴文本取值 myPane.XAxis.Type = AxisType.Text; //X轴类型 //画到zedGraphControl1控件中,此句必加 zgc.AxisChange(); //重绘控件 Refresh(); }
protected void CreateChart() { zgc.Visible = true; GraphPane myPane = zgc.GraphPane; myPane.CurveList.Clear(); // Set the titles and axis labels myPane.Title.Text = this.Text; myPane.XAxis.Title.IsVisible = false; //.Text = "Time, Days\n(Since Plant Construction Startup)"; myPane.YAxis.Title.IsVisible = false; // Text = "Widget Production\n(units/hour)"; myPane.Legend.IsVisible = false; myPane.XAxis.Type = AxisType.Date; var y = GetYValues(); //Program.CurrentWoman.BBT.GetTemperaturesSince(initialMonth, valuesCount); //DateTime.DaysInMonth(initialMonth.Year, initialMonth.Month)); //{ 36.6, 36.4, 36.2, 36.9, 36.8, 36.4, 36.8, 36.6, 36.8, 36.5 }; var x = GetXValues(); var labels = new List <GraphObj>(); PointPairList list = new PointPairList(); Symbol emptyCircle = new Symbol(SymbolType.Circle, Color.Blue); emptyCircle.Size = 10; emptyCircle.Fill = new Fill(Color.White); Symbol filledCircle = new Symbol(SymbolType.Circle, Color.Blue); filledCircle.Size = 10; filledCircle.Fill = new Fill(Color.Blue); myPane.GraphObjList.Clear(); if (x == null) { myPane.XAxis.Scale.FormatAdditional = new Dictionary <double, string>(); for (int i = 0; i < y.Length; i++) { if (y[i] == 0) { continue; } DateTime d = dateFrom.Value.AddDays(i); PointPair point = new PointPair((double)new XDate(d.Year, d.Month, d.Day), y[i]); point.Symbol = filledCircle; point.DashStyle = (i + 1 < y.Length && y[i + 1] == 0) ? DashStyle.Dash : DashStyle.Solid; list.Add(point); if (y[i] > MaxYValue) { MaxYValue = y[i]; } if (y[i] < MinYValue) { MinYValue = y[i]; } myPane.XAxis.Scale.FormatAdditional[point.X] = " - " + (i + 1).ToString(); } var curve = myPane.AddCurve("Main", list, Color.Blue, SymbolType.Circle); curve.Line.Width = 2.0F; } else { if (x.Length != y.Length) { throw new Exception("Number of X values must match number of Y values."); } filledCircle.Size = 5; for (int i = 0; i < y.Length; i++) { if (y[i] == 0) { continue; } PointPair point = new PointPair(x[i], y[i]); list.Add(point); var txt = new TextObj((i + 1).ToString(), point.X, point.Y - 1, CoordType.AxisXYScale, AlignH.Center, AlignV.Top); txt.ZOrder = ZOrder.A_InFront; txt.FontSpec.Border.IsVisible = false; txt.FontSpec.Fill.IsVisible = false; labels.Add(txt); var txt1 = new TextObj(y[i].ToString(), point.X, point.Y + 1, CoordType.AxisXYScale, AlignH.Center, AlignV.Bottom); txt1.ZOrder = ZOrder.A_InFront; txt1.FontSpec.Border.IsVisible = false; if (y[i] < 21 || y[i] > 35) { txt1.FontSpec.Fill.IsVisible = true; txt1.FontSpec.IsBold = true; txt1.FontSpec.Fill.Color = Color.LightCoral; txt1.FontSpec.Fill.Brush = Brushes.LightCoral; } else { txt1.FontSpec.Fill.IsVisible = false; } labels.Add(txt1); var s = ((XDate)x[i]).ToString("d"); var txt2 = new TextObj(s, point.X, 0, CoordType.AxisXYScale, AlignH.Left, AlignV.Center); txt2.ZOrder = ZOrder.A_InFront; txt2.FontSpec.Border.IsVisible = false; txt2.FontSpec.Fill.IsVisible = false; txt2.FontSpec.Angle = 90; labels.Add(txt2); if (y[i] > MaxYValue) { MaxYValue = y[i]; } if (y[i] < MinYValue) { MinYValue = y[i]; } } myPane.BarSettings.ClusterScaleWidthAuto = true; myPane.BarSettings.MinClusterGap = 0.0f; var bar = myPane.AddBar("Main", list, Color.Blue); bar.Bar.Fill = new Fill(Color.LightSkyBlue, Color.White, Color.LightSkyBlue); } myPane.GraphObjList.AddRange(labels); SetupGraph(); // Calculate the Axis Scale Ranges zgc.AxisChange(); }
private void CreateGraph(ZedGraphControl zgc) { this.Cursor = Cursors.WaitCursor; FunctionValues = new PointPairList(); try { myPane = zgc.GraphPane; // Set the Titles if (grSettings.GraphType.Equals(GraphTypes.ParametricFamily) || grSettings.GraphType.Equals(GraphTypes.ParametricFunction)) { myPane.Title.Text = grSettings.GraphType + ": (" + grSettings.FunctionA + ", " + grSettings.FunctionB + ")"; } else { myPane.Title.Text = grSettings.GraphType + ": " + grSettings.FunctionA; } myPane.Chart.Fill.Type = FillType.Solid; myPane.Chart.Fill.Color = grSettings.Background; OppositeGraphColor = Color.FromArgb(255 - grSettings.Background.R, 255 - grSettings.Background.G, 255 - grSettings.Background.B); if (grSettings.GraphType.Equals(GraphTypes.Function)) { CreateGraphOfFunction(zgc); } else if (grSettings.GraphType.Equals(GraphTypes.Derivative)) { CreateGraphOfDerivative(zgc); } else if (grSettings.GraphType.Equals(GraphTypes.VectorField)) { CreateGraphOfVectorField(zgc); } else if (grSettings.GraphType.Equals(GraphTypes.LevelCurves)) { CreateGraphOfLevelCurves(zgc); } else if (grSettings.GraphType.Equals(GraphTypes.LevelCurves2)) { CreateGraphOfLevelCurves(zgc); } else if (grSettings.GraphType.Equals(GraphTypes.ParametricFunction)) { CreateGraphOfParametricFunction(zgc); } else if (grSettings.GraphType.Equals(GraphTypes.ParametricFamily)) { CreateGraphOfParametricFamily(zgc); } else if (grSettings.GraphType.Equals(GraphTypes.Slope)) { CreateGraphOfSlope(zgc); } else if (grSettings.GraphType.Equals(GraphTypes.Iteration)) { CreateGraphOfIteration(zgc); } else if (grSettings.GraphType.Equals(GraphTypes.Cobweb)) { CreateGraphOfCobweb(zgc); } else if (grSettings.GraphType.Equals(GraphTypes.TwoDIteration)) { CreateGraphOf2DIteration(zgc); } // Tell ZedGraph to refigure the axes since the data have changed zgc.AxisChange(); if (grSettings.Grid) { myPane.XAxis.MajorGrid.IsVisible = true; myPane.YAxis.MajorGrid.IsVisible = true; myPane.XAxis.Color = Color.FromArgb(255 - grSettings.Background.R, 255 - grSettings.Background.G, 255 - grSettings.Background.B); myPane.XAxis.MajorGrid.Color = Color.FromArgb(255 - grSettings.Background.R, 255 - grSettings.Background.G, 255 - grSettings.Background.B); myPane.YAxis.Color = Color.FromArgb(255 - grSettings.Background.R, 255 - grSettings.Background.G, 255 - grSettings.Background.B); myPane.YAxis.MajorGrid.Color = Color.FromArgb(255 - grSettings.Background.R, 255 - grSettings.Background.G, 255 - grSettings.Background.B); } else { myPane.XAxis.MajorGrid.IsVisible = false; myPane.YAxis.MajorGrid.IsVisible = false; } this.Cursor = Cursors.Default; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void CreateScatterplot(ZedGraphControl zgc) { GraphPane myPane = zgc.GraphPane; myPane.CurveList.Clear(); // Set the titles myPane.Title.IsVisible = false; myPane.XAxis.Title.Text = "x"; myPane.YAxis.Title.Text = "y"; myPane.GraphObjList.Clear(); int colorIndex = -1; int colorSymbol = -1; //if (convexHull != null && convexHull.Count > 0) //{ // foreach (List<Vertex> vrt in convexHull) // { // ++colorIndex; // if (colorIndex >= brushes.Count) // { // colorIndex = 0; // } // ++colorSymbol; // if (colorSymbol >= symbolTypes.Length) // { // colorSymbol = 0; // } // PointD[] pol = new PointD[vrt.Count]; // PolyObj obj = new PolyObj(); // obj.Fill = new Fill(colors[colorIndex]); // obj.Fill.Color = Color.Transparent; // // obj.ZOrder = ZOrder.E_BehindCurves; // int id = -1; // foreach (Vertex cl in vrt) // { // pol[++id] = new PointD(cl[0], cl[1]); // } // obj.Points = pol; // myPane.GraphObjList.Add(obj); // } //} if (facilities != null && facilities.Count > 0) { for (int f = 0; f < facilities.Count; ++f) { Facility fac = facilities[f]; List <int> clients = fac.VertexIndices; PointPairList list1 = new PointPairList(); foreach (int cl in clients) { list1.Add(vertices[cl][0], vertices[cl][1]); } ++colorIndex; if (colorIndex >= brushes.Count) { colorIndex = 0; } ++colorSymbol; if (colorSymbol >= symbolTypes.Length) { colorSymbol = 0; } Fill fillCurrent = new Fill(colors[colorIndex]); // Add the curve LineItem myCurve = myPane.AddCurve("F" + f, list1, colors[colorIndex], SymbolType.Circle); myCurve.Line.IsVisible = false; myCurve.Line.Fill = fillCurrent; myCurve.Symbol.Size = 1; myCurve.Symbol.Border.IsVisible = true; myCurve.Symbol.Fill = new Fill(colors[colorIndex]); myCurve.Symbol.Fill.IsVisible = true; } } else { for (int i = 0; i < vertices.Length; ++i) { PointPairList list1 = new PointPairList(); list1.Add(vertices[i][0], vertices[i][1]); ++colorIndex; if (colorIndex >= brushes.Count) { colorIndex = 0; } ++colorSymbol; if (colorSymbol >= symbolTypes.Length) { colorSymbol = 0; } // Add the curve LineItem myCurve = myPane.AddCurve("V" + i, list1, Color.Green, SymbolType.Circle); myCurve.Symbol.Size = 0.7f; myCurve.Line.IsVisible = false; myCurve.Symbol.Border.IsVisible = true; // myCurve.Symbol.Fill = new Fill(Color.Blue); //myCurve.Symbol.Fill.IsVisible = false; } } //// Add the curve //LineItem myCurve = myPane.AddCurve("G1", list1, Color.Blue, SymbolType.Diamond); //myCurve.Line.IsVisible = false; //myCurve.Symbol.Border.IsVisible = false; //myCurve.Symbol.Fill = new Fill(Color.Blue); //myCurve = myPane.AddCurve("G2", list2, Color.Green, SymbolType.Diamond); //myCurve.Line.IsVisible = false; //myCurve.Symbol.Border.IsVisible = false; //myCurve.Symbol.Fill = new Fill(Color.Green); // Fill the background of the chart rect and pane //myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f); //myPane.Fill = new Fill(Color.White, Color.SlateGray, 45.0f); myPane.Fill = new Fill(Color.WhiteSmoke); zgc.AxisChange(); zgc.Invalidate(); }
private void CreateTimeGraph(ZedGraphControl zgc, List <double> xData, List <double> yData, string strname) { Color color = Color.Blue; switch (ColorcomboBox.Text) { case "Blue": color = Color.Blue; break; case "Green": color = Color.Green; break; case "Beige": color = Color.Beige; break; case "Black": color = Color.Black; break; case "Brown": color = Color.Brown; break; case "Gray": color = Color.Gray; break; case "Ivory": color = Color.Ivory; break; case "Khaki": color = Color.Blue; break; case "Pink": color = Color.Pink; break; case "Purple": color = Color.Purple; break; case "Red": color = Color.Red; break; case "Silver": color = Color.Silver; break; case "Turquoise": color = Color.Turquoise; break; case "Violet": color = Color.Violet; break; case "Yellow": color = Color.Yellow; break; default: break; } GraphPane myPane = zgc.GraphPane; // Set the titles and axis labels double[] x = xData.ToArray(); double[] y = yData.ToArray(); // Make up some data points from the Sine function LineItem myCurve; // Generate a blue curve with circle symbols, and "My Curve 2" in the legend myCurve = zedGraphControl1.GraphPane.AddCurve("Time" + strname, x, y, color, SymbolType.None); myCurve.Line.Width = 2.0f; // Make the symbols opaque by filling them with white myCurve.Symbol.Fill = new Fill(Color.White); // Fill the axis background with a color gradient zgc.AxisChange(); zgc.Refresh(); }
protected void AxisChange() { m_cZG.AxisChange(); }
private void CreateGraph(ZedGraphControl zgc) { // Get a reference to the GraphPane instance in the ZedGraphControl GraphPane myPane = zgc.GraphPane; // Set the titles and axis labels myPane.Title.Text = "Data Logger"; myPane.XAxis.Title.Text = "Time"; myPane.YAxis.Title.Text = "Temperature [°C]"; myPane.Y2Axis.Title.Text = "Humidity [%]"; // Add gridlines myPane.XAxis.MajorGrid.IsVisible = true; myPane.YAxis.MajorGrid.IsVisible = true; // myPane.Y2Axis.MajorGrid.IsVisible = true; myPane.XAxis.MajorGrid.Color = Color.LightBlue; myPane.YAxis.MajorGrid.Color = Color.LightBlue; //myPane.Y2Axis.MajorGrid.Color = Color.LightBlue; // Make the Y axis scale colors myPane.YAxis.Scale.FontSpec.FontColor = Color.Blue; myPane.YAxis.Title.FontSpec.FontColor = Color.Blue; myPane.Y2Axis.Scale.FontSpec.FontColor = Color.DarkGray; myPane.Y2Axis.Title.FontSpec.FontColor = Color.DarkGray; // Manually set the axis range myPane.YAxis.Scale.Min = -20; myPane.YAxis.Scale.Max = 60; myPane.Y2Axis.Scale.Min = 0; myPane.Y2Axis.Scale.Max = 100; // First Y Axis Settings //myPane.YAxis.MajorGrid.IsZeroLine = false; myPane.YAxis.MinorTic.IsOpposite = false; myPane.YAxis.MajorTic.IsOpposite = false; // Y2 Axis Settings myPane.Y2Axis.IsVisible = true; myPane.Y2Axis.MinorTic.IsOpposite = false; myPane.Y2Axis.MajorTic.IsOpposite = false; // Fill the axis background with a gradient myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45F); //myPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0f); myPane.Fill = new Fill(Color.White, Color.FromArgb(220, 220, 255), 45F); //myPane.Fill = new Fill(Color.LightSlateGray, Color.White, 45.0f); // Legend position myPane.Legend.Position = LegendPos.Top; // Set the XAxis to date type myPane.XAxis.Type = AxisType.Date; myPane.XAxis.Scale.MajorUnit = DateUnit.Second; zedGraphControl1.GraphPane.XAxis.Scale.Format = "T"; zedGraphControl1.GraphPane.XAxis.Type = AxisType.Date; // x-Axis type, scale in minutes after start //myPane.XAxis.Scale.Min = 0; //myPane.XAxis.Scale.Max = 20; //myPane.XAxis.Scale.MinorStep = 1; //myPane.XAxis.Scale.MajorStep = 5; // Initially, a curve is added with no data points (list is empty) curve0 = myPane.AddCurve("", list1, Color.Blue, SymbolType.None); curve1 = myPane.AddCurve("", list2, Color.DarkGray, SymbolType.None); // curve line widths curve0.Line.Width = 1.8F; curve1.Line.Width = 1.8F; zgc.AxisChange(); zgc.Invalidate(); }
// Call this method from the Form_Load method, passing your ZedGraphControl public void CreateChart(ZedGraphControl zgc, TeachPoint tPoint) { // clear previous values GraphPane myPane = zgc.GraphPane; myPane.CurveList.Clear(); // Set the titles and axis labels // myPane.Title = "Teachpoint shift:" + tPoint.Name; // myPane.XAxis.Title = "Updates"; // myPane.YAxis.Title = "Parameter A"; // myPane.Y2Axis.Title = "Parameter B"; // Make up some data points based on the Sine function //PointPairList[] list = new PointPairList[tPoint.Dimension]; //PointPairList list = new PointPairList(); LineItem myCurve = null; SymbolType simbol = SymbolType.Circle; System.Drawing.Color color = Color.Blue; for (int dim = 0; dim < tPoint.Dimension; dim++) { PointPairList list = new PointPairList(); list.Clear(); for (int idx = 0; idx < tPoint.History.History.Count; idx++) { NPoint npoint = (NPoint)tPoint.History.History[idx]; double y = npoint.Coordinate[dim]; list.Add((double)idx, y); } myCurve = myPane.AddCurve(tPoint.DimensionNames[dim], list, color, simbol++); myCurve.Symbol.Fill = new Fill(Color.Gray); } // Associate this curve with the Y2 axis //myCurve.IsY2Axis = true; // // Show the x axis grid // myPane.XAxis.IsShowGrid = true; // // // Make the Y axis scale red // myPane.YAxis.ScaleFontSpec.FontColor = Color.Blue; // myPane.YAxis.TitleFontSpec.FontColor = Color.Blue; // // turn off the opposite tics so the Y tics don't show up on the Y2 axis // myPane.YAxis.IsOppositeTic = false; // myPane.YAxis.IsMinorOppositeTic = false; // // Don't display the Y zero line // myPane.YAxis.IsZeroLine = false; // // Align the Y axis labels so they are flush to the axis // myPane.YAxis.ScaleAlign = AlignP.Inside; // // Manually set the axis range // //myPane.YAxis.Min = -30; // //myPane.YAxis.Max = 30; // // Enable the Y2 axis display //myPane.Y2Axis.IsVisible = true; // Make the Y2 axis scale blue //myPane.Y2Axis.ScaleFontSpec.FontColor = Color.Blue; //myPane.Y2Axis.TitleFontSpec.FontColor = Color.Blue; // turn off the opposite tics so the Y2 tics don't show up on the Y axis //myPane.Y2Axis.IsOppositeTic = false; //myPane.Y2Axis.IsMinorOppositeTic = false; // Display the Y2 axis grid lines //myPane.Y2Axis.IsShowGrid = true; // Align the Y2 axis labels so they are flush to the axis //myPane.Y2Axis.ScaleAlign = AlignP.Inside; // Fill the axis background with a gradient // myPane.AxisFill = new Fill( Color.White, Color.LightGray, 45.0f ); // Calculate the Axis Scale Ranges zgc.AxisChange(); zgc.Refresh(); }
/// <summary> /// 取出1分钟数据的时间,开收盘价,高低价,成交量等信息输入该图 /// </summary> private void Form_Load(object sender, EventArgs e) { //画一张大图,包含价格K线和成交量 MasterPane myPaneMaster = zedG.MasterPane; myPaneMaster.Title.Text = secCode; myPaneMaster.Title.FontSpec.FontColor = Color.Black; //PaneMaster里面画一张价格的小图 GraphPane panePrice = new GraphPane(new Rectangle(10, 10, 10, 10), "Mes", " t ( h )", "Rate"); myPaneMaster.PaneList[0] = (panePrice); //PaneMaster里面画一张成交量的小图 GraphPane paneVolume = new GraphPane(new Rectangle(10, 10, 10, 10), "Mes", " t ( h )", "Rate"); myPaneMaster.PaneList.Add(paneVolume); //蜡烛线例子 //设置名称和坐标轴 panePrice.Title.Text = "K线图"; panePrice.XAxis.Title.Text = "日期"; panePrice.XAxis.Title.FontSpec.FontColor = Color.Black; panePrice.YAxis.Title.Text = "价格"; panePrice.YAxis.Title.FontSpec.FontColor = Color.Black; //spl装载时间,价格数据 StockPointList spl = new StockPointList(); Random rand = new Random(); //将系统时间转化为xDate时间 XDate xStart = XDate.DateTimeToXLDate(startTime); XDate xEnd = XDate.DateTimeToXLDate(endTime); //取Sec的分钟数据,存储于data中 List <DateTime> tradeDays = DateUtils.GetTradeDays(startTime, endTime); //数据准备,取minute数据,然后再将数据进行转换为各个频率 Dictionary <string, List <KLine> > data = new Dictionary <string, List <KLine> >(); foreach (var tempDay in tradeDays) { var stockData = Platforms.container.Resolve <StockMinuteRepository>().fetchFromLocalCsvOrWindAndSave(secCode, tempDay); if (!data.ContainsKey(secCode)) { data.Add(secCode, stockData.Cast <KLine>().ToList()); } else { data[secCode].AddRange(stockData.Cast <KLine>().ToList()); } } //定义变量存储分钟数据 Dictionary <string, List <KLine> > minuteData = new Dictionary <string, List <KLine> >(); foreach (var variety in data) { minuteData.Add(variety.Key, data[variety.Key]); } //定义成交量 double[] volume = new double[minuteData[secCode].Count]; //根据频率选择累加的时间 switch (frequency) { //取tick数据 case 0: log.Info("暂时没有tick数据"); break; //1min K线 case 1: for (int i = 0; i < minuteData[secCode].Count; i++) { double timePoint = i; double open = minuteData[secCode][i].open; double close = minuteData[secCode][i].close; double high = minuteData[secCode][i].high; double low = minuteData[secCode][i].low; volume[i] = minuteData[secCode][i].volume; StockPt pt = new StockPt(timePoint, high, low, open, close, volume[i]); spl.Add(pt); // 时间加1分钟 xStart.AddMinutes(1.0); // but skip the weekends if (XDate.XLDateToDayOfWeek(xStart.XLDate) == 6) { xStart.AddDays(2.0); } } break; //显示5min K线 case 2: Dictionary <string, List <KLine> > minuteData5Min = new Dictionary <string, List <KLine> >(); foreach (var variety in data) { List <KLine> data5K = new List <KLine>(); data5K = MinuteFrequencyTransferUtils.MinuteToNPeriods(minuteData[variety.Key], "Minutely", 5); minuteData5Min.Add(variety.Key, data5K); } for (int i = 0; i < minuteData5Min[secCode].Count; i++) { double timePoint = i; double open = minuteData5Min[secCode][i].open; double close = minuteData5Min[secCode][i].close; double high = minuteData5Min[secCode][i].high; double low = minuteData5Min[secCode][i].low; volume[i] = minuteData[secCode][i].volume; StockPt pt = new StockPt(timePoint, high, low, open, close, volume[i]); spl.Add(pt); // 时间加5分钟 xStart.AddMinutes(5.0); // but skip the weekends if (XDate.XLDateToDayOfWeek(xStart.XLDate) == 6) { xStart.AddDays(2.0); } } break; //显示15min K线 case 3: Dictionary <string, List <KLine> > minuteData15Min = new Dictionary <string, List <KLine> >(); foreach (var variety in data) { List <KLine> data15K = new List <KLine>(); data15K = MinuteFrequencyTransferUtils.MinuteToNPeriods(minuteData[variety.Key], "Minutely", 15); minuteData15Min.Add(variety.Key, data15K); } for (int i = 0; i < minuteData15Min[secCode].Count; i++) { double timePoint = i; double open = minuteData15Min[secCode][i].open; double close = minuteData15Min[secCode][i].close; double high = minuteData15Min[secCode][i].high; double low = minuteData15Min[secCode][i].low; volume[i] = minuteData[secCode][i].volume; StockPt pt = new StockPt(timePoint, high, low, open, close, volume[i]); spl.Add(pt); // 时间加15分钟 xStart.AddMinutes(15.0); // but skip the weekends if (XDate.XLDateToDayOfWeek(xStart.XLDate) == 6) { xStart.AddDays(2.0); } } break; //显示30min K线 case 4: Dictionary <string, List <KLine> > minuteData30Min = new Dictionary <string, List <KLine> >(); foreach (var variety in data) { List <KLine> data30K = new List <KLine>(); data30K = MinuteFrequencyTransferUtils.MinuteToNPeriods(minuteData[variety.Key], "Minutely", 30); minuteData30Min.Add(variety.Key, data30K); } for (int i = 0; i < minuteData30Min[secCode].Count; i++) { double timePoint = i; double open = minuteData30Min[secCode][i].open; double close = minuteData30Min[secCode][i].close; double high = minuteData30Min[secCode][i].high; double low = minuteData30Min[secCode][i].low; volume[i] = minuteData[secCode][i].volume; StockPt pt = new StockPt(timePoint, high, low, open, close, volume[i]); spl.Add(pt); // 时间加30分钟 xStart.AddMinutes(30.0); // but skip the weekends if (XDate.XLDateToDayOfWeek(xStart.XLDate) == 6) { xStart.AddDays(2.0); } } break; //显示60min K线 case 5: Dictionary <string, List <KLine> > minuteData60Min = new Dictionary <string, List <KLine> >(); foreach (var variety in data) { List <KLine> data60K = new List <KLine>(); data60K = MinuteFrequencyTransferUtils.MinuteToNPeriods(minuteData[variety.Key], "Minutely", 60); minuteData60Min.Add(variety.Key, data60K); } for (int i = 0; i < minuteData60Min[secCode].Count; i++) { double timePoint = i; double open = minuteData60Min[secCode][i].open; double close = minuteData60Min[secCode][i].close; double high = minuteData60Min[secCode][i].high; double low = minuteData60Min[secCode][i].low; volume[i] = minuteData[secCode][i].volume; StockPt pt = new StockPt(timePoint, high, low, open, close, volume[i]); spl.Add(pt); // 时间加60分钟 xStart.AddMinutes(60.0); // but skip the weekends if (XDate.XLDateToDayOfWeek(xStart.XLDate) == 6) { xStart.AddDays(2.0); } } break; //显示日K线 case 6: Dictionary <string, List <KLine> > minuteDataDaily = new Dictionary <string, List <KLine> >(); foreach (var variety in data) { List <KLine> dataDaily = new List <KLine>(); dataDaily = MinuteFrequencyTransferUtils.MinuteToNPeriods(minuteData[variety.Key], "Minutely", 240); minuteDataDaily.Add(variety.Key, dataDaily); } for (int i = 0; i < minuteDataDaily[secCode].Count; i++) { double timePoint = i; double open = minuteDataDaily[secCode][i].open; double close = minuteDataDaily[secCode][i].close; double high = minuteDataDaily[secCode][i].high; double low = minuteDataDaily[secCode][i].low; volume[i] = minuteData[secCode][i].volume; StockPt pt = new StockPt(timePoint, high, low, open, close, volume[i]); spl.Add(pt); // 时间加1天 xStart.AddDays(1.0); // but skip the weekends if (XDate.XLDateToDayOfWeek(xStart.XLDate) == 6) { xStart.AddDays(2.0); } } break; } //添加栅格线 //myPane.XAxis.MajorGrid.IsVisible = true; //myPane.YAxis.MajorGrid.IsVisible = true; //myPane.XAxis.MajorGrid.Color = Color.LightGray; //myPane.YAxis.MajorGrid.Color = Color.LightGray; //myPane.YAxis.MajorGrid.DashOff = 0; //myPane.XAxis.MajorGrid.DashOff = 0; panePrice.XAxis.Type = AxisType.Date; panePrice.XAxis.Scale.Format = "MM-dd"; //myPane.XAxis.Scale.FontSpec.Angle = 45;//X轴文字方向,0-90度 //开始Y轴坐标设置 ////设置Y轴坐标的范围 //myPane.YAxis.Scale.Max = Math.Round(maxhi * 1.2, 2);//Math.Ceiling(maxhi); //myPane.YAxis.Scale.Min = Math.Round(minlow * 0.8, 2); //Y轴最大刻度,注意minStep只会显示刻度线不会显示刻度值,minStep为纵坐标步长 panePrice.YAxis.Scale.MajorStep = 0.01; //myPane.XAxis.Scale.FontSpec.FontColor = Color.Black; //myPane.YAxis.Scale.FontSpec.FontColor = Color.Black; panePrice.XAxis.Type = AxisType.DateAsOrdinal; //myPane.Legend.FontSpec.Size = 18f; //myPane.Legend.Position = LegendPos.InsideTopRight; //myPane.Legend.Location = new Location(0.5f, 0.6f, CoordType.PaneFraction, // AlignH.Right, AlignV.Top); JapaneseCandleStickItem myCurve = panePrice.AddJapaneseCandleStick(secCode, spl); myCurve.Stick.IsAutoSize = true; //myCurve.Stick.Color = Color.Blue; myCurve.Stick.FallingFill = new Fill(Color.Green); //下跌颜色 myCurve.Stick.RisingFill = new Fill(Color.Red); //上扬颜色 // pretty it up a little //myPane.Chart.Fill = new Fill(Color.LightBlue, Color.LightGoldenrodYellow, 135.0f); //myPane.Fill = new Fill(Color.Orange, Color.FromArgb(220, 220, 255), 45.0f); Color c1 = ColorTranslator.FromHtml("#ffffff"); Color c2 = ColorTranslator.FromHtml("#ffd693"); panePrice.Chart.Fill = new Fill(c1); //图形区域颜色 panePrice.Fill = new Fill(c2); //整体颜色 //成交量线例子 // Set the Titles paneVolume.Title.Text = "成交量"; paneVolume.XAxis.Title.Text = "Time"; paneVolume.YAxis.Title.Text = "Volume Num"; // Make up some random data points //string[] labels = { "Panther", "Lion", "Cheetah","Cougar", "Tiger", "Leopard" }; //double[] y1 = { 100, 115, 75, 22, 98, 40, -100, -20 }; //double[] y2 = { 90, 100, 95, 35, 80, 35 }; //double[] y3 = { 80, 110, 65, 15, 54, 67 }; //double[] y4 = { 120, 125, 100, 40, 105, 75 }; // Generate a red bar with "Curve 1" in the legend BarItem myBar = paneVolume.AddBar(null, null, volume, Color.Red); //myBar.Bar.Fill = new Fill(Color.Red); // Generate a blue bar with "Curve 2" in the legend //myBar = paneVolume.AddBar("Curve 2", null, y2, Color.Blue); //myBar.Bar.Fill = new Fill(Color.Blue, Color.White, Color.Blue); //设置bar宽度 paneVolume.BarSettings.ClusterScaleWidth = 0.5; log.Info(paneVolume.BarSettings.GetClusterWidth()); paneVolume.BarSettings.Type = BarType.Cluster; // Generate a green bar with "Curve 3" in the legend //myBar = myPane.AddBar("Curve 3", null, y3, Color.Green); //myBar.Bar.Fill = new Fill(Color.Green, Color.White, // Color.Green); // Generate a black line with "Curve 4" in the legend //LineItem myCurve = myPane.AddCurve("Curve 4", //null, y4, Color.Black, SymbolType.Circle); //myCurve.Line.Fill = new Fill(Color.White, //Color.LightSkyBlue, -45F); // Fix up the curve attributes a little //myCurve.Symbol.Size = 8.0F; //myCurve.Symbol.Fill = new Fill(Color.White); //myCurve.Line.Width = 2.0F; // Draw the X tics between the labels instead of // at the labels paneVolume.XAxis.MajorTic.IsBetweenLabels = true; // Set the XAxis labels //myPane.XAxis.Scale.TextLabels = labels; // Set the XAxis to Text type paneVolume.XAxis.Type = AxisType.Text; // Fill the Axis and Pane backgrounds paneVolume.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 90F); paneVolume.Fill = new Fill(Color.FromArgb(250, 250, 255)); using (Graphics g = CreateGraphics()) myPaneMaster.SetLayout(g, 2, 0); zedG.AxisChange(); }
public void CreateScatterplot(ZedGraphControl zgc, double[] x, double[] y, double[] slr, double[] rlr, double[] inliersX, double[] inliersY) { GraphPane myPane = zgc.GraphPane; myPane.CurveList.Clear(); // Set the titles myPane.Title.IsVisible = false; myPane.Chart.Border.IsVisible = false; myPane.XAxis.Title.Text = "X"; myPane.YAxis.Title.Text = "Y"; myPane.XAxis.IsAxisSegmentVisible = true; myPane.YAxis.IsAxisSegmentVisible = true; myPane.XAxis.MinorGrid.IsVisible = false; myPane.YAxis.MinorGrid.IsVisible = false; myPane.XAxis.MinorTic.IsOpposite = false; myPane.XAxis.MajorTic.IsOpposite = false; myPane.YAxis.MinorTic.IsOpposite = false; myPane.YAxis.MajorTic.IsOpposite = false; myPane.XAxis.Scale.MinGrace = 0; myPane.XAxis.Scale.MaxGrace = 0; myPane.YAxis.Scale.MinGrace = 0; myPane.YAxis.Scale.MaxGrace = 0; PointPairList list1 = new PointPairList(x, y); PointPairList list2 = null; PointPairList list3 = null; PointPairList list4 = new PointPairList(inliersX, inliersY); if (slr != null) { list2 = new PointPairList(x, slr); } if (rlr != null) { list3 = new PointPairList(x, rlr); } if (inliersX != null) { list4 = new PointPairList(inliersX, inliersY); } LineItem myCurve; // Add the curves myCurve = myPane.AddCurve("Inliers", list4, Color.Blue, SymbolType.Circle); myCurve.Line.IsVisible = false; myCurve.Symbol.Fill = new Fill(Color.Blue); myCurve = myPane.AddCurve("Points", list1, Color.Gray, SymbolType.Circle); myCurve.Line.IsVisible = false; myCurve.Symbol.Border.IsVisible = false; myCurve.Symbol.Fill = new Fill(Color.Gray); myCurve = myPane.AddCurve("Simple", list2, Color.Red, SymbolType.Circle); myCurve.Line.IsAntiAlias = true; myCurve.Line.IsVisible = true; myCurve.Symbol.IsVisible = false; myCurve = myPane.AddCurve("RANSAC", list3, Color.Blue, SymbolType.Circle); myCurve.Line.IsAntiAlias = true; myCurve.Line.IsVisible = true; myCurve.Symbol.IsVisible = false; zgc.AxisChange(); zgc.Invalidate(); }
public void CreateChart(ZedGraphControl zedGraphControl1) { //time plot //Declare a new GraphPane object GraphPane myPane = zedGraphControl1.GraphPane; // Set the titles and axis labels myPane.Title.Text = "Ngo Oscilloscope"; myPane.XAxis.Title.Text = "Time (seconds)"; myPane.YAxis.Title.Text = "Amplitude (V)"; //myPane.Y2Axis.Title.Text = "Output Amplitude"; // Make up some data points based on the data PointPairList list = new PointPairList(); PointPairList list2 = new PointPairList(); //create the data points to be plotted for (int i = 0; i < graph.Length - 1; i++) { double x = (double)i * delta_t; //convert to time double y = graph[i]; //value in volts double y2 = triggerBar.Value; list.Add(x, y); //add points to the list list2.Add(x, y2); } // Note: All data being plotted by zedgraph have to be “Double” format. // Data should be saved as a PointPairList before plotting. // So “List.Add()” method should be called after you define or // change the data that are plotted. // Generate a red curve with diamond symbols, and "Alpha" in the legend LineItem myCurve = myPane.AddCurve("Signal", list, Color.Red, SymbolType.Diamond); // Fill the symbols with white myCurve.Symbol.Fill = new Fill(Color.White); // Generate a blue curve with circle symbols, and "Beta" in the legend myCurve = myPane.AddCurve("Trigger", list2, Color.Blue, SymbolType.Circle); // Fill the symbols with white myCurve.Symbol.Fill = new Fill(Color.White); // Associate this curve with the Y2 axis myCurve.IsY2Axis = true; //Some enhancing setting: // Show the x axis grid myPane.XAxis.MajorGrid.IsVisible = true; // Make the Y axis scale red myPane.YAxis.Scale.FontSpec.FontColor = Color.Red; myPane.YAxis.Title.FontSpec.FontColor = Color.Red; // turn off the opposite tics so the Y tics don't show up on the Y2 axis myPane.YAxis.MajorTic.IsOpposite = false; myPane.YAxis.MinorTic.IsOpposite = false; // Don't display the Y zero line myPane.YAxis.MajorGrid.IsZeroLine = false; // Align the Y axis labels so they are flush to the axis myPane.YAxis.Scale.Align = AlignP.Inside; // Manually set the axis range myPane.YAxis.Scale.Min = y_min; myPane.YAxis.Scale.Max = y_max; myPane.Y2Axis.Scale.Min = 0; myPane.Y2Axis.Scale.Max = 210; // Enable the Y2 axis display //myPane.Y2Axis.IsVisible = true; // Make the Y2 axis scale blue myPane.Y2Axis.Scale.FontSpec.FontColor = Color.Blue; myPane.Y2Axis.Title.FontSpec.FontColor = Color.Blue; // turn off the opposite tics so the Y2 tics don't show up on the Y axis myPane.Y2Axis.MajorTic.IsOpposite = false; myPane.Y2Axis.MinorTic.IsOpposite = false; // Display the Y2 axis grid lines myPane.Y2Axis.MajorGrid.IsVisible = false; // Align the Y2 axis labels so they are flush to the axis myPane.Y2Axis.Scale.Align = AlignP.Inside; // Fill the axis background with a gradient myPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0f); // Calculate the Axis Scale Ranges //Note: ZedGraphControl.AxisChange() command keep checking and // adjusting the display axis setting according to the List changes. zedGraphControl1.AxisChange(); }
public ODEGraphics(List <Dictionary <string, FloatingPoint> > approximaPoints, List <Dictionary <string, FloatingPoint> > solutionPoints = null, string TAG_1 = "Приближение решения для {0}", string TAG_2 = "Точное решения для {0}") { InitializeComponent(); ZedGraphControl zedGraph = new ZedGraphControl(); zedGraph.Location = new Point(0, 0); zedGraph.Name = "zedGraph"; zedGraph.Size = new Size(600, 600); Controls.Add(zedGraph); GraphPane myPane = zedGraph.GraphPane; myPane.CurveList.Clear(); myPane.Title.Text = "Графики функций решений \n" + "системы ОДУ"; myPane.XAxis.Title.Text = "X"; myPane.YAxis.Title.Text = "Y"; List <List <double> > bufferPoints = new List <List <double> >(); List <double> single2DPoint = new List <double>(); int current_color = 0; foreach (string key in approximaPoints[0].Keys) { if (!key.Equals("x")) { foreach (Dictionary <string, FloatingPoint> namedVector in approximaPoints) { single2DPoint.Add(namedVector["x"].RealValue); single2DPoint.Add(namedVector[key].RealValue); bufferPoints.Add(new List <double>(single2DPoint)); single2DPoint.Clear(); } CreateGraph(myPane, bufferPoints, ALL_COLORS[current_color], string.Format(TAG_1, key)); current_color++; bufferPoints.Clear(); } } if (!(solutionPoints is null)) { foreach (string key in solutionPoints[0].Keys) { if (!key.Equals("x")) { foreach (Dictionary <string, FloatingPoint> namedVector in solutionPoints) { single2DPoint.Add(namedVector["x"].RealValue); single2DPoint.Add(namedVector[key].RealValue); bufferPoints.Add(new List <double>(single2DPoint)); single2DPoint.Clear(); } CreateGraph(myPane, bufferPoints, ALL_COLORS[current_color], string.Format(TAG_2, key)); current_color++; bufferPoints.Clear(); } } } zedGraph.AxisChange(); zedGraph.Invalidate(); }
public static void genChart(ZedGraphControl ct, string productCode, string type, string title, params PointPairList[] lists) { GraphPane pane = ct.GraphPane; ct.IsAntiAlias = true; pane.Border.IsVisible = false; pane.Title.Text = title; pane.Title.FontSpec.Family = "宋体"; pane.Title.FontSpec.Size = 26; pane.Title.FontSpec.IsAntiAlias = true; pane.YAxis.Title.IsVisible = false; pane.Legend.IsVisible = true; pane.Legend.FontSpec.Family = "宋体"; pane.Legend.FontSpec.Size = 20; //倾斜度 pane.XAxis.Scale.FontSpec.Angle = 30; pane.XAxis.Type = AxisType.DateAsOrdinal; if (type.Length == 0 || (type.IndexOf('i') >= 0 && type.IndexOf('m') < 0)) { pane.XAxis.Scale.Format = "yy-MM-dd"; } else { pane.XAxis.Scale.Format = "yy-MM-dd"; } pane.XAxis.Scale.IsReverse = true; pane.XAxis.Scale.FontSpec.Family = "宋体"; pane.XAxis.Scale.FontSpec.IsBold = true; pane.XAxis.Scale.FontSpec.IsAntiAlias = true; //抗锯齿 //pane.XAxis.Scale.FontSpec.IsDropShadow = true; //看起来粗一点 pane.XAxis.Scale.FontSpec.Size = 20; //在对面不显示出刻度 pane.XAxis.MajorTic.IsOpposite = false; pane.XAxis.Title.IsVisible = false; pane.YAxis.Scale.FontSpec.Family = "宋体"; pane.YAxis.Scale.FontSpec.Size = 20; pane.YAxis.MajorGrid.IsVisible = true; pane.YAxis.MajorGrid.PenWidth = 1; pane.YAxis.MajorGrid.DashOff = 2; //虚线中孔间距 pane.YAxis.MajorGrid.DashOn = 2; //虚线单位长度 pane.YAxis.MajorGrid.Color = Color.FromArgb(201, 201, 201); pane.YAxis.MajorTic.IsOpposite = false; //去掉小刻度 pane.XAxis.MinorTic.IsAllTics = false; pane.XAxis.Scale.MajorStep = 1; pane.YAxis.MinorTic.IsAllTics = false; try { pane.YAxis.Scale.MajorStep = Math.Floor(lists[0].Max(list => list.Y) / 20); } catch { pane.XAxis.Scale.MajorStep = 1; } int i = 0; Color color = Color.Red; string legend = "价格指数"; Regex dateRegex = new Regex(@".*日价格趋势.*"); Match m = dateRegex.Match(title); if (m.Success) { legend = "均价"; } foreach (PointPairList list in lists) { if (lists.Length > 1) { switch (i) { case 0: color = Color.Orange; legend = "最低价"; break; case 1: color = Color.Red; legend = "均价"; break; case 2: color = Color.Green; legend = "最高价"; break; } } LineItem curve = pane.AddCurve(legend, list, color, SymbolType.Diamond); curve.Line.Width = 1.5F; curve.Symbol.Fill = new Fill(Color.White); curve.Symbol.Size = 5; curve.Line.IsAntiAlias = true; if (i != 1 && lists.Length > 1) { curve.Line.Style = System.Drawing.Drawing2D.DashStyle.Dot; } i++; } // Leave some extra space on top for the labels to fit within the chart rect //pane.YAxis.Scale.MaxGrace = 0.2; //pane.XAxis.Scale.BaseTic = 50; //pane.Chart.Fill = new Fill(Color.White, Color.SteelBlue, 45.0F); pane.Chart.Border.IsVisible = false; //pane.Chart.Border.Color = Color.Red; //重新计算坐标刻度 ct.AxisChange(); Bitmap bmp = pane.GetImage(270, 200, 1000); if (productCode.Equals("00")) { productCode = ""; } bmp.Save(("chart/" + type + "s" + productCode + ".png").ToUpper()); pane.GetImage(330, 200, 1000).Save(("chart/" + type + "m" + productCode + ".png").ToUpper()); pane.GetImage(675, 200, 1000).Save(("chart/" + type + "l" + productCode + ".png").ToUpper()); }
private void CreateFreqGraph(ZedGraphControl zgc, double[] sectionBuffers) { int FreqMin = int.Parse(FreqMintextBox.Text); int FreqMax = int.Parse(FreqMaxtextBox.Text); convertClkRate = int.Parse(SamplingTextbox.Text); sectionLength = int.Parse(DataLengthtextBox.Text); Freqrange = int.Parse(FreqrangetextBox.Text); Complex[] fftsamples = new Complex[sectionLength]; for (int i = 0; i < sectionLength; i++) { fftsamples[i] = sectionBuffers[i]; } Fourier.Forward(fftsamples, FourierOptions.NoScaling); double[] hzsample = new double[sectionBuffers.Length]; double[] mag = new double[sectionBuffers.Length]; for (int i = 0; i < fftsamples.Length / Freqrange; i++) { mag[i] = (2.0 / sectionLength) * (Math.Abs(Math.Sqrt(Math.Pow(fftsamples[i].Real, 2) + Math.Pow(fftsamples[i].Imaginary, 2)))); hzsample[i] = convertClkRate / sectionLength * i; } int Minxlength = int.Parse(FreqMintextBox.Text); int Maxxlength = int.Parse(FreqMaxtextBox.Text); double[] x = new double[Minxlength]; double[] y = new double[Minxlength]; double[] x1 = new double[Maxxlength]; double[] y1 = new double[Maxxlength]; for (int i = 0; i < x.Length; i++) { x[i] = i; } for (int i = 0; i < x1.Length; i++) { x1[i] = i; } y[Minxlength - 1] = 10; y1[Maxxlength - 1] = 10; zgc.GraphPane.CurveList.Clear(); GraphPane myPane = zgc.GraphPane; // Set the titles and axis labels // Make up some data points from the Sine function PointPairList list = new PointPairList(); LineItem myCurve; LineItem Mincurve; LineItem Maxcurve; // Generate a blue curve with circle symbols, and "My Curve 2" in the legend myCurve = zedGraphControl2.GraphPane.AddCurve("Channel 0", hzsample, mag, Color.Red, SymbolType.None); Mincurve = zedGraphControl2.GraphPane.AddCurve("FreqMin", x, y, Color.DarkBlue, SymbolType.None); Maxcurve = zedGraphControl2.GraphPane.AddCurve("FreqMax", x1, y1, Color.DarkOrange, SymbolType.None); Mincurve.Line.Style = DashStyle.Custom; Mincurve.Line.Width = 2; Mincurve.Line.DashOn = 5; Mincurve.Line.DashOff = 5; Maxcurve.Line.Style = DashStyle.Custom; Maxcurve.Line.Width = 2; Maxcurve.Line.DashOn = 5; Maxcurve.Line.DashOff = 5; // Make the symbols opaque by filling them with white myCurve.Line.Fill = new Fill(Color.White, Color.Red, 45F); myCurve.Symbol.Fill = new Fill(Color.White); // Fill the axis background with a color gradient zgc.AxisChange(); zgc.Refresh(); }
public void CreateBarGraph(ZedGraphControl zgc, double[] discriminants) { GraphPane myPane = zgc.GraphPane; myPane.CurveList.Clear(); myPane.Title.IsVisible = false; myPane.Legend.IsVisible = false; myPane.Border.IsVisible = false; myPane.Border.IsVisible = false; myPane.Margin.Bottom = 20f; myPane.Margin.Right = 20f; myPane.Margin.Left = 20f; myPane.Margin.Top = 30f; myPane.YAxis.Title.IsVisible = true; myPane.YAxis.IsVisible = true; myPane.YAxis.MinorGrid.IsVisible = false; myPane.YAxis.MajorGrid.IsVisible = false; myPane.YAxis.IsAxisSegmentVisible = false; myPane.YAxis.Scale.Max = 9.5; myPane.YAxis.Scale.Min = -0.5; myPane.YAxis.MajorGrid.IsZeroLine = false; myPane.YAxis.Title.Text = "Classes"; myPane.YAxis.MinorTic.IsOpposite = false; myPane.YAxis.MajorTic.IsOpposite = false; myPane.YAxis.MinorTic.IsInside = false; myPane.YAxis.MajorTic.IsInside = false; myPane.YAxis.MinorTic.IsOutside = false; myPane.YAxis.MajorTic.IsOutside = false; myPane.XAxis.MinorTic.IsOpposite = false; myPane.XAxis.MajorTic.IsOpposite = false; myPane.XAxis.Title.IsVisible = true; myPane.XAxis.Title.Text = "Relative class response"; myPane.XAxis.IsVisible = true; myPane.XAxis.Scale.Min = 0; myPane.XAxis.Scale.Max = 100; myPane.XAxis.IsAxisSegmentVisible = false; myPane.XAxis.MajorGrid.IsVisible = false; myPane.XAxis.MajorGrid.IsZeroLine = false; myPane.XAxis.MinorTic.IsOpposite = false; myPane.XAxis.MinorTic.IsInside = false; myPane.XAxis.MinorTic.IsOutside = false; myPane.XAxis.Scale.Format = "0'%"; // Create data points for three BarItems using Random data PointPairList list = new PointPairList(); for (int i = 0; i < discriminants.Length; i++) { list.Add(discriminants[i] * 100, i); } BarItem myCurve = myPane.AddBar("b", list, Color.DarkBlue); // Set BarBase to the YAxis for horizontal bars myPane.BarSettings.Base = BarBase.Y; zgc.AxisChange(); zgc.Invalidate(); }
private void CreateFreqMaxGraph(ZedGraphControl zgc, double[] sectionBuffers) { zgc.GraphPane.CurveList.Clear(); int FreqMin = int.Parse(FreqMintextBox.Text); int FreqMax = int.Parse(FreqMaxtextBox.Text); convertClkRate = int.Parse(SamplingTextbox.Text); sectionLength = int.Parse(DataLengthtextBox.Text); Freqrange = int.Parse(FreqrangetextBox.Text); Complex[] fftsamples = new Complex[sectionLength]; xMaxchartxaxis[0] = xMaxchartxaxis[0] + 1 * sectionLength / convertClkRate; for (int i = 0; i < sectionLength; i++) { fftsamples[i] = sectionBuffers[i]; } Fourier.Forward(fftsamples, FourierOptions.NoScaling); double[] mag = new double[sectionBuffers.Length]; double[] fftmax = new double[1]; for (int i = FreqMin; i < FreqMax; i++) { mag[i] = (2.0 / sectionLength) * (Math.Abs(Math.Sqrt(Math.Pow(fftsamples[i].Real, 2) + Math.Pow(fftsamples[i].Imaginary, 2)))); } fftmax[0] = mag.Max(); GraphPane myPane = zgc.GraphPane; // Set the titles and axis labels double[] y = sectionBuffers; LineItem myCurve; if (LongTermcheckBox.Checked) { list.Add(xMaxchartxaxis, fftmax); // Generate a blue curve with circle symbols, and "My Curve 2" in the legend myCurve = myPane.AddCurve("Channel 0", list, Color.DarkGreen, SymbolType.Square); myCurve.Line.Width = 3.0f; zgc.AxisChange(); zgc.Refresh(); StreamcheckBox.Checked = false; } else if (StreamcheckBox.Checked) { list.Add(xMaxchartxaxis, fftmax); // Generate a blue curve with circle symbols, and "My Curve 2" in the legend myCurve = myPane.AddCurve("Channel 0", list, Color.DarkGreen, SymbolType.Square); myCurve.Line.Width = 3.0f; zgc.AxisChange(); zgc.Refresh(); if (list.Count >= 20) { list.RemoveAt(0); } LongTermcheckBox.Checked = false; } else { MessageBox.Show("chart attribute is null"); errorCode = waveformAiCtrl.Stop(); if (BioFailed(errorCode)) { throw new Exception(); } waveformAiCtrl.Dispose(); SamplingTextbox.Enabled = true; DataLengthtextBox.Enabled = true; ChanneltextBox.Enabled = true; FreqrangetextBox.Enabled = true; DeviceIDtextBox.Enabled = true; FreqMintextBox.Enabled = true; FreqMaxtextBox.Enabled = true; button2.Enabled = true; button3.Enabled = false; } }
public void CreateFrameTimeGraph(ZedGraphControl zg, IList <string> projectInfoLines, IEnumerable <ProteinBenchmark> benchmarks, IList <Color> graphColors) { Debug.Assert(zg != null); try { // get a reference to the GraphPane GraphPane myPane = zg.GraphPane; // Clear the bars myPane.CurveList.Clear(); // Clear the bar labels myPane.GraphObjList.Clear(); // Clear the XAxis Project Information myPane.XAxis.Title.Text = String.Empty; // If no Project Information, get out if (projectInfoLines.Count == 0) { return; } // Create the bars for each benchmark int i = 0; foreach (ProteinBenchmark benchmark in benchmarks) { var yPoints = new double[2]; yPoints[0] = benchmark.MinimumFrameTime.TotalSeconds; yPoints[1] = benchmark.AverageFrameTime.TotalSeconds; CreateBar(i, myPane, benchmark.OwningSlotName, yPoints, graphColors); i++; } // Create the bar labels BarItem.CreateBarLabels(myPane, true, String.Empty, zg.Font.Name, zg.Font.Size, Color.Black, true, false, false); // Set the Titles myPane.Title.Text = "HFM.NET - Client Benchmarks"; var sb = new StringBuilder(); for (i = 0; i < projectInfoLines.Count - 2; i++) { sb.Append(projectInfoLines[i]); sb.Append(" "); } sb.Append(projectInfoLines[i]); myPane.XAxis.Title.Text = sb.ToString(); myPane.YAxis.Title.Text = "Frame Time (Seconds)"; // Draw the X tics between the labels instead of at the labels myPane.XAxis.MajorTic.IsBetweenLabels = true; // Set the XAxis labels var labels = new[] { "Min. Frame Time", "Avg. Frame Time" }; myPane.XAxis.Scale.TextLabels = labels; // Set the XAxis to Text type myPane.XAxis.Type = AxisType.Text; // Fill the Axis and Pane backgrounds myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 90F); myPane.Fill = new Fill(Color.FromArgb(250, 250, 255)); } finally { // Tell ZedGraph to refigure the // axes since the data have changed zg.AxisChange(); // Refresh the control zg.Refresh(); } }
private void CreateFreqGraph(ZedGraphControl zgc, List <double> xData, List <double> yData, string strname) { Color color = Color.Blue; switch (ColorcomboBox.Text) { case "Blue": color = Color.Blue; break; case "Green": color = Color.Green; break; case "Beige": color = Color.Beige; break; case "Black": color = Color.Black; break; case "Brown": color = Color.Brown; break; case "Gray": color = Color.Gray; break; case "Ivory": color = Color.Ivory; break; case "Khaki": color = Color.Blue; break; case "Pink": color = Color.Pink; break; case "Purple": color = Color.Purple; break; case "Red": color = Color.Red; break; case "Silver": color = Color.Silver; break; case "Turquoise": color = Color.Turquoise; break; case "Violet": color = Color.Violet; break; case "Yellow": color = Color.Yellow; break; default: break; } double[] x = xData.ToArray(); double[] y = yData.ToArray(); double convertClkRate = 1 / (x[11] - x[10]); long convertClkrate = Convert.ToInt64(convertClkRate); int sectionLength = x.Length; Complex[] fftsamples = new Complex[sectionLength]; for (int i = 0; i < sectionLength; i++) { fftsamples[i] = y[i]; } Fourier.Forward(fftsamples, FourierOptions.NoScaling); double[] hzsample = new double[y.Length]; double[] mag = new double[y.Length]; for (int i = 0; i < fftsamples.Length / 2; i++) { mag[i] = (2.0 / sectionLength) * (Math.Sqrt(Math.Pow(fftsamples[i].Real, 2) + Math.Pow(fftsamples[i].Imaginary, 2))); hzsample[i] = convertClkRate / sectionLength * i; } GraphPane myPane = zgc.GraphPane; // Set the titles and axis labels // Make up some data points from the Sine function PointPairList list = new PointPairList(); list.Add(hzsample, mag); LineItem myCurve; // Generate a blue curve with circle symbols, and "My Curve 2" in the legend myCurve = zedGraphControl2.GraphPane.AddCurve("Freq" + strname, list, color, SymbolType.None); //myCurve = zedGraphControl2.GraphPane.AddCurve("Channel 0", hzsample, mag, Color.Red, SymbolType.None); // Make the symbols opaque by filling them with white myCurve.Line.Fill = new Fill(Color.White, color, 45F); myCurve.Symbol.Fill = new Fill(Color.White); // Fill the axis background with a color gradient zgc.AxisChange(); zgc.Refresh(); }
public void CreateResultScatterplot(ZedGraphControl zgc, double[][] inputs, double[] expected, double[] output) { GraphPane myPane = zgc.GraphPane; myPane.CurveList.Clear(); // Set the titles myPane.Title.IsVisible = false; myPane.XAxis.Title.Text = sourceColumns[0]; myPane.YAxis.Title.Text = sourceColumns[1]; // Classification problem PointPairList list1 = new PointPairList(); // Z = -1, OK PointPairList list2 = new PointPairList(); // Z = +1, OK PointPairList list3 = new PointPairList(); // Z = -1, Error PointPairList list4 = new PointPairList(); // Z = +1, Error for (int i = 0; i < output.Length; i++) { if (output[i] == -1) { if (expected[i] == -1) { list1.Add(inputs[i][0], inputs[i][1]); } if (expected[i] == 1) { list3.Add(inputs[i][0], inputs[i][1]); } } else { if (expected[i] == -1) { list4.Add(inputs[i][0], inputs[i][1]); } if (expected[i] == 1) { list2.Add(inputs[i][0], inputs[i][1]); } } } // Add the curve LineItem myCurve = myPane.AddCurve("G1 Hits", list1, Color.Blue, SymbolType.Diamond); myCurve.Line.IsVisible = false; myCurve.Symbol.Border.IsVisible = false; myCurve.Symbol.Fill = new Fill(Color.Blue); myCurve = myPane.AddCurve("G2 Hits", list2, Color.Green, SymbolType.Diamond); myCurve.Line.IsVisible = false; myCurve.Symbol.Border.IsVisible = false; myCurve.Symbol.Fill = new Fill(Color.Green); myCurve = myPane.AddCurve("G1 Miss", list3, Color.Blue, SymbolType.Plus); myCurve.Line.IsVisible = false; myCurve.Symbol.Border.IsVisible = true; myCurve.Symbol.Fill = new Fill(Color.Blue); myCurve = myPane.AddCurve("G2 Miss", list4, Color.Green, SymbolType.Plus); myCurve.Line.IsVisible = false; myCurve.Symbol.Border.IsVisible = true; myCurve.Symbol.Fill = new Fill(Color.Green); // Fill the background of the chart rect and pane //myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f); //myPane.Fill = new Fill(Color.White, Color.SlateGray, 45.0f); myPane.Fill = new Fill(Color.WhiteSmoke); zgc.AxisChange(); zgc.Invalidate(); }
/// <summary> /// Draws a sequence statistic chart for the FastqComponent_Details handle within this class /// </summary> public void DrawSequenceStatistics() { Console.WriteLine("Drawing new sequence length distribution!"); FqPerBaseSatistics[] perBaseStatistics = componentDetails.perBaseStatistics; double[] x = new double[perBaseStatistics.Length]; PointPairList boxList = new PointPairList(); PointPairList lowerWhisker = new PointPairList(); PointPairList upperWhisker = new PointPairList(); PointPairList medians = new PointPairList(); int count = 1; for (int i = 0; i < x.Length; i++) { x[i] = count; boxList.Add((double)x[i], (double)perBaseStatistics[i].ThirdQuartile, (double)perBaseStatistics[i].FirstQuartile); medians.Add((double)x[i], (double)perBaseStatistics[i].Median); upperWhisker.Add((double)x[i], (double)perBaseStatistics[i].UpperThreshold); lowerWhisker.Add((double)x[i], (double)perBaseStatistics[i].LowerThreshold); count++; } Size size = graphControl.ClientSize; Rectangle rect = new Rectangle(); rect.Size = size; graphControl.GraphPane = new GraphPane(); graphControl.GraphPane.CurveList.Clear(); graphControl.GraphPane.Rect = rect; GraphPane myPane = graphControl.GraphPane; myPane.Title.Text = "Per Base Statistics " + componentDetails.getGraphName(); // set X and Y axis titles myPane.XAxis.Title.Text = "Base Position"; myPane.YAxis.Title.Text = "Qualities"; CurveItem median = myPane.AddCurve("Median", medians, Color.Green, SymbolType.None); LineItem myLine = (LineItem)median; myLine.Line.IsVisible = true; myLine.Line.IsAntiAlias = true; myLine.Symbol.Fill.Type = FillType.Solid; myLine.Symbol.Size = 1; HiLowBarItem myCurve = myPane.AddHiLowBar("Quartiles", boxList, Color.Black); myCurve.Bar.Fill.Type = FillType.Solid; myCurve.Bar.Fill.Color = Color.Yellow; myCurve.Bar.Border.Color = Color.Yellow; CurveItem lthresholds = myPane.AddCurve("Lower Threshold", lowerWhisker, Color.Red, SymbolType.HDash); LineItem lthreshline = (LineItem)lthresholds; lthreshline.Line.IsVisible = false; lthreshline.Symbol.Fill.Type = FillType.Solid; lthreshline.Symbol.Size = 1; lthreshline.Symbol.Fill.Color = Color.Red; CurveItem uppthesh = myPane.AddCurve("Upper Threshold", upperWhisker, Color.Red, SymbolType.HDash); LineItem uthreshline = (LineItem)uppthesh; uthreshline.Line.IsVisible = false; uthreshline.Symbol.Fill.Type = FillType.Solid; uthreshline.Symbol.Size = 1; uthreshline.Symbol.Fill.Color = Color.Red; graphControl.Focus(); graphControl.AxisChange(); graphControl.Invalidate(); graphControl.Refresh(); }