public void createGraph() { //zgc.GraphPane = new GraphPane(); GraphPane myPane = zgc.GraphPane; // Set the titles and axis labels myPane.Title.Text = this.getMethod() + " results"; myPane.XAxis.Title.Text = "distance"; myPane.YAxis.Title.Text = "relative count"; myCurveG = myPane.AddCurve("Genuines", new PointPairList(), Color.Green, SymbolType.Circle); myCurveI = myPane.AddCurve("Impostors", new PointPairList(), Color.Red, SymbolType.Circle); myCurveG.Line.Width = 1; myCurveI.Line.Width = 1; myCurveG.Line.Fill = new Fill(Color.FromArgb(60, 0, 255, 0)); myCurveI.Line.Fill = new Fill(Color.FromArgb(60, 255, 0, 0)); myCurveG.Symbol.Size = 2; myCurveI.Symbol.Size = 2; myCurveG.Symbol.Fill = new Fill(Color.Green); myCurveI.Symbol.Fill = new Fill(Color.Red); LineItem myCurveThresh = myPane.AddCurve("Thresh", threshPoints, Color.Black, SymbolType.None); myCurveThresh.Line.Width = 1; myCurveThresh.Line.Style = System.Drawing.Drawing2D.DashStyle.Dot; this.updatePanes(); zgc.AxisChange(); }
void DrawError(List <double> xi, List <double> dif, string task) { ZedGraph.PointPairList err_list = new ZedGraph.PointPairList(); int n = xi.Count(); for (int i = 1; i < n; i++) { err_list.Add(xi[i], dif[i]); } zedGraphControl1.GraphPane.XAxis.Min = -0.1; zedGraphControl1.GraphPane.XAxis.Max = 1.0; zedGraphControl1.GraphPane.CurveList.Clear(); ZedGraph.LineItem CurveV = zedGraphControl1.GraphPane.AddCurve("error in scheme`s values", err_list, Color.FromName("Green"), ZedGraph.SymbolType.None); if (task == "test") { zedGraphControl1.GraphPane.YAxis.Title = "|u(x) - v(x)|"; } else if (task == "main") { zedGraphControl1.GraphPane.YAxis.Title = "|v(x) - v2(x)|"; } zedGraphControl1.AxisChange(); zedGraphControl1.Invalidate(); }
void DrawSolve(List <double> xi, List <double> ui, List <double> vi) { ZedGraph.PointPairList v_list = new ZedGraph.PointPairList(); ZedGraph.PointPairList u_list = new ZedGraph.PointPairList(); for (int i = 0; i < xi.Count; i++) { v_list.Add(xi[i], vi[i]); u_list.Add(xi[i], ui[i * 2]); if (i % ((n / 1000) + 1) == 0) { dataGridView1.Rows.Add(i, xi[i], vi[i], ui[i * 2], Math.Abs(vi[i] - ui[i * 2])); } } zedGraphControl2.GraphPane.XAxis.Min = -0.01; zedGraphControl2.GraphPane.XAxis.Max = 1.0; zedGraphControl2.GraphPane.CurveList.Clear(); zedGraphControl2.GraphPane.Title = "Решение"; ZedGraph.LineItem CurveV = zedGraphControl2.GraphPane.AddCurve("v(x)", v_list, colors[1], ZedGraph.SymbolType.None); ZedGraph.LineItem CurveU = zedGraphControl2.GraphPane.AddCurve("v2(x)", u_list, colors[4], ZedGraph.SymbolType.None); zedGraphControl2.AxisChange(); zedGraphControl2.Invalidate(); }
public Form1() { InitializeComponent(); myPane = myPlot.GraphPane; int status = myDevice.connect(); if (status == 0) { MessageBox.Show("Device couldn't be found!"); Environment.Exit(0); } myPane.XAxis.Scale.Min = 0; myPane.XAxis.Scale.Max = plotWidth; myPane.YAxis.Scale.Min = 0; myPane.YAxis.Scale.Max = 5; myDevice.pinMode(2, 1); myLine = myPane.AddCurve("Analog Voltage", myPoints, Color.Blue, SymbolType.None); myDevice.initPwm(); myLine.Line.Width = 1; myPlot.Invalidate(); myPlot.AxisChange(); myTimer.Start(); }
public GraphController(Model model, ZedGraphControl graphControl) { this.model = model; this.graphControl = graphControl; this.graphPane = graphControl.GraphPane; // Initialize lines this.lineItemA = this.graphPane.AddCurve("Person A", new PointPairList(), Color.Red, SymbolType.Diamond); this.lineItemB = this.graphPane.AddCurve("Person B", new PointPairList(), Color.Blue, SymbolType.Circle); this.lineItemAgent = this.graphPane.AddCurve("Agent", new PointPairList(), Color.Green, SymbolType.Star); this.lineItemAgent.IsY2Axis = true; // Set the Titles this.graphPane.Title.Text = "Graph of persons' data and the agent's state"; this.graphPane.XAxis.Title.Text = "Time"; this.graphPane.XAxis.Type = AxisType.Date; this.graphPane.Y2Axis.Title.Text = "Agent's state"; this.graphPane.YAxis.Scale.Min = -4; this.graphPane.YAxis.Scale.Max = 4; this.graphPane.Y2Axis.Scale.Min = -4; this.graphPane.Y2Axis.Scale.Max = 4; this.graphPane.Y2Axis.IsVisible = true; // Update threshold lines UpdateThresholdLines(); }
private void Form1_Load(object sender, EventArgs e) { // set your pane myPane = zedGraphControl1.GraphPane; // set a title myPane.Title.Text = "This is an example!"; // set X and Y axis titles myPane.XAxis.Title.Text = "X Axis"; myPane.YAxis.Title.Text = "Y Axis"; // ---- CURVE ONE ---- // draw a sin curve for (int i = 0; i < 100; i++) { listPointsOne.Add(i, Math.Sin(i)); } // set lineitem to list of points myCurveOne = myPane.AddCurve(null, listPointsOne, Color.Black, SymbolType.Circle); // --------------------- // ---- CURVE TWO ---- listPointsTwo.Add(10, 50); listPointsTwo.Add(50, 50); // set lineitem to list of points myCurveTwo = myPane.AddCurve(null, listPointsTwo, Color.Blue, SymbolType.None); myCurveTwo.Line.Width = 5; // --------------------- // delegate to draw zedGraphControl1.AxisChange(); }
public void AddCurve(GraphPane pane, string name, string measure, Color color, SymbolType sType, int capacity) { _dataPointList = new RollingPointPairList(capacity); // Добавим кривую пока еще без каких-либо точек _myCurve = pane.AddCurve(string.Format("{0} ({1})",name,measure), _dataPointList, color, sType); }
void DrawError(List <double> xi, List <double> dif) { ZedGraph.PointPairList err_list = new ZedGraph.PointPairList(); xdifference = dif[0]; xPoint = xi[0]; for (int i = 1; i < xi.Count; i++) { err_list.Add(xi[i], dif[i]); if (xdifference < dif[i]) { xdifference = dif[i]; xPoint = xi[i]; } } zedGraphControl1.GraphPane.XAxis.Min = -0.01; zedGraphControl1.GraphPane.XAxis.Max = 1.0; zedGraphControl1.GraphPane.CurveList.Clear(); zedGraphControl1.GraphPane.Title = "Погрешность"; ZedGraph.LineItem CurveV = zedGraphControl1.GraphPane.AddCurve("error in scheme`s values", err_list, colors[1], ZedGraph.SymbolType.None); zedGraphControl1.AxisChange(); zedGraphControl1.Invalidate(); }
public GcsMainPanel() { InitializeComponent(); _btn_ge_server.Enabled = false; _btn_goto_ge.Enabled = false; artificialHorizon.BackColor = toolStripContainer1.ContentPanel.BackColor; _heightLine = _zgc_height.GraphPane.AddCurve("Height", new PointPairList(), Color.Blue, SymbolType.None); _zgc_height.GraphPane.Title.IsVisible = false; _zgc_height.GraphPane.YAxis.MajorGrid.IsVisible = true; _zgc_height.GraphPane.XAxis.Title.IsVisible = false; _zgc_height.AxisChange(); _zgc_height.GraphPane.Legend.IsVisible = false; _zgc_height.GraphPane.IsFontsScaled = false; _zgc_height.GraphPane.YAxis.Title.Text = "Height [m]"; _zgc_height.GraphPane.XAxis.IsVisible = false; _speedLine = _zgc_speed.GraphPane.AddCurve("Speed", new PointPairList(), Color.Blue, SymbolType.None); _zgc_speed.GraphPane.Title.IsVisible = false; _zgc_speed.GraphPane.YAxis.MajorGrid.IsVisible = true; _zgc_speed.GraphPane.XAxis.Title.IsVisible = false; _zgc_speed.AxisChange(); _zgc_speed.GraphPane.Legend.IsVisible = false; _zgc_speed.GraphPane.IsFontsScaled = false; _zgc_speed.GraphPane.YAxis.Title.Text = "Speed [km/h]"; _zgc_speed.GraphPane.XAxis.IsVisible = false; _beginDateTime = DateTime.Now; }
public void CreateGraph() { // get a reference to the GraphPane GraphPane myPane = this.zedGraphControlBode.GraphPane; a = this.myBodeFunction.bode(10, 20, 10, 10); zedGraphControlBode.Invalidate(); zedGraphControlBode.AxisChange(); // Generate a red curve with diamond // symbols, and "Porsche" in the legend // Generate a blue curve with circle // symbols, and "Piper" in the legend BodeCurve = myPane.AddCurve("Command", this.a, Color.Blue, SymbolType.None); this.BodeCurve.Line.Width = 3.0F; // Tell ZedGraph to refigure the` // axes since the data have changed myPane.XAxis.Type = AxisType.Linear; // myPane.XAxis.Scale.Format = "mm:ss"; // 24 hour clock for HH myPane.XAxis.MajorGrid.IsVisible = true; zedGraphControlBode.AxisChange(); }
public IXAccelHome() { InitializeComponent(); graphXIndex = 0; accelData = new List<Int16>(); zedGraphDataList = new NoDupePointList(); /*for (double i = 0; i < 36; i++) { double x = i * 10.0 + 50.0; double y = Math.Sin(i * Math.PI / 15.0) * 16.0; zedGraphDataList.Add(x, y); }*/ zedGraphCurve = ZedGraphFrontPage.GraphPane.AddCurve("AccelData", zedGraphDataList, Color.Red); zedGraphCurve.Line.Width = 1.5F; zedGraphCurve.Symbol.Fill = new Fill(Color.White); zedGraphCurve.Symbol.Size = 5; zedGraphCurve.Label.IsVisible = false; ZedGraphFrontPage.GraphPane.YAxis.Scale.Min = -4096; ZedGraphFrontPage.GraphPane.YAxis.Scale.Max = 4096; ZedGraphFrontPage.GraphPane.XAxis.Scale.Min = 0; ZedGraphFrontPage.GraphPane.XAxis.Scale.Max = 500000; ZedGraphFrontPage.AxisChange(); Refresh(); }
public SetCollectProperty(LineItem lineItem,string CollectId) { InitializeComponent(); this.lineItem = lineItem; this.CollectId = CollectId; this.label_CollectId.Text = CollectId.ToString(); this.comboBox_LineStyle.SelectedIndex = 0; this.comboBox_SymbolType.DataSource = Enum.GetNames(typeof(SymbolType)); }
private void button2_Click(object sender, EventArgs e) { double sigma = Convert.ToDouble(textBox1.Text); int N = Convert.ToInt32(textBox3.Text); int n = elem.val.Length; double[] interval = new double[N + 1]; double[] value = new double[N]; double[] f = new double[N]; //строим функции распределения ZedGraph.PointPairList F_list = new ZedGraph.PointPairList(); ZedGraph.PointPairList Fn_list = new ZedGraph.PointPairList(); zedGraphControl1.GraphPane.Title.Text = "График функций распределения"; zedGraphControl1.GraphPane.XAxis.Title.Text = "X"; zedGraphControl1.GraphPane.YAxis.Title.Text = "F(x)"; double D = 0.0; double h = elem.val[n - 1] / 1000.0; int sum = 0; for (int i = 0; i < 1000; i++) { sum = 0; for (int j = 0; j < n; j++) { double temp = elem.val[0] + h * i; if (elem.val[j] < elem.val[0] + h * i) { sum++; } } if (Fn_list.Count != 0) { Fn_list.Add(elem.val[0] + h * i, Fn_list[Fn_list.Count - 1].Y); } Fn_list.Add(elem.val[0] + h * i, (double)sum / (double)n); F_list.Add(elem.val[0] + h * i, 1 - Math.Exp(-(elem.val[0] + h * i) * (elem.val[0] + h * i) / (2 * sigma * sigma))); D = Math.Max(D, Math.Abs((double)sum / (double)n - (1 - Math.Exp(-(elem.val[0] + h * i) * (elem.val[0] + h * i) / (2 * sigma * sigma))))); } zedGraphControl1.GraphPane.CurveList.Clear(); textBox4.Text = D.ToString(); ZedGraph.LineItem CurveF = zedGraphControl1.GraphPane.AddCurve("F", F_list, Color.FromName("Red"), ZedGraph.SymbolType.None); ZedGraph.LineItem CurveFn = zedGraphControl1.GraphPane.AddCurve("Fвыб", Fn_list, Color.FromName("Green"), ZedGraph.SymbolType.None); zedGraphControl1.AxisChange(); zedGraphControl1.Invalidate(); }
public Barier(Interval interval) { points = new PointPairList(); this.interval = interval; curve = new LineItem("", points, Color.SteelBlue, SymbolType.Diamond); curve.Line.IsVisible = false; curve.Symbol.Fill.Color = Color.SteelBlue; curve.Symbol.Fill.Type = FillType.Solid; interval.graphPane.CurveList.Add(curve); barierType = "Равнины, луга, соланчаки"; }
private void CreateGraph() { GraphPane myPaneLeft = zedGraphControl1.GraphPane; GraphPane myPaneRight = zedGraphControl2.GraphPane; myPaneLeft.Title.Text = "Plot of Left Foot Motion.\n"; myPaneLeft.XAxis.Title.Text = "Time (seconds)"; myPaneLeft.YAxis.Title.Text ="Left foot motion (mm)"; myPaneRight.Title.Text = "Plot of Right Foot Motion.\n"; myPaneRight.XAxis.Title.Text = "Time (seconds)"; myPaneRight.YAxis.Title.Text = "Right foot motion (mm)"; //lists to save points as they come from the MCE xDataL = new PointPairList(); yDataL = new PointPairList(); zDataL = new PointPairList(); xDataR = new PointPairList(); yDataR = new PointPairList(); zDataR = new PointPairList(); // Initially, a curve is added with no data points (list is empty) // Color is blue, and there will be no symbols // 2nd line graph (red) added to show peaks curveLeft = myPaneLeft.AddCurve("z-position", zDataL, Color.Blue, SymbolType.None); curveLeft = myPaneLeft.AddCurve("y-position", yDataL, Color.Red, SymbolType.None); curveLeft = myPaneLeft.AddCurve("x-position", xDataL, Color.Green, SymbolType.None); curveRight = myPaneRight.AddCurve("z-position", zDataR, Color.Blue, SymbolType.None); curveRight = myPaneRight.AddCurve("y-position", yDataR, Color.Red, SymbolType.None); curveRight = myPaneRight.AddCurve("x-position", xDataR, Color.Green, SymbolType.None); //curve = myPane.AddCurve("Peak", peakData, Color.Red, SymbolType.Plus); // Just manually control the X axis range so it scrolls continuously // instead of discrete step-sized jumps myPaneLeft.XAxis.Scale.Min = 0; myPaneLeft.XAxis.Scale.Max = 6.0; myPaneLeft.YAxis.Scale.Min = -800; //if needed, fix Y-axis to a max and min myPaneLeft.YAxis.Scale.Max = 500; myPaneLeft.XAxis.Scale.MinorStep = 0.2; myPaneLeft.XAxis.Scale.MajorStep = 1.0; myPaneRight.XAxis.Scale.Min = 0; myPaneRight.XAxis.Scale.Max = 6.0; myPaneRight.YAxis.Scale.Min = -800; //if needed, fix Y-axis to a max and min myPaneRight.YAxis.Scale.Max = 500; myPaneRight.XAxis.Scale.MinorStep = 0.2; myPaneRight.XAxis.Scale.MajorStep = 1.0; // Scale the axes zedGraphControl1.AxisChange(); zedGraphControl2.AxisChange(); }
//creates the graph using the elevationList and colors list, called by drawGraph or by map.MapFrame.VisibleChanged. private void updateGraph(object sender, EventArgs e) { if (zedGraphControl1.IsDisposed) { return; } RectangleF rect = new RectangleF(0, 0, zedGraphControl1.Size.Width, zedGraphControl1.Size.Height); String xAxisLabel = "Distance (" + xUnits + ")"; String yAxisLabel = "Elevation (" + yUnits + ")"; zedGraphControl1.GraphPane = new GraphPane(rect, "Elevation Graph", xAxisLabel, yAxisLabel); if (totalDist != 0) { switch (xUnits) { case Units.Meters: zedGraphControl1.GraphPane.XAxis.Scale.Max = totalDist; break; case Units.Kilometers: zedGraphControl1.GraphPane.XAxis.Scale.Max = totalDist * distanceUnitFactors[0]; break; case Units.Miles: zedGraphControl1.GraphPane.XAxis.Scale.Max = totalDist * distanceUnitFactors[1]; break; case Units.Feet: zedGraphControl1.GraphPane.XAxis.Scale.Max = totalDist * distanceUnitFactors[2]; break; } } //draw curves for (int i = 0; i < rasterLayers.Length; i++) { if (rasterLayers[i].IsVisible) { ZedGraph.LineItem myCurve = zedGraphControl1.GraphPane.AddCurve(rasterLayers[i].LegendText, elevationList[i], colors[i], SymbolType.None); myCurve.Line.IsAntiAlias = true; myCurve.Line.Width = 2f; myCurve.Line.Fill.IsVisible = false; } } //refresh the graph zedGraphControl1.AxisChange(); zedGraphControl1.Refresh(); }
private void button2_Click(object sender, EventArgs e) { met2.Clear(); met2.Tag = ""; var settings2 = GetSettings(new TurnirSelector(), new RandomScreeener()); var calc2 = new SimpleCalculator(settings2); var d1 = DateTime.Now; var curve2V = calc2.Start(); time2 = DateTime.Now.Subtract(d1); label13.Text = Math.Round(time2.TotalSeconds, 3).ToString(CultureInfo.InvariantCulture); met2 = zedGraphControl1.GraphPane.AddCurve("Метод2", new double[] { 0 }, new double[] { 0 }, Color.Blue); foreach (var d in curve2V) { met2.AddPoint(d.Key, d.Value); } zedGraphControl1.AxisChange(); zedGraphControl1.RestoreScale(zedGraphControl1.GraphPane); }
private void button1_Click(object sender, EventArgs e) { met1.Clear(); met1.Tag = ""; var settings1 = GetSettings(new RuletteSelector(), new SelectionScreener()); var calc1 = new SimpleCalculator(settings1); var d1 = DateTime.Now; var curve1V=calc1.Start(); time1 = DateTime.Now.Subtract(d1); label12.Text = Math.Round(time1.TotalSeconds, 3).ToString(CultureInfo.InvariantCulture); met1 = zedGraphControl1.GraphPane.AddCurve("Метод1", new double[] { 0 }, new double[] { 0 }, Color.Red); foreach (var d in curve1V) { met1.AddPoint(d.Key, d.Value); } zedGraphControl1.AxisChange(); zedGraphControl1.RestoreScale(zedGraphControl1.GraphPane); }
public ZedGraphWrapper(ZedGraphControl zedGraphControl, string baseName) { this.zedGraphControl = zedGraphControl; this.masterPane = zedGraphControl.GraphPane; baseLine = AddDots(baseName, new PointPairList(), Color.Purple); zedGraphControl.DoubleClickEvent += new ZedGraphControl.ZedMouseEventHandler(zedGraphControl_DoubleClickEvent); zedGraphControl.MouseMoveEvent += new ZedGraphControl.ZedMouseEventHandler(zedGraphControl_MouseMoveEvent); zedGraphControl.GraphPane.AxisChangeEvent += new GraphPane.AxisChangeEventHandler(GraphPane_AxisChangeEvent); PointF paneLeftUpper = this.masterPane.GeneralTransform(new PointF(0, 0), CoordType.ChartFraction); PointF paneRightLower = this.masterPane.GeneralTransform(new PointF(1, 1), CoordType.ChartFraction); heightMultiplier = (paneRightLower.X - paneLeftUpper.X) / (paneRightLower.Y - paneLeftUpper.Y); }
public bool MouseMove1(object sender, MouseEventArgs e) { if (pointList == null || modelNames == null) { return(false); } //only update every quarter of a second DateTime now = DateTime.Now; if ((now - lastUpdate).Milliseconds < 250) { return(false); } ZedGraphControl zgc = (ZedGraphControl)sender; PointF currentPoint = (PointF)e.Location; CurveItem curveItem; int closestPoint; if (zgc.GraphPane.FindNearestPoint(currentPoint, allPointsCurve, out curveItem, out closestPoint)) { //add tooltip showing the model name tt.Show(modelNames[closestPoint], zgc.ParentForm, new Point((int)e.X + 15, (int)e.Y - 15), 2000); //put a circle around the current point currentList.Clear(); currentList.Add(new PointPair(pointList[periodToShow][closestPoint])); circle = zgc.GraphPane.AddCurve("", currentList, Color.Black, SymbolType.Circle); circle.Line.IsVisible = false; circle.Symbol.Border.IsVisible = true; circle.Symbol.Fill.IsVisible = false; circle.Symbol.Size = 8; zgc.Refresh(); lastPoint = e.Location; lastUpdate = DateTime.Now; } else { currentList.Clear(); circle = zgc.GraphPane.AddCurve("", currentList, Color.Black, SymbolType.Circle); zgc.Refresh(); } return(false); }
private void Form1_Load(object sender, EventArgs e) { GraphPane myPane = zedGraphControl1.GraphPane; myPane.Title.Text = "Offsets"; port.Encoding = Encoding.GetEncoding(28591); port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived); // Begin communications port.Open(); // Save 1200 points. At 50 ms sample rate, this is one minute // The RollingPointPairList is an efficient storage class that always // keeps a rolling set of point data without needing to shift any data values RollingPointPairList list_x = new RollingPointPairList(1200); RollingPointPairList list_y = new RollingPointPairList(1200); RollingPointPairList list_z = new RollingPointPairList(1200); // Initially, a curve is added with no data points (list is empty) // Color is blue, and there will be no symbols curve_x = myPane.AddCurve("X", list_x, Color.Blue, SymbolType.None); curve_y = myPane.AddCurve("Y", list_y, Color.Green, SymbolType.None); curve_z = myPane.AddCurve("Z", list_z, Color.Pink, SymbolType.None); // Sample at 50ms intervals timer1.Tick += new EventHandler(timer1_Tick); timer1.Interval = 100; timer1.Enabled = true; timer1.Start(); // Just manually control the X axis range so it scrolls continuously // instead of discrete step-sized jumps myPane.XAxis.Title.Text = "Time"; myPane.XAxis.Scale.Min = 0; myPane.XAxis.Scale.Max = 30; myPane.XAxis.Scale.MinorStep = 1; myPane.XAxis.Scale.MajorStep = 5; myPane.YAxis.Title.Text = "G-force"; // Scale the axes zedGraphControl1.AxisChange(); // Save the beginning time for reference tickStart = Environment.TickCount; }
} // Выборочные характеристики void DrawF(double lmb, List <double> rand_val) { ZedGraph.PointPairList F_list = new ZedGraph.PointPairList(); ZedGraph.PointPairList Fn_list = new ZedGraph.PointPairList(); ZedGraph.PointPairList f_list = new ZedGraph.PointPairList(); double D = 0.0; // Мера расхождения double Fn; //for (int i = 0; i < n; i++) //{ // Fn = (double)i / (double)n; // Fn_list.Add(rand_val[i], Fn); // D = Math.Max(D, Math.Abs(Fn - F(rand_val[i], lmb))); //} //textBox3.Text = D.ToString(); double h = rand_val[n - 1] / 1000.0; int sum = 0; for (int i = 0; i < 1000; i++) { sum = 0; for (int j = 0; j < n; j++) { double temp = rand_val[0] + h * i; if (rand_val[j] < rand_val[0] + h * i) { sum++; } } Fn_list.Add(rand_val[0] + h * i, (double)sum / (double)n); F_list.Add(rand_val[0] + h * i, F(h * i, lmb)); D = Math.Max(D, Math.Abs((double)sum / (double)n - F(rand_val[0] + h * i, lmb))); } textBox3.Text = D.ToString(); zedGraphControl1.GraphPane.CurveList.Clear(); ZedGraph.LineItem CurveF = zedGraphControl1.GraphPane.AddCurve("F", F_list, Color.FromName("Red"), ZedGraph.SymbolType.None); ZedGraph.LineItem CurveFn = zedGraphControl1.GraphPane.AddCurve("Fn", Fn_list, Color.FromName("Blue"), ZedGraph.SymbolType.None); zedGraphControl1.AxisChange(); zedGraphControl1.Invalidate(); } // График функций распределения
/// <summary> /// /// </summary> public void Draw(ZedGraph.GraphPane pane, object dataSource) { if (this.GraphPaneConfig == null) { return; } if (this.DataSource == null) { return; } this.GraphPaneConfig.ConfigGraphPane(pane); foreach (CurveConfigBase cfg in this.GraphPaneConfig.CurveConfigBaseCollection) { CurveDataCollection cds = cfg.Create(dataSource); foreach (CurveData cd in cds) { switch (this.GraphPaneConfig.CurItemType) { case CurveItemType.Line: if (this.GraphPaneConfig.XAxisType == ZedGraph.AxisType.Date) { ZedGraph.LineItem curve = pane.AddCurve(cd.Name, cd.PointList, cd.Color); curve.Symbol.Fill = new ZedGraph.Fill(Color.White); } else if (this.GraphPaneConfig.XAxisType == ZedGraph.AxisType.Text) { LineItem curve = pane.AddCurve(cd.Name, null, cd.YValues, cd.Color); pane.XAxis.Scale.TextLabels = cd.XAxisLabels; curve.Symbol.Fill = new Fill(Color.White); } break; case CurveItemType.Bar: pane.AddBar(cd.Name, null, cd.YValues, cd.Color); pane.XAxis.Scale.TextLabels = cd.XAxisLabels; break; case CurveItemType.Pie: pane.AddPieSlices(cd.YValues, cd.XAxisLabels); break; } } } }
public ChartForm() { InitializeComponent(); var z = zedGraphControl1; GraphPane p = z.GraphPane; tempCurve = AddCurve("Temperatur - Ist", Color.Red); tempSPCurve = AddCurve("Temperatur - Soll", Color.LightSalmon); humCurve = AddCurve("Feuchtigkeit - Ist ", Color.Blue); humSPCurve = AddCurve("Feuchtigkeit - Soll", Color.LightBlue); p.Title.Text = "Verlauf von Temperatur und Feuchtigkeit"; p.XAxis.Title.Text = "Zeit [s]"; p.YAxis.Title.Text = "Temperatur [%], Luftfeuchte [%]"; }
public void CreateChart2(ZedGraphControl zedGraphControl2) { ZedGraph.GraphPane myPane2 = zedGraphControl2.GraphPane; myPane2.Title.Text = "Spectrum Analysis (DFT)"; myPane2.XAxis.Title.Text = "Frequency"; zedGraphControl2.GraphPane.CurveList.Clear(); zedGraphControl2.GraphPane.GraphObjList.Clear(); if (Linear.Checked) { myPane2.YAxis.Title.Text = "[Linearized]"; for (int x = 199; x > 0; x--) { list1.Add(-1 * x, wave[x]); } for (int x = 0; x < 199; x++) { list1.Add(x, wave[x]); } } else { myPane2.YAxis.Title.Text = "[dB]"; for (int x = 199; x > 0; x--) { list1.Add(-1 * x, 20 * Math.Log10(wave[x])); } for (int x = 0; x < 199; x++) { list1.Add(x, 20 * Math.Log10(wave[x])); } } ZedGraph.LineItem myCurve = myPane2.AddCurve("", list1, Color.Black, SymbolType.None); myPane2.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0f); myPane2.XAxis.MajorGrid.IsVisible = true; myPane2.YAxis.MajorGrid.IsVisible = true; zedGraphControl2.GraphPane.YAxis.Scale.MaxAuto = true; myPane2.XAxis.Scale.Min = 0; myPane2.XAxis.Scale.Max = 200; myPane2.XAxis.Scale.MinorStep = 1; myPane2.XAxis.Scale.MajorStep = 10; zedGraphControl2.AxisChange(); zedGraphControl2.Invalidate(); }
public static ZedGraphControl KresliGraf(string nazovGrafu,List<Spread> myCustomObjects, ZedGraphControl zg1) { zg1.GraphPane.CurveList.Clear(); zg1.GraphPane.GraphObjList.Clear(); GraphPane myPane = zg1.GraphPane; // Set the titles and axis labels myPane.Title.Text = nazovGrafu; myPane.XAxis.Title.Text = "Date"; myPane.YAxis.Title.Text = "$"; myPane.XAxis.Type = AxisType.Date; PointPairList list = new PointPairList(); int rok = myCustomObjects.First().Date.Year; DateTime predchadzDatum = myCustomObjects.First().Date; foreach (var item in myCustomObjects) { var x = (double)new XDate(DateTime.Parse(item.Date.ToShortDateString())); var y = item.Value; //Console.WriteLine(x + " " + y); list.Add(x, y); //Console.WriteLine(rok + " > " + item.Date.Year.ToString() + " " + (item.Date + " > " + new DateTime(item.Date.Year, 1, 1)).ToString() + " " + (predchadzDatum + " < " + new DateTime(item.Date.Year, 1, 1)).ToString()); //Console.WriteLine((rok > item.Date.Year).ToString() + " " + (item.Date > new DateTime(item.Date.Year, 1, 1)).ToString() + " " + (predchadzDatum < new DateTime(item.Date.Year, 1, 1)).ToString()); if (item.Date.Year != predchadzDatum.Year) { LineItem line = new LineItem(String.Empty, new[] { x, x }, new[] { myPane.YAxis.Scale.Min, myPane.YAxis.Scale.Max }, Color.Black, SymbolType.None); line.Line.Style = System.Drawing.Drawing2D.DashStyle.Dash; line.Line.Width = 1f; myPane.CurveList.Add(line); Console.WriteLine("Datum " + item.Date); } predchadzDatum = item.Date; } myPane.CurveList.Add(new LineItem("My Curve", list, Color.Blue, SymbolType.None)); zg1.Refresh(); // LineItem myCurve = myPane.AddCurve("My Curve", list, Color.Blue, SymbolType.None); zg1.AxisChange(); return zg1; }
} // График функций распределения void Drawf(double lmb, List <double> rand_val) { ZedGraph.PointPairList f_list = new ZedGraph.PointPairList(); double h = 10.0 / 1000.0; for (int i = 0; i < 1000; i++) { f_list.Add(h * i, f(h * i, lmb)); } zedGraphControl3.GraphPane.CurveList.Clear(); ZedGraph.LineItem Curvef = zedGraphControl3.GraphPane.AddCurve("f", f_list, Color.FromName("Red"), ZedGraph.SymbolType.None); zedGraphControl3.GraphPane.YAxis.Scale.Min = 0.0; zedGraphControl3.GraphPane.XAxis.Scale.Max = 5.001; zedGraphControl3.AxisChange(); zedGraphControl3.Invalidate(); } // График функции плотности
/// <summary> /// Public constructor. /// Initializes form and graph. /// </summary> /// <param name="f"></param> public Graph(Form1 f) { InitializeComponent(); m_parentForm = f; this.Disposed += new EventHandler(Graph_Disposed); m_pane = zedGraphControl1.GraphPane; m_pane.Title.Text = TITLE; m_pane.XAxis.Title.Text = X_AXIS_NAME; m_pane.YAxis.Title.Text = Y_AXIS_NAME; m_pane.XAxis.Type = AxisType.Date; m_pairList = new PointPairList(); m_tempLine = m_pane.AddCurve(CURVE_NAME, m_pairList, Color.Red, SymbolType.None); zedGraphControl1.AxisChange(); }
public void InitGraph(string graphTitle, string xAxisTitle, string yAxisTitle) { zedGraphCtrl.GraphPane.Title.Text = graphTitle; zedGraphCtrl.GraphPane.XAxis.Title.Text = xAxisTitle; zedGraphCtrl.GraphPane.YAxis.Title.Text = yAxisTitle; zedGraphCtrl.GraphPane.XAxis.Scale.MinAuto = true; zedGraphCtrl.GraphPane.XAxis.Scale.MinAuto = true; zedGraphCtrl.GraphPane.YAxis.Type = ZedGraph.AxisType.Linear; zedGraphCtrl.GraphPane.YAxis.Scale.MinAuto = true; zedGraphCtrl.GraphPane.YAxis.Scale.MaxAuto = true; zedGraphCtrl.GraphPane.XAxis.MajorGrid.IsVisible = true; zedGraphCtrl.GraphPane.YAxis.MajorGrid.IsVisible = true; zedGraphCtrl.GraphPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0F); Line_1 = zedGraphCtrl.GraphPane.AddCurve("Current Reading", null, Color.Red, ZedGraph.SymbolType.Diamond); Line_1.Line.Width = 2; zedGraphCtrl.AxisChange( ); zedGraphCtrl.Invalidate( ); }
public void createGraph() { GraphPane myPane = zgc.GraphPane; // Set the titles and axis labels myPane.Title.Text = this.getMethod() + " results"; myPane.XAxis.Title.Text = "template #"; myPane.YAxis.Title.Text = "distance"; myCurveG = myPane.AddCurve("Genuine", new PointPairList(), Color.Black, SymbolType.Diamond); myCurveG.Line.IsVisible = false; myCurveG.Symbol.Border.IsVisible = false; myCurveG.Symbol.Fill = new Fill(Color.Green); myCurveG.Symbol.Size = 6; myCurveI = myPane.AddCurve("Impostor", new PointPairList(), Color.Black, SymbolType.Diamond); myCurveI.Line.IsVisible = false; myCurveI.Symbol.Border.IsVisible = false; myCurveI.Symbol.Fill = new Fill(Color.Red); myCurveI.Symbol.Size = 5; this.updatePanes(); threshPoints.Clear(); threshPoints.Add(new PointPair(-1, this.getStatistics().Thresh)); int max = 0; if (myCurveG.Points.Count > 0) { max = (int)myCurveG.Points[myCurveG.Points.Count - 1].X; } if (myCurveI.Points.Count > 0 && myCurveI.Points[myCurveI.Points.Count - 1].X > max) { max = (int)myCurveI.Points[myCurveI.Points.Count - 1].X; } threshPoints.Add(new PointPair(max + 1, this.getStatistics().Thresh)); LineItem myCurveThresh = myPane.AddCurve("Thresh", threshPoints, Color.Black, SymbolType.None); myCurveThresh.Line.Style = System.Drawing.Drawing2D.DashStyle.Dot; // Calculate the Axis Scale Ranges zgc.AxisChange(); }
private void LoadData() { DataAccess.Libs.ClearAnalysisDataCache(myData); myData.LoadData(); pricePane.myGraphObj.myOnViewportChanged += new Charts.Controls.myGraphControl.OnViewportChanged(this.Chart_OnViewportChanged); volumePanel.myGraphObj.myOnViewportChanged += new Charts.Controls.myGraphControl.OnViewportChanged(this.Chart_OnViewportChanged); pricePane.myGraphObj.myOnPointValue += new Charts.Controls.myGraphControl.OnPointValue(PointValueEventPrice); volumePanel.myGraphObj.myOnPointValue += new Charts.Controls.myGraphControl.OnPointValue(PointValueEventPrice); pricePane.myGraphObj.myGraphPane.CurveList.Clear(); pricePane.myGraphObj.SetSeriesX(myData.DateTime.Values, Charts.AxisType.DateAsOrdinal); switch (cbChartType.myValue) { case AppTypes.ChartTypes.CandleStick: candleCurve = pricePane.myGraphObj.AddCandleStick(myData.DataStockCode, myData.High.Values, myData.Low.Values, myData.Open.Values, myData.Close.Values, myData.Volume.Values, commonClass.Settings.sysChartBarUpColor, commonClass.Settings.sysChartBarDnColor, commonClass.Settings.sysChartBullCandleColor, commonClass.Settings.sysChartBearCandleColor); break; case AppTypes.ChartTypes.Line: lineCurve = pricePane.myGraphObj.AddCurveLine(myData.DataStockCode, myData.Close.Values, SymbolType.Circle, Color.Blue, 1); break; case AppTypes.ChartTypes.Bar: barCurve = pricePane.myGraphObj.AddCurveBar(myData.DataStockCode, myData.Close.Values, Color.Blue, Color.Blue, 1); break; } pricePane.myGraphObj.SetFont(14); pricePane.myGraphObj.DefaultViewport(); pricePane.myGraphObj.UpdateChart(); volumePanel.myGraphObj.myGraphPane.CurveList.Clear(); volumePanel.myGraphObj.SetSeriesX(myData.DateTime.Values, Charts.AxisType.DateAsOrdinal); barCurve = volumePanel.myGraphObj.AddCurveBar(myData.DataStockCode, myData.Volume.Values, Color.Navy, Color.Green, 1); volumePanel.myGraphObj.SetFont(14); volumePanel.myGraphObj.DefaultViewport(); volumePanel.myGraphObj.UpdateChart(); }
void DrawTestError(double[] v, ZedGraphControl graph) { ZedGraph.PointPairList err_list = new ZedGraph.PointPairList(); double h = 1.0 / n; double x = 0.0; eps1 = 0.0; double exact; double temp; x_eps1 = x; for (int i = 0; i < n + 1; i++) { exact = ExactTestSolve(x); temp = Math.Abs(exact - v[i]); err_list.Add(x, temp); if (temp > eps1) { eps1 = temp; x_eps1 = x; } x += h; } graph.GraphPane.XAxis.Min = -0.01; graph.GraphPane.XAxis.Max = 1.0; graph.GraphPane.CurveList.Clear(); graph.GraphPane.Title = "Погрешность"; ZedGraph.LineItem CurveV = graph.GraphPane.AddCurve("|ui-vi|", err_list, colors[1], ZedGraph.SymbolType.None); graph.AxisChange(); graph.Invalidate(); }
void DrawTestSolve(double[] v, ZedGraphControl graph, DataGridView tab) { ZedGraph.PointPairList v_list = new ZedGraph.PointPairList(); ZedGraph.PointPairList u_list = new ZedGraph.PointPairList(); double h = 1.0 / n; double x = 0.0; double exact; double temp; for (int i = 0; i < n + 1; i++) { exact = ExactTestSolve(x); u_list.Add(x, exact); v_list.Add(x, v[i]); temp = Math.Abs(exact - v[i]); if (i % ((n / 1000) + 1) == 0) { tab.Rows.Add(i, x, v[i], exact, temp); } x += h; } graph.GraphPane.XAxis.Min = -0.01; graph.GraphPane.XAxis.Max = 1.0; graph.GraphPane.CurveList.Clear(); graph.GraphPane.Title = "Решение"; ZedGraph.LineItem CurveV = graph.GraphPane.AddCurve("v(x)", v_list, colors[1], ZedGraph.SymbolType.None); ZedGraph.LineItem CurveU = graph.GraphPane.AddCurve("u(x)", u_list, colors[4], ZedGraph.SymbolType.None); graph.AxisChange(); graph.Invalidate(); }
//Функции для работы с графиками void DrawSolve(List <double> xi, List <double> ui, List <double> vi, string task) { ZedGraph.PointPairList v_list = new ZedGraph.PointPairList(); ZedGraph.PointPairList u_list = new ZedGraph.PointPairList(); int m = task == "test" ? 1 : 2; // в случае основной задачи нужно перепрыгивать значения от половинного шага int n = xi.Count(); for (int i = 0; i < n; i++) { v_list.Add(xi[i], vi[i]); u_list.Add(xi[i], ui[i * m]); } zedGraphControl2.GraphPane.XAxis.Min = -0.1; zedGraphControl2.GraphPane.XAxis.Max = 1.0; zedGraphControl2.GraphPane.CurveList.Clear(); if (task == "test") { ZedGraph.LineItem CurveV = zedGraphControl2.GraphPane.AddCurve("num solve", v_list, Color.FromName("Blue"), ZedGraph.SymbolType.None); ZedGraph.LineItem CurveU = zedGraphControl2.GraphPane.AddCurve("exact solve", u_list, Color.FromName("Red"), ZedGraph.SymbolType.None); zedGraphControl2.GraphPane.YAxis.Title = "u(x), v(x)"; } else if (task == "main") { zedGraphControl2.GraphPane.YAxis.Title = "v(x), v2(x)"; ZedGraph.LineItem CurveV = zedGraphControl2.GraphPane.AddCurve("v(x)", v_list, Color.FromName("Blue"), ZedGraph.SymbolType.None); ZedGraph.LineItem CurveU = zedGraphControl2.GraphPane.AddCurve("v2(x)", u_list, Color.FromName("Red"), ZedGraph.SymbolType.None); } zedGraphControl2.AxisChange(); zedGraphControl2.Invalidate(); }
private void updateGraph() { if (radioButton2.Checked) //fill ensembles from customEnsembles list { ensembles = new ProcessData.Ensemble[customEnsembles.Count]; for (int i = 0; i < customEnsembles.Count; i++) { ensembles[i] = customEnsembles[i]; } } processor.findEnsembles(getEnsembles()); graph.drawGraph(zedGraphControl1, futurePeriod); if (list != null) { currentSelection = zedGraphControl1.GraphPane.AddCurve("", list, Color.Black, SymbolType.Circle); currentSelection.Line.IsVisible = false; currentSelection.Symbol.Border.IsVisible = true; currentSelection.Symbol.Fill.IsVisible = false; currentSelection.Symbol.Size = 8; zedGraphControl1.Refresh(); } }
/// <summary> /// Add a curve (<see cref="CurveItem"/> object) to the plot with /// the given data points (double arrays) and properties. /// This is simplified way to add curves without knowledge of the /// <see cref="CurveList"/> class. An alternative is to use /// the <see cref="ZedGraph.CurveList" /> Add() method. /// </summary> /// <param name="label">The text label (string) for the curve that will be /// used as a <see cref="Legend"/> entry.</param> /// <param name="x">An array of double precision X values (the /// independent values) that define the curve.</param> /// <param name="y">An array of double precision Y values (the /// dependent values) that define the curve.</param> /// <param name="color">The color to used for the curve line, /// symbols, etc.</param> /// <param name="symbolType">A symbol type (<see cref="SymbolType"/>) /// that will be used for this curve.</param> /// <returns>A <see cref="CurveItem"/> class for the newly created curve. /// This can then be used to access all of the curve properties that /// are not defined as arguments to the /// <see cref="AddCurve(string,double[],double[],Color,SymbolType)"/> method.</returns> public LineItem AddCurve( string label, double[] x, double[] y, Color color, SymbolType symbolType ) { LineItem curve = new LineItem( label, x, y, color, symbolType ); _curveList.Add( curve ); return curve; }
/// <summary> /// Draw this <see cref="CurveItem"/> to the specified <see cref="Graphics"/> /// device as a symbol at each defined point. The routine /// only draws the symbols; the lines are draw by the /// <see cref="Line.DrawCurve"/> method. This method /// is normally only called by the Draw method of the /// <see cref="CurveItem"/> object /// </summary> /// <param name="g"> /// A graphic device object to be drawn into. This is normally e.Graphics from the /// PaintEventArgs argument to the Paint() method. /// </param> /// <param name="pane"> /// A reference to the <see cref="GraphPane"/> object that is the parent or /// owner of this object. /// </param> /// <param name="curve">A <see cref="LineItem"/> representing this /// curve.</param> /// <param name="scaleFactor"> /// The scaling factor to be used for rendering objects. This is calculated and /// passed down by the parent <see cref="GraphPane"/> object using the /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust /// font sizes, etc. according to the actual size of the graph. /// </param> /// <param name="isSelected">Indicates that the <see cref="Symbol" /> should be drawn /// with attributes from the <see cref="Selection" /> class. /// </param> public void Draw( Graphics g, GraphPane pane, LineItem curve, float scaleFactor, bool isSelected) { var source = this; if (isSelected) source = Selection.Symbol; var minX = (int) pane.Chart.Rect.Left; var maxX = (int) pane.Chart.Rect.Right; var minY = (int) pane.Chart.Rect.Top; var maxY = (int) pane.Chart.Rect.Bottom; // (Dale-a-b) we'll set an element to true when it has been drawn //var isPixelDrawn = new bool[maxX + 1,maxY + 1]; var points = curve.Points; if (points == null || (!_border.IsVisible && !_fill.IsVisible)) return; var sModeSave = g.SmoothingMode; if (_isAntiAlias) g.SmoothingMode = SmoothingMode.HighQuality; // For the sake of speed, go ahead and create a solid brush and a pen // If it's a gradient fill, it will be created on the fly for each symbol //SolidBrush brush = new SolidBrush( this.fill.Color ); using (var pen = source._border.GetPen(pane, scaleFactor)) using (var path = MakePath(g, scaleFactor)) { var rect = path.GetBounds(); using (var brush = source.Fill.MakeBrush(rect)) { var valueHandler = new ValueHandler(pane, false); var xScale = curve.GetXAxis(pane).Scale; var yScale = curve.GetYAxis(pane).Scale; var xIsLog = xScale.IsLog; var yIsLog = yScale.IsLog; var xIsOrdinal = xScale.IsAnyOrdinal; var xMin = xScale.Min; var xMax = xScale.Max; // Loop over each defined point for (var i = 0; i < points.Count; i++) { // Get the user scale values for the current point // use the valueHandler only for stacked types double curX; double curY; if (pane.LineType == LineType.Stack) { double lowVal; valueHandler.GetValues(curve, i, out curX, out lowVal, out curY); } // otherwise, just access the values directly. Avoiding the valueHandler for // non-stacked types is an optimization to minimize overhead in case there are // a large number of points. else { curX = points[i].X; if (curve is StickItem) curY = points[i].Z; else curY = points[i].Y; } // Any value set to double max is invalid and should be skipped // This is used for calculated values that are out of range, divide // by zero, etc. // Also, any value <= zero on a log scale is invalid if (curX == PointPairBase.Missing || curY == PointPairBase.Missing || Double.IsNaN(curX) || Double.IsNaN(curY) || Double.IsInfinity(curX) || Double.IsInfinity(curY) || (curX <= 0 && xIsLog) || (yIsLog && curY <= 0.0) || (!xIsOrdinal && (curX < xMin || curX > xMax))) continue; // Transform the user scale values to pixel locations var tmpX = (int) xScale.Transform(curve.IsOverrideOrdinal, i, curX); var tmpY = (int) yScale.Transform(curve.IsOverrideOrdinal, i, curY); // Maintain an array of "used" pixel locations to avoid duplicate drawing operations //if (tmpX >= minX && tmpX <= maxX && tmpY >= minY && tmpY <= maxY) // guard against the zoom-in case //{ // if (isPixelDrawn[tmpX, tmpY]) continue; // isPixelDrawn[tmpX, tmpY] = true; //} // If the fill type for this symbol is a Gradient by value type, // the make a brush corresponding to the appropriate current value if (_fill.IsGradientValueType || _border._gradientFill.IsGradientValueType) using (var tBrush = _fill.MakeBrush(rect, points[i])) using (var tPen = _border.GetPen(pane, scaleFactor, points[i])) DrawSymbol(g, tmpX, tmpY, path, tPen, tBrush); else // Otherwise, the brush is already defined // Draw the symbol at the specified pixel location DrawSymbol(g, tmpX, tmpY, path, pen, brush); } } }
private void DrawPoints(GraphPane pane, int maxX, int maxY, LineItem curve, IPointList points, IGraphics g, Symbol source, float scaleFactor, int minX, int minY, bool[,] isPixelDrawn) { double curX; double curY; int tmpX; int tmpY; double lowVal; if (points != null && (_border.IsVisible || _fill.IsVisible)) { SmoothingMode sModeSave = g.SmoothingMode; if (_isAntiAlias) { g.SmoothingMode = SmoothingMode.HighQuality; } // For the sake of speed, go ahead and create a solid brush and a pen // If it's a gradient fill, it will be created on the fly for each symbol //SolidBrush brush = new SolidBrush( this.fill.Color ); using (Pen pen = source._border.GetPen(pane, scaleFactor)) using (GraphicsPath path = MakePath(g, scaleFactor)) { RectangleF rect = path.GetBounds(); using (Brush brush = source.Fill.MakeBrush(rect)) { ValueHandler valueHandler = new ValueHandler(pane, false); Scale xScale = curve.GetXAxis(pane).Scale; Scale yScale = curve.GetYAxis(pane).Scale; bool xIsLog = xScale.IsLog; bool yIsLog = yScale.IsLog; bool xIsOrdinal = xScale.IsAnyOrdinal; double xMin = xScale.Min; double xMax = xScale.Max; // Loop over each defined point for (int i = 0; i < points.Count; i++) { // Check that this symbol should be shown, if not, then continue to the next symbol if (!points[i].ShowSymbol) { continue; } // Get the user scale values for the current point // use the valueHandler only for stacked types if (pane.LineType == LineType.Stack) { valueHandler.GetValues(curve, i, out curX, out lowVal, out curY); } // otherwise, just access the values directly. Avoiding the valueHandler for // non-stacked types is an optimization to minimize overhead in case there are // a large number of points. else { curX = points[i].X; if (curve is StickItem) { curY = points[i].Z; } else { curY = points[i].Y; } } // Any value set to double max is invalid and should be skipped // This is used for calculated values that are out of range, divide // by zero, etc. // Also, any value <= zero on a log scale is invalid if (curX != PointPair.Missing && curY != PointPair.Missing && !System.Double.IsNaN(curX) && !System.Double.IsNaN(curY) && !System.Double.IsInfinity(curX) && !System.Double.IsInfinity(curY) && (curX > 0 || !xIsLog) && (!yIsLog || curY > 0.0) && (xIsOrdinal || (curX >= xMin && curX <= xMax))) { // Transform the user scale values to pixel locations tmpX = (int)xScale.Transform(curve.IsOverrideOrdinal, i, curX); tmpY = (int)yScale.Transform(curve.IsOverrideOrdinal, i, curY); // Maintain an array of "used" pixel locations to avoid duplicate drawing operations if (tmpX >= minX && tmpX <= maxX && tmpY >= minY && tmpY <= maxY) // guard against the zoom-in case { if (isPixelDrawn[tmpX, tmpY]) { continue; } isPixelDrawn[tmpX, tmpY] = true; } // If the fill type for this symbol is a Gradient by value type, // the make a brush corresponding to the appropriate current value if (_fill.IsGradientValueType || _border._gradientFill.IsGradientValueType) { using (Brush tBrush = _fill.MakeBrush(rect, points[i])) using (Pen tPen = _border.GetPen(pane, scaleFactor, points[i])) this.DrawSymbol(g, tmpX, tmpY, path, tPen, tBrush); } else { // Otherwise, the brush is already defined // Draw the symbol at the specified pixel location this.DrawSymbol(g, tmpX, tmpY, path, pen, brush); } } } } } g.SmoothingMode = sModeSave; } }
/// <summary> /// 图形描绘 /// </summary> public override void DrawGraph() { #region 图形所需数据 //线条数组[线条数] [每条线的刻度值] double[][] lines; //X轴刻度 double[] xAixsScale; //线条标注 string[] labels; //X轴刻度标注 string[] xAxisScaleLabels; if (base.XAxisScaleRefrence == DataTableStruct.Rows) { xAixsScale = new double[base.DataSource.Rows.Count]; xAxisScaleLabels = new string[base.DataSource.Rows.Count]; for (int i = 0; i < base.DataSource.Rows.Count; i++) { xAixsScale[i] = i; xAxisScaleLabels[i] = base.DataSource.Rows[i][base.CNNameColumn].ToString(); } //要绘制的线条数为数据列数 lines = new double[base.ShowValueColumns.Length][]; //线条标注 labels = new string[lines.Length]; for (int i = 0; i < base.ShowValueColumns.Length; i++) { labels[i] = base.ShowValueColumns[i].ColumnName; } //填充每条线的数据值 for (int i = 0; i < lines.Length; i++) { lines[i] = new double[xAixsScale.Length]; for (int j = 0; j < base.DataSource.Rows.Count; j++) { if (Convert.IsDBNull(base.DataSource.Rows[j][base.ShowValueColumns[i].ColumnField])) { lines[i][j] = 0; } else { lines[i][j] = Convert.ToDouble(base.DataSource.Rows[j][base.ShowValueColumns[i].ColumnField]); } } } } else { xAixsScale = new double[base.ShowValueColumns.Length]; xAxisScaleLabels = new string[base.ShowValueColumns.Length]; for (int i = 0; i < base.ShowValueColumns.Length; i++) { xAixsScale[i] = i; xAxisScaleLabels[i] = base.ShowValueColumns[i].ColumnName; } //要绘制的线条数为数据集的纪录数 lines = new double[base.DataSource.Rows.Count][]; //线条标注 labels = new string[lines.Length]; for (int i = 0; i < base.DataSource.Rows.Count; i++) { labels[i] = base.DataSource.Rows[i][base.CNNameColumn].ToString(); } //填充每条线的数据值 for (int i = 0; i < lines.Length; i++) { lines[i] = new double[xAixsScale.Length]; for (int j = 0; j < base.ShowValueColumns.Length; j++) { if (Convert.IsDBNull(base.DataSource.Rows[i][base.ShowValueColumns[j].ColumnField])) { lines[i][j] = 0; } else { lines[i][j] = Convert.ToDouble(base.DataSource.Rows[i][base.ShowValueColumns[j].ColumnField]); } } } } int maxXaisxScale = xAixsScale.Length; //Console.Beep(); #endregion #region 显示图形 base.GraphContainer.Controls.Clear(); ZedGraph.ZedGraphControl grphTx = new ZedGraph.ZedGraphControl(); grphTx.IsEnableHZoom = false; grphTx.IsEnableVZoom = false; grphTx.IsEnableWheelZoom = false; grphTx.Dock = System.Windows.Forms.DockStyle.Fill; ZedGraph.GraphPane myPane = grphTx.GraphPane; myPane.Title.Text = base.GraphTitle; myPane.XAxis.Title.Text = base.XAxisTitle; myPane.YAxis.Title.Text = base.YAxisTitle; myPane.Chart.Fill = new Fill(Color.FromArgb(255, 255, 245), Color.FromArgb(255, 255, 190), 90F); //线条显示 for (int i = 0; i < lines.Length; i++) { Color color; if (base.Colors == null) { color = GetColor(); } else { color = base.Colors[i]; } ZedGraph.LineItem myCurve = myPane.AddCurve(labels[i], xAixsScale, lines[i], color); myCurve.Symbol.Fill = new Fill(Color.White); } //X轴属性 myPane.XAxis.Scale.Min = 0; //X轴刻度起始值 myPane.XAxis.Scale.Max = maxXaisxScale; //X轴刻度最大值 myPane.XAxis.Scale.TextLabels = xAxisScaleLabels; //x轴刻度中文标注 myPane.XAxis.Type = AxisType.Text; //类型 myPane.XAxis.Scale.FontSpec.Angle = 90; //文字方向 myPane.XAxis.Scale.FontSpec.Size = 11F; //文字大小 // Display the Y axis grid lines myPane.YAxis.MajorGrid.IsVisible = true; myPane.YAxis.MinorGrid.IsVisible = true; BoxObj box = new BoxObj(0, 100, 1, 30, Color.Empty, Color.FromArgb(150, Color.LightGreen)); box.Fill = new Fill(Color.White, Color.FromArgb(200, Color.LightGreen), 45.0F); box.ZOrder = ZOrder.E_BehindCurves; box.IsClippedToChartRect = true; box.Location.CoordinateFrame = CoordType.XChartFractionYScale; myPane.GraphObjList.Add(box); TextObj text = new TextObj("", 0.95f, 85, CoordType.AxisXYScale, AlignH.Right, AlignV.Center); text.FontSpec.Fill.IsVisible = false; text.FontSpec.Border.IsVisible = false; text.FontSpec.IsBold = true; text.FontSpec.IsItalic = true; text.Location.CoordinateFrame = CoordType.XChartFractionYScale; text.IsClippedToChartRect = true; myPane.GraphObjList.Add(text); myPane.Fill = new Fill(Color.WhiteSmoke, Color.Lavender, 0F); grphTx.AxisChange(); base.GraphContainer.Controls.Add(grphTx); #endregion }
private void Draw(ZedGraphControl pane, double[] vals) { double sigma = Convert.ToDouble(textBox1.Text); int N = Convert.ToInt32(textBox3.Text); int n = vals.Length; double[] interval = new double[N + 1]; double[] value = new double[N]; double[] f = new double[N]; //строим функции распределения ZedGraph.PointPairList F_list = new ZedGraph.PointPairList(); ZedGraph.PointPairList Fn_list = new ZedGraph.PointPairList(); zedGraphControl1.GraphPane.Title.Text = "График функций распределения"; zedGraphControl1.GraphPane.XAxis.Title.Text = "X"; zedGraphControl1.GraphPane.YAxis.Title.Text = "F(x)"; double D = 0.0; // Мера расхождения double h = vals[n - 1] / 1000; int sum = 0; for (int i = 0; i < 1000; i++) { sum = 0; for (int j = 0; j < n; j++) { double temp = vals[0] + h * i; if (vals[j] < vals[0] + h * i) { sum++; } } Fn_list.Add(vals[0] + h * i, (double)sum / (double)n); F_list.Add(vals[0] + h * i, 1 - Math.Exp(-(vals[0] + h * i) * (vals[0] + h * i) / (2 * sigma * sigma))); D = Math.Max(D, Math.Abs((double)sum / (double)n - (1 - Math.Exp(-(vals[0] + h * i) * (vals[0] + h * i) / (2 * sigma * sigma))))); } zedGraphControl1.GraphPane.CurveList.Clear(); textBox4.Text = D.ToString(); ZedGraph.LineItem CurveF = zedGraphControl1.GraphPane.AddCurve("F", F_list, Color.FromName("Red"), ZedGraph.SymbolType.None); ZedGraph.LineItem CurveFn = zedGraphControl1.GraphPane.AddCurve("Fn", Fn_list, Color.FromName("Blue"), ZedGraph.SymbolType.None); zedGraphControl1.AxisChange(); zedGraphControl1.Invalidate(); //гистограмма double h2 = (vals[n - 1] - vals[0]) / N; for (int i = 0; i < N; i++) { interval[i] = vals[0] + (double)i * h2; } interval[N] = vals[n - 1]; int sum2; for (int i = 0; i < N; i++) { sum2 = 0; for (int j = 0; j < n; j++) { if ((interval[i] < vals[j]) && (vals[j] <= interval[i + 1])) { sum2++; } } value[i] = (double)sum2 / (h2 * (double)n); } GraphPane pane1 = zedGraphControl2.GraphPane; pane1.CurveList.Clear(); BarItem curve1 = pane1.AddBar(null, null, value, Color.Blue); zedGraphControl2.GraphPane.Title.Text = "Гистограмма"; pane1.YAxis.Scale.Min = 0.0; pane1.YAxis.Scale.Max = value.Max() + 0.001; pane1.BarSettings.MinClusterGap = 0.0f; zedGraphControl2.AxisChange(); zedGraphControl2.Invalidate(); //3 таблица double max = 0.0; for (int i = 0; i < N; i++) { dataGridView3.ColumnCount = N; dataGridView3.RowCount = 3; dataGridView3.Rows[0].HeaderCell.Value = "z [ j ] "; dataGridView3.Rows[1].HeaderCell.Value = "f ( z [ j ] )"; dataGridView3.Rows[2].HeaderCell.Value = "n [ j ] / n ∆[ j ] "; dataGridView3.Columns[i].HeaderText = string.Format("z" + (i + 1), i); dataGridView3.Rows[0].Cells[i].Value = interval[i] + h2 * 0.5; f[i] = ((interval[i] + h2 * 0.5) * Math.Exp(-(interval[i] + h2 * 0.5) * (interval[i] + h2 * 0.5) / (2 * sigma * sigma))) / (sigma * sigma); dataGridView3.Rows[1].Cells[i].Value = f[i]; dataGridView3.Rows[2].Cells[i].Value = value[i]; if (Math.Abs(value[i] - f[i]) > max) { max = Math.Abs(value[i] - f[i]); } } textBox5.Text = max.ToString(); }
public void drawGraph(ZedGraphControl zgc, int period) { if (zgc == null) { zgc = zedGraphControl1; } periodToShow = period; colorIndex = 0; symbolIndex = 0; RectangleF rect = new RectangleF(0, 0, zgc.Size.Width, zgc.Size.Height); String xAxisLabel = "Precipitation Change, %"; String yAxisLabel = "Temperature Change, degC"; dates = datesForm.DateRange; String title = "Changes in Mean Annual Temp & Precip\nComparing " + dates[0].ToString() + " to " + dates[periodToShow + 1].ToString(); zgc.GraphPane = new GraphPane(rect, title, xAxisLabel, yAxisLabel); zgc.GraphPane.Legend.Position = LegendPos.InsideBotRight; zgc.GraphPane.Legend.FontSpec.Size = 8f; // add ensemble points ProcessData.Ensemble[] ensembles = processor.getEnsembles(); for (int i = 0; i < ensembles.Length; i++) { ProcessData.Ensemble ensemble = ensembles[i]; ZedGraph.LineItem curve = zgc.GraphPane.AddCurve(ensemble.ensembleName, ensemble.getEnsemblePoints(periodToShow), getColor(), getSymbol()); curve.Line.IsVisible = false; curve.Symbol.Border.IsVisible = true; curve.Symbol.Fill.IsVisible = false; curve.Symbol.Size = 6; } // add all points pointList = processor.getPoints(); allPointsCurve = zgc.GraphPane.AddCurve(pointList[periodToShow].Count + " GCMs", pointList[periodToShow], Color.Black, SymbolType.Circle); allPointsCurve.Line.IsVisible = false; allPointsCurve.Symbol.Border.IsVisible = false; allPointsCurve.Symbol.Fill.IsVisible = true; allPointsCurve.Symbol.Size = 2; allPointsCurve.Symbol.Fill.Type = FillType.Solid; //change axes to get new mins and maxs for drawing lines zgc.AxisChange(); for (int i = 0; i < ensembles.Length; i++) { ProcessData.Ensemble ensemble = ensembles[i]; if (ensemble.statistical) { //add precip line LineObj line1 = new LineObj(Color.Black, ensemble.center[periodToShow].X, zgc.GraphPane.YAxis.Scale.Min, ensemble.center[periodToShow].X, zgc.GraphPane.YAxis.Scale.Max); line1.Line.Width = 1f; zgc.GraphPane.GraphObjList.Add(line1); //add temp line LineObj line2 = new LineObj(Color.Black, zgc.GraphPane.XAxis.Scale.Min, ensemble.center[periodToShow].Y, zgc.GraphPane.XAxis.Scale.Max, ensemble.center[periodToShow].Y); line2.Line.Width = 1f; zgc.GraphPane.GraphObjList.Add(line2); } } modelNames = processor.getModelNames(); zgc.Refresh(); }
private void _cpuGraphInit() { Color[] cColor = { Color.AliceBlue, Color.Cyan, Color.LightBlue, Color.Aquamarine, Color.Orange, Color.Coral, Color.LightGoldenrodYellow, Color.Gold }; RollingPointPairList[] rpList = new RollingPointPairList[iCores]; LineItem[] lCurve = new LineItem[iCores]; GraphPane myPane = cpuGraphControl.GraphPane; myPane.CurveList.Clear(); myPane.Chart.Fill.Type = FillType.None; myPane.Margin.All = 0; myPane.Margin.Top = 2f; myPane.Title.Text = ""; myPane.Border.IsVisible = false; myPane.Legend.IsVisible = false; myPane.XAxis.Title.Text = ""; myPane.XAxis.Scale.Max = Properties.Settings.Default.f2TimspanCPU; myPane.XAxis.Scale.Min = 0; myPane.XAxis.Scale.IsVisible = false; myPane.XAxis.IsVisible = false; myPane.YAxis.Scale.IsVisible = false; myPane.YAxis.Title.Text = ""; myPane.YAxis.IsVisible = false; myPane.YAxis.Scale.Max = 105; myPane.YAxis.Scale.Min = 0; TextureBrush texBrush = new TextureBrush(Properties.Resources.cpuback); myPane.Fill = new Fill(texBrush, true); int tSpan = Properties.Settings.Default.f2TimspanCPU, timer = Properties.Settings.Default.f2TimerCPU, iPL = 1000 / timer * tSpan; cpuGraphControl.Size = new Size(110, 35);//.Dock = DockStyle.Fill; for (int i = 0; i < iCores; i++) { rpList[i] = new RollingPointPairList(iPL); lCurve[i] = myPane.AddCurve("core" + i.ToString(), rpList[i], cColor[i], SymbolType.None); // lCurve[i].Line.IsSmooth = true; // lCurve[i].Line.SmoothTension = 0.2F; lCurve[i].Line.Width = 0.01F; lCurve[i].Line.IsAntiAlias = true; lCurve[i].IsVisible = false; } cpuGraphControl.AxisChange(); cpuGraphControl.Visible = false; }
private void BUT_log2_Click(object sender, EventArgs e) { Utilities.FFT2 fft = new FFT2(); using ( OpenFileDialog ofd = new OpenFileDialog()) { ofd.Filter = "*.log|*.log"; ofd.ShowDialog(); if (!File.Exists(ofd.FileName)) return; var file = new StreamReader(File.OpenRead(ofd.FileName)); int bins = (int)NUM_bins.Value; int N = 1 << bins; Color[] color = new Color[] { Color.Red, Color.Green, Color.Blue, Color.Black, Color.Violet, Color.Orange }; ZedGraphControl[] ctls = new ZedGraphControl[] { zedGraphControl1, zedGraphControl2, zedGraphControl3, zedGraphControl4, zedGraphControl5, zedGraphControl6 }; // 3 imus * 2 sets of measurements(gyr/acc) datastate[] alldata = new datastate[3 * 2]; for (int a = 0; a < alldata.Length; a++) alldata[a] = new datastate(); Log.DFLog dflog = new Log.DFLog(); while (!file.EndOfStream) { var item = dflog.GetDFItemFromLine(file.ReadLine(), 0); if (item.msgtype == null) { continue; } if (item.msgtype.StartsWith("ACC")) { int sensorno = int.Parse(item.msgtype.Substring(3)) - 1 + 3; alldata[sensorno].type = item.msgtype; int offsetAX = dflog.FindMessageOffset(item.msgtype, "AccX"); int offsetAY = dflog.FindMessageOffset(item.msgtype, "AccY"); int offsetAZ = dflog.FindMessageOffset(item.msgtype, "AccZ"); int offsetTime = dflog.FindMessageOffset(item.msgtype, "TimeUS"); double time = double.Parse(item.items[offsetTime]) / 1000.0; if (time != alldata[sensorno].lasttime) alldata[sensorno].timedelta = alldata[sensorno].timedelta * 0.99 + (time - alldata[sensorno].lasttime) * 0.01; alldata[sensorno].lasttime = time; alldata[sensorno].datax.Add(double.Parse(item.items[offsetAX])); alldata[sensorno].datay.Add(double.Parse(item.items[offsetAY])); alldata[sensorno].dataz.Add(double.Parse(item.items[offsetAZ])); } else if (item.msgtype.StartsWith("GYR")) { int sensorno = int.Parse(item.msgtype.Substring(3)) - 1; alldata[sensorno].type = item.msgtype; int offsetGX = dflog.FindMessageOffset(item.msgtype, "GyrX"); int offsetGY = dflog.FindMessageOffset(item.msgtype, "GyrY"); int offsetGZ = dflog.FindMessageOffset(item.msgtype, "GyrZ"); int offsetTime = dflog.FindMessageOffset(item.msgtype, "TimeUS"); double time = double.Parse(item.items[offsetTime]) / 1000.0; if (time != alldata[sensorno].lasttime) alldata[sensorno].timedelta = alldata[sensorno].timedelta * 0.99 + (time - alldata[sensorno].lasttime) * 0.01; alldata[sensorno].lasttime = time; alldata[sensorno].datax.Add(double.Parse(item.items[offsetGX])); alldata[sensorno].datay.Add(double.Parse(item.items[offsetGY])); alldata[sensorno].dataz.Add(double.Parse(item.items[offsetGZ])); } } int controlindex = 0; foreach (var sensordata in alldata) { if (sensordata.datax.Count <= N) continue; double samplerate = 0; samplerate = Math.Round(1000 / sensordata.timedelta, 1); double[] freqt = fft.FreqTable(N, (int)samplerate); double[] avgx = new double[N / 2]; double[] avgy = new double[N / 2]; double[] avgz = new double[N / 2]; int totalsamples = sensordata.datax.Count; int count = totalsamples / N; int done = 0; while (count > 1) // skip last part { var fftanswerx = fft.rin(sensordata.datax.Skip(N * done).Take(N).ToArray(), (uint)bins); var fftanswery = fft.rin(sensordata.datay.Skip(N * done).Take(N).ToArray(), (uint)bins); var fftanswerz = fft.rin(sensordata.dataz.Skip(N * done).Take(N).ToArray(), (uint)bins); for (int b = 0; b < N / 2; b++) { if (freqt[b] < (double)NUM_startfreq.Value) continue; avgx[b] += fftanswerx[b] / (N / 2); avgy[b] += fftanswery[b] / (N / 2); avgz[b] += fftanswerz[b] / (N / 2); } count--; done++; } ZedGraph.PointPairList pplx = new ZedGraph.PointPairList(freqt, avgx); ZedGraph.PointPairList pply = new ZedGraph.PointPairList(freqt, avgy); ZedGraph.PointPairList pplz = new ZedGraph.PointPairList(freqt, avgz); var curvex = new LineItem(sensordata.type + " x", pplx, color[0], SymbolType.None); var curvey = new LineItem(sensordata.type + " y", pply, color[1], SymbolType.None); var curvez = new LineItem(sensordata.type + " z", pplz, color[2], SymbolType.None); ctls[controlindex].GraphPane.Legend.IsVisible = true; ctls[controlindex].GraphPane.XAxis.Title.Text = "Freq Hz"; ctls[controlindex].GraphPane.YAxis.Title.Text = "Amplitude"; ctls[controlindex].GraphPane.Title.Text = "FFT " + sensordata.type + " - " + Path.GetFileName(ofd.FileName) + " - " + samplerate + "hz input"; ctls[controlindex].GraphPane.CurveList.Clear(); ctls[controlindex].GraphPane.CurveList.Add(curvex); ctls[controlindex].GraphPane.CurveList.Add(curvey); ctls[controlindex].GraphPane.CurveList.Add(curvez); ctls[controlindex].Invalidate(); ctls[controlindex].AxisChange(); ctls[controlindex].GraphPane.XAxis.Scale.Max = samplerate / 2; ctls[controlindex].Refresh(); controlindex++; } } }
//FMT, 131, 43, IMU, IffffffIIf, TimeMS,GyrX,GyrY,GyrZ,AccX,AccY,AccZ,ErrG,ErrA,Temp //FMT, 135, 43, IMU2, IffffffIIf, TimeMS,GyrX,GyrY,GyrZ,AccX,AccY,AccZ,ErrG,ErrA,Temp //FMT, 149, 43, IMU3, IffffffIIf, TimeMS,GyrX,GyrY,GyrZ,AccX,AccY,AccZ,ErrG,ErrA,Temp //FMT, 172, 23, ACC1, IIfff, TimeMS,TimeUS,AccX,AccY,AccZ //FMT, 173, 23, ACC2, IIfff, TimeMS,TimeUS,AccX,AccY,AccZ //FMT, 174, 23, ACC3, IIfff, TimeMS,TimeUS,AccX,AccY,AccZ //FMT, 175, 23, GYR1, IIfff, TimeMS,TimeUS,GyrX,GyrY,GyrZ //FMT, 176, 23, GYR2, IIfff, TimeMS,TimeUS,GyrX,GyrY,GyrZ //FMT, 177, 23, GYR3, IIfff, TimeMS,TimeUS,GyrX,GyrY,GyrZ private void myButton1_Click(object sender, EventArgs e) { Utilities.FFT2 fft = new FFT2(); using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.Filter = "*.log|*.log"; ofd.ShowDialog(); if (!File.Exists(ofd.FileName)) return; var file = new StreamReader(File.OpenRead(ofd.FileName)); int bins = (int)NUM_bins.Value; int N = 1 << bins; double[] datainGX = new double[N]; double[] datainGY = new double[N]; double[] datainGZ = new double[N]; double[] datainAX = new double[N]; double[] datainAY = new double[N]; double[] datainAZ = new double[N]; List<double[]> avg = new List<double[]>(); // 6 avg.Add(new double[N / 2]); avg.Add(new double[N / 2]); avg.Add(new double[N / 2]); avg.Add(new double[N / 2]); avg.Add(new double[N / 2]); avg.Add(new double[N / 2]); object[] datas = new object[] { datainGX, datainGY, datainGZ, datainAX, datainAY, datainAZ }; string[] datashead = new string[] { "GYR1-GyrX", "GYR1-GyrY", "GYR1-GyrZ", "ACC1-AccX", "ACC1-AccY", "ACC1-AccZ" }; Color[] color = new Color[] { Color.Red, Color.Green, Color.Black, Color.Violet, Color.Blue, Color.Orange }; ZedGraphControl[] ctls = new ZedGraphControl[] { zedGraphControl1, zedGraphControl2, zedGraphControl3, zedGraphControl4, zedGraphControl5, zedGraphControl6 }; int samplecounta = 0; int samplecountg = 0; double lasttime = 0; double timedelta = 0; double[] freqt = null; double samplerate = 0; Log.DFLog dflog = new Log.DFLog(); while (!file.EndOfStream) { var item = dflog.GetDFItemFromLine(file.ReadLine(), 0); if (item.msgtype == "ACC1") { int offsetAX = dflog.FindMessageOffset("ACC1", "AccX"); int offsetAY = dflog.FindMessageOffset("ACC1", "AccY"); int offsetAZ = dflog.FindMessageOffset("ACC1", "AccZ"); int offsetTime = dflog.FindMessageOffset("ACC1", "TimeUS"); double time = double.Parse(item.items[offsetTime]) / 1000.0; timedelta = timedelta * 0.99 + (time - lasttime) * 0.01; // we missed gyro data if (samplecounta >= N) continue; datainAX[samplecounta] = double.Parse(item.items[offsetAX]); datainAY[samplecounta] = double.Parse(item.items[offsetAY]); datainAZ[samplecounta] = double.Parse(item.items[offsetAZ]); samplecounta++; lasttime = time; } else if (item.msgtype == "GYR1") { int offsetGX = dflog.FindMessageOffset("GYR1", "GyrX"); int offsetGY = dflog.FindMessageOffset("GYR1", "GyrY"); int offsetGZ = dflog.FindMessageOffset("GYR1", "GyrZ"); int offsetTime = dflog.FindMessageOffset("ACC1", "TimeUS"); double time = double.Parse(item.items[offsetTime]) / 1000.0; // we missed accel data if (samplecountg >= N) continue; datainGX[samplecountg] = double.Parse(item.items[offsetGX]); datainGY[samplecountg] = double.Parse(item.items[offsetGY]); datainGZ[samplecountg] = double.Parse(item.items[offsetGZ]); samplecountg++; } if (samplecounta >= N && samplecountg >= N) { int inputdataindex = 0; foreach (var itemlist in datas) { var fftanswer = fft.rin((double[])itemlist, (uint)bins); for (int b = 0; b < N / 2; b++) { avg[inputdataindex][b] += fftanswer[b] * (1.0 / (N / 2.0)); } samplecounta = 0; samplecountg = 0; inputdataindex++; } } } if (freqt == null) { samplerate = Math.Round(1000 / timedelta, 1); freqt = fft.FreqTable(N, (int)samplerate); } // 0 out all data befor cutoff for (int inputdataindex = 0; inputdataindex < 6; inputdataindex++) { for (int b = 0; b < N/2; b++) { if (freqt[b] < (double) NUM_startfreq.Value) { avg[inputdataindex][b] = 0; continue; } break; } } int controlindex = 0; foreach (var item in avg) { ZedGraph.PointPairList ppl = new ZedGraph.PointPairList(freqt, item); //double xMin, xMax, yMin, yMax; var curve = new LineItem(datashead[controlindex], ppl, color[controlindex], SymbolType.None); //curve.GetRange(out xMin, out xMax, out yMin, out yMax, true, false, ctls[c].GraphPane); ctls[controlindex].GraphPane.Legend.IsVisible = false; ctls[controlindex].GraphPane.XAxis.Title.Text = "Freq Hz"; ctls[controlindex].GraphPane.YAxis.Title.Text = "Amplitude"; ctls[controlindex].GraphPane.Title.Text = "FFT " + datashead[controlindex] + " - " + Path.GetFileName(ofd.FileName) + " - " + samplerate + "hz input"; ctls[controlindex].GraphPane.CurveList.Clear(); ctls[controlindex].GraphPane.CurveList.Add(curve); ctls[controlindex].Invalidate(); ctls[controlindex].AxisChange(); ctls[controlindex].Refresh(); controlindex++; } } }
/// <summary> /// Add a curve (<see cref="CurveItem"/> object) to the plot with /// the given data points (<see cref="IPointList"/>) and properties. /// This is simplified way to add curves without knowledge of the /// <see cref="CurveList"/> class. An alternative is to use /// the <see cref="ZedGraph.CurveList" /> Add() method. /// </summary> /// <param name="label">The text label (string) for the curve that will be /// used as a <see cref="Legend"/> entry.</param> /// <param name="points">A <see cref="IPointList"/> of double precision value pairs that define /// the X and Y values for this curve</param> /// <param name="color">The color to used for the curve line, /// symbols, etc.</param> /// <param name="symbolType">A symbol type (<see cref="SymbolType"/>) /// that will be used for this curve.</param> /// <returns>A <see cref="CurveItem"/> class for the newly created curve. /// This can then be used to access all of the curve properties that /// are not defined as arguments to the /// <see cref="AddCurve(string,IPointList,Color,SymbolType)"/> method.</returns> public LineItem AddCurve( string label, IPointList points, Color color, SymbolType symbolType ) { LineItem curve = new LineItem( label, points, color, symbolType ); _curveList.Add( curve ); return curve; }
/// <summary> /// Forces a update of the scatter plot. /// </summary> /// public void UpdateGraph() { zedGraphControl.GraphPane.Title.Text = scatterplot.Title; zedGraphControl.GraphPane.XAxis.Title.Text = Scatterplot.XAxisTitle; zedGraphControl.GraphPane.YAxis.Title.Text = Scatterplot.YAxisTitle; classes.Clear(); if (scatterplot.Classes != null) { if (scatterplot.Classes.Count == 0) { zedGraphControl.GraphPane.Legend.IsVisible = false; // Create space for unlabelled data PointPairList list = new PointPairList(scatterplot.XAxis, scatterplot.YAxis); LineItem item = new LineItem(String.Empty, list, Color.Black, SymbolType.Default); item.Line.IsVisible = LinesVisible; item.Symbol.Border.IsVisible = false; item.Symbol.Fill = new Fill(Color.Black); if (SymbolSize == 0) item.Symbol.IsVisible = false; else item.Symbol.Size = SymbolSize; classes.Add(item); } else { zedGraphControl.GraphPane.Legend.IsVisible = true; var colors = new ColorSequenceCollection(scatterplot.Classes.Count); // Create a curve item for each of the labels for (int i = 0; i < scatterplot.Classes.Count; i++) { // retrieve the x,y pairs for the label double[] x = scatterplot.Classes[i].XAxis; double[] y = scatterplot.Classes[i].YAxis; PointPairList list = new PointPairList(x, y); LineItem item = new LineItem(scatterplot.Classes[i].Text, list, colors[i], SymbolType.Default); item.Line.IsVisible = LinesVisible; item.Symbol.Border.IsVisible = false; item.Symbol.Fill = new Fill(colors[i]); if (SymbolSize == 0) item.Symbol.IsVisible = false; else item.Symbol.Size = SymbolSize; classes.Add(item); } } zedGraphControl.AxisChange(); zedGraphControl.Invalidate(); if (!ScaleTight) zedGraphControl.ZoomPane(zedGraphControl.GraphPane, 1.1, PointF.Empty, false); else zedGraphControl.RestoreScale(zedGraphControl.GraphPane); } }
/// <summary> /// The Copy Constructor /// </summary> /// <param name="rhs">The <see cref="LineItem"/> object from which to copy</param> public LineItem(LineItem rhs) : base(rhs) { symbol = new Symbol(rhs.Symbol); line = new Line(rhs.Line); }
private void BUT_run_Click(object sender, EventArgs e) { Utilities.FFT2 fft = new FFT2(); using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.Filter = "*.wav|*.wav"; ofd.ShowDialog(); if (!File.Exists(ofd.FileName)) return; var st = File.OpenRead(ofd.FileName); int bins = 10; double[] buffer = new double[1 << bins]; int a = 0; while (st.Position < st.Length) { byte[] temp = new byte[2]; var read = st.Read(temp, 0, temp.Length); var val = (double)BitConverter.ToInt16(temp, 0); buffer[a] = val; a++; if (a == (1 << bins)) { var fftanswer = fft.rin(buffer, (uint)bins); var freqt = fft.FreqTable(buffer.Length, 1000); ZedGraph.PointPairList ppl = new ZedGraph.PointPairList(); for (int b = 0; b < fftanswer.Length; b++) { ppl.Add(freqt[b], fftanswer[b]); } double xMin, xMax, yMin, yMax; var curve = new LineItem("FFT", ppl, Color.Red, SymbolType.Diamond); curve.GetRange(out xMin, out xMax, out yMin, out yMax, true, false, zedGraphControl1.GraphPane); zedGraphControl1.GraphPane.XAxis.Title.Text = "Freq Hz"; zedGraphControl1.GraphPane.YAxis.Title.Text = "Amplitude"; zedGraphControl1.GraphPane.Title.Text = "FFT"; zedGraphControl1.GraphPane.CurveList.Clear(); zedGraphControl1.GraphPane.CurveList.Add(curve); zedGraphControl1.Invalidate(); zedGraphControl1.AxisChange(); zedGraphControl1.Refresh(); int width = Console.WindowWidth - 1; int height = Console.WindowHeight - 1; int r = 1; foreach (var ff in fftanswer) { int col = (int)((r / (double)fftanswer.Length) * width); int row = (int)((ff * 0.2) + 0.5); //Console.SetCursorPosition(col, height - row); Console.Write("*"); r++; } // 50% overlap st.Seek(-(1 << bins) / 2, SeekOrigin.Current); a = 0; buffer = new double[buffer.Length]; //Console.Clear(); } } } }
/// <summary> /// The Copy Constructor /// </summary> /// <param name="rhs">The <see cref="StickItem"/> object from which to copy</param> public StickItem(LineItem rhs) : base(rhs) { }
/// <summary> /// The Copy Constructor /// </summary> /// <param name="rhs">The <see cref="LineItem"/> object from which to copy</param> public LineItem( LineItem rhs ) : base(rhs) { symbol = new Symbol( rhs.Symbol ); line = new Line( rhs.Line ); }
public void initGui() { //the GraphPane profileLine = new PointPairList(); userClickrList = new PointPairList(); grpCurve = profileGrp.GraphPane.AddCurve("", profileLine, Color.FromArgb(0,0,0,0), SymbolType.XCross); grpCurve.Symbol.Border.Color = Color.Black; grpCurve.Line.Fill = new Fill(Color.FromArgb(100, 227, 185, 113)); profileGrp.GraphPane.Y2Axis.MajorGrid.IsZeroLine = false; userClickCurve = profileGrp.GraphPane.AddCurve("", userClickrList, Color.Blue, SymbolType.None); profileGrp.GraphPane.Legend.IsVisible = false; profileGrp.GraphPane.Title.Text = "Profiel Titel"; profileGrp.GraphPane.XAxis.Title.Text = "Afstand (m)"; profileGrp.GraphPane.YAxis.Title.Text = "Hoogte (m)"; hlabel = new TextObj() { ZOrder = ZOrder.A_InFront }; profileGrp.GraphPane.GraphObjList.Add(hlabel); symbolBtn.SelectedIndex = 0; }
void GraphFromFile(string[] _filePath, double xc = 0.0, double yc = 1.0) { double[][] x = new double[_filePath.Length][]; double[][] y = new double[_filePath.Length][]; int[] iMax = new int[_filePath.Length]; if (this.radioButton_Setting_BrightField.Checked) { this.zgc_Profile.GraphPane.YAxis.Title.Text = "Differential"; this.zgc_Profile.GraphPane.Y2Axis.Title.Text = "Intensity"; this.zgc_Profile.GraphPane.Y2Axis.IsVisible = true; } else { this.zgc_Profile.GraphPane.YAxis.Title.Text = "Intensity"; this.zgc_Profile.GraphPane.Y2Axis.IsVisible = false; } LineItem[] lineItem = new LineItem[_filePath.Length]; //Color設定 int seed=Environment.TickCount; for (int n = 0; n < _filePath.Length; n++) { //ファイル読み込み double[][] dbleData; if (ClsNk.FileIO.IsFileLocked(_filePath[n])) { MessageBox.Show(Path.GetFileNameWithoutExtension(_filePath[n]) + "\r\nはロックされています."); continue; } ClsNk.FileIO.readFile(_filePath[n], out dbleData); x[n] = new double[dbleData.GetLength(0) - 1]; y[n] = new double[dbleData.GetLength(0) - 1]; double max = 0.0; Regex r = new Regex(@"(\w+)(\d{4})(F1|F2)([XZ])([bd])"); Match m = r.Match(Path.GetFileNameWithoutExtension(_filePath[n])); for (int i = 0; i < dbleData.GetLength(0) - 1; i++) { x[n][i] = dbleData[i + 1][0]; y[n][i] = Convert.ToString(m.Groups[5]) == "b" ? dbleData[i + 1][6] : dbleData[i + 1][5]; if (max < y[n][i]) { max = y[n][i]; iMax[n] = i; } } if (this.checkBox_GraphPeakX.Checked) { double xMax = x[n][iMax[n]]; for (int i = 0; i < dbleData.GetLength(0) - 1; i++) { x[n][i] -= xMax + xc; } } if (this.checkBox_GraphPeakY.Checked) { double yMax = y[n][iMax[n]]; for (int i = 0; i < dbleData.GetLength(0) - 1; i++) { y[n][i] /= yMax * yc; } } //Color設定 Random rdm = new Random(seed++); int R = rdm.Next(256); int G = rdm.Next(256); int B = rdm.Next(256); lineItem[n] = this.zgc_Profile.GraphPane.AddCurve(System.IO.Path.GetFileNameWithoutExtension(_filePath[n]) + ":" + this.zgc_Profile.GraphPane.YAxis.Title.Text, x[n], y[n], Color.FromArgb(R,G,B), SymbolType.None); } }
/// <summary> /// Calculates and draws the four lines on the graph /// </summary> public void DrawGraph() { /// this code has the possibility to draw ZedGraph /// has worked for many people online, the problem is getting graphControl to take a child //WindowsFormsHost host = new WindowsFormsHost(); //ZedGraph.ZedGraphControl graph = new ZedGraphControl(); //graph.IsEnableZoom = false; //host.Child = graph; //graphControl.Children.Add(host); //this.Width = graph.Width + 2 * 20; //this.Height = graph.Height + 3 * 20; externPopSettings = App.externPopForm; ExternPopForm EPS = externPopSettings; myPane.CurveList.Clear(); //TODO: Lines drawn simultaneously ZedGraph.LineItem myCurve = myPane.AddCurve("1", new ZedGraph.PointPairList(), Color.Red, ZedGraph.SymbolType.None); ZedGraph.LineItem myCurve2 = myPane.AddCurve("2", new ZedGraph.PointPairList(), Color.Blue, ZedGraph.SymbolType.None); ZedGraph.LineItem myCurve3 = myPane.AddCurve("3", new ZedGraph.PointPairList(), Color.LimeGreen, ZedGraph.SymbolType.None); ZedGraph.LineItem myCurve4 = myPane.AddCurve("4", new ZedGraph.PointPairList(), Color.Black, ZedGraph.SymbolType.None); double p = 0; double q = 0; double AA = 0; double Aa = 0; double aa = 0; int AAcount = 0; int Aacount = 0; int aacount = 0; int AAnext = 0; int Aanext = 0; int aanext = 0; int psize = 0; int times = 1; p = mutationModifier(initAlleleFrequency.Value); q = 1 - p; AA = Math.Pow(p, 2) * popSize.Value * fitnessAA.Value; Aa = 2 * p * q * popSize.Value * fitnessAa.Value; aa = Math.Pow(q, 2) * popSize.Value * fitnessaa.Value; //Console.WriteLine(((Math.Pow(p,2))+(Math.Pow(q,2))+(2*p*q)).ToString()); /*Console.WriteLine((Math.Pow(q,2)).ToString()); * Console.WriteLine((2*p*q).ToString());*/ AAcount = (int)Math.Round(AA); Aacount = (int)Math.Round(Aa); aacount = (int)Math.Round(aa); myPane.CurveList[0].Points.Add(0, p); myPane.CurveList[1].Points.Add(0, p); myPane.CurveList[2].Points.Add(0, p); myPane.CurveList[3].Points.Add(0, p); ///This while loop runs once for each line /// in order to calculate a line point by point to allow simultaneous line drawing /// this loop needs to do all 4 lines at once, not 1 after the other while (times < 5) { p = mutationModifier(initAlleleFrequency.Value); q = 1 - p; AA = Math.Pow(p, 2) * popSize.Value * fitnessAA.Value; Aa = 2 * p * q * popSize.Value * fitnessAa.Value; aa = Math.Pow(q, 2) * popSize.Value * fitnessaa.Value; AAcount = (int)Math.Round(AA); Aacount = (int)Math.Round(Aa); aacount = (int)Math.Round(aa); for (int i = 1; i < generation.Value; i++) { psize = AAcount + Aacount + aacount; AAnext = 0; Aanext = 0; aanext = 0; #region Generate New Population for (int k = 0; k < this.popSize.Value; k++) { int r = rand.Next(psize); allele first; allele second; if (r < AAcount) { first = allele.AA; } else if (AAcount <= r && r < AAcount + Aacount) { first = allele.Aa; } else { first = allele.aa; } r = rand.Next(psize); if (0 <= r && r < AAcount) { second = allele.AA; } else if (AAcount <= r && r < AAcount + Aacount) { second = allele.Aa; } else { second = allele.aa; } if (first == allele.AA) { switch (second) { case allele.AA: AAnext++; break; case allele.Aa: if (rand.Next(2) == 0) { AAnext++; } else { Aanext++; } break; case allele.aa: Aanext++; break; } } else if (first == allele.Aa) { switch (second) { case allele.AA: if (rand.Next(2) == 0) { AAnext++; } else { Aanext++; } break; case allele.Aa: switch (rand.Next(4)) { case 0: AAnext++; break; case 1: aanext++; break; default: Aanext++; break; } break; case allele.aa: if (rand.Next(2) == 0) { Aanext++; } else { aanext++; } break; } } else { switch (second) { case allele.AA: Aanext++; break; case allele.Aa: if (rand.Next(2) == 0) { aanext++; } else { Aanext++; } break; case allele.aa: aanext++; break; } } } #endregion if (EPS.enabled && (i >= EPS.ExposureBegin.Value) && (i <= (EPS.ExposureBegin.Value + EPS.ExposureDuration.Value)) && (randnum.NextDouble() < EPS.ExposureChance.Value)) { double tot = EPS.AADistribution.Value + EPS.AaDistribution.Value + EPS.aaDistribution.Value; double ExternAA = (EPS.AADistribution.Value / tot); double ExternAa = (EPS.AaDistribution.Value / tot); double Externaa = (EPS.aaDistribution.Value / tot); int totnext = AAnext + Aanext + aanext; int totAA = (int)(ExternAA * totnext * EPS.MigrationSize.Value + (AAnext) * (1 - EPS.MigrationSize.Value)); int totAa = (int)(ExternAa * totnext * EPS.MigrationSize.Value + (Aanext) * (1 - EPS.MigrationSize.Value)); int totaa = (int)(Externaa * totnext * EPS.MigrationSize.Value + (aanext) * (1 - EPS.MigrationSize.Value)); int skewedtot = totAA + totAa + totaa; if (skewedtot < totnext) { totAa += (totnext - skewedtot); } AAnext = totAA; Aanext = totAa; aanext = totaa; } if (AAnext + Aanext + aanext != popSize.Value) { throw new Exception("You calculated wrong, stupid."); } p = (2 * AAnext + Aanext) / (2 * popSize.Value); //adds the point to the list of points to be drawn? myPane.CurveList[times - 1].Points.Add(i, p); p = mutationModifier(p); q = 1 - p; AA = Math.Pow(p, 2) * popSize.Value * fitnessAA.Value; Aa = 2 * p * q * popSize.Value * fitnessAa.Value; aa = Math.Pow(q, 2) * popSize.Value * fitnessaa.Value; AAcount = (int)Math.Round(AA); Aacount = (int)Math.Round(Aa); aacount = (int)Math.Round(aa); } // draw the graph, line-by-line (will redraw 4 times) //myPane.Draw(g.CreateGraphics()); times++; } //draw the graph, all lines together myPane.Draw(graphics); }