public void plotBox(int colorIndex) { GraphPane myPane = zedGraphControl1.GraphPane; int index = 0; foreach (SummaryData summary in m_data.SummaryData) { //Plot the items, first the median values CurveItem meadian = myPane.AddCurve("", masterList[index][0], Color.Black, SymbolType.HDash); LineItem myLine = (LineItem)meadian; myLine.Line.IsVisible = false; myLine.Symbol.Size = 25; myLine.Symbol.Fill.Type = FillType.Solid; //Box HiLowBarItem myCurve = myPane.AddHiLowBar(summary.SeriesName, masterList[index][1], GetNextColor()); myCurve.Bar.Fill.Type = FillType.Solid; //Wiskers ErrorBarItem myerror = myPane.AddErrorBar("", masterList[index][2], Color.Black); //Outliers CurveItem upper = myPane.AddCurve("", masterList[index][3], Color.Black, SymbolType.Circle); LineItem bLine = (LineItem)upper; bLine.Symbol.Size = 3; bLine.Line.IsVisible = false; index++; } }
public HiLowBarDemo() : base("A demo demonstrating HiLow Bars.\n" + "These are bars in which the top and the bottom of the bar is defined with user data", "Hi-Low Bar", DemoType.Bar) { GraphPane myPane = base.GraphPane; // Set the title and axis labels myPane.Title.Text = "Hi-Low Bar Graph Demo"; myPane.XAxis.Title.Text = "Event"; myPane.YAxis.Title.Text = "Range of Values"; // Make up some data points based on the Sine function PointPairList list = new PointPairList(); for (int i = 1; i < 45; i++) { double y = Math.Sin((double)i * Math.PI / 15.0); double yBase = y - 0.4; list.Add((double)i, y, yBase); } // Generate a red bar with "Curve 1" in the legend HiLowBarItem myCurve = myPane.AddHiLowBar("Curve 1", list, Color.Red); // Fill the bar with a red-white-red gradient for a 3d look myCurve.Bar.Fill = new Fill(Color.Red, Color.White, Color.Red, 0); // Make the bar width based on the available space, rather than a size in points // myCurve.Bar.IsAutoSize = true; // Fill the axis background with a color gradient myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 45.0F); base.ZedGraphControl.AxisChange(); }
/// <summary> /// a hacked mess to show box-wisker plot for outlier manipulation /// </summary> /// <param name="iv">double array of independent variable values</param> /// <param name="tags">string array of what should be date/time tags</param> /// <returns>a graph pane to display in the master</returns> private GraphPane addPlotBW(double[] iv, string[] tags) { //http://www.sharpstatistics.co.uk/index.php?option=com_content&view=article&id=12&Itemid=13 //and hacked by mog 4/1/11 //For each set of data for the boxplot calculate the median and the inter quartile (IQR) range //which is just the value of the 75th percentile minus the 25th percentile. The median is where //the horizontal bar goes. Using the 25th and 75th percentile a HiLowBarIten can be set which is //just a bar where the top and base are specified. //An error bar that has upper and lower values of the 25th percentile minus 1.5 times the IQR and //the 75th percentile plus 1.5 times the IQR is set to give the whiskers. As with the HiLowItem //barList is a PointPairList with the high and low values. //All that is left to do is add any points that are above or below the end of the whiskers. SortedList <string, double> datevalue = getlist(tags, iv); GraphPane gp = new GraphPane(); // "Median designated within box.\n" + // "Whiskers are +- 1.5 * IQR (IQR = 75th percentile - 25th percentile)\n" + // "Points above/below whiskers are designated as outliers."; //median of each array PointPairList medians = new PointPairList(); //75th and 25th percentile, defines the box PointPairList hiLowList = new PointPairList(); //+/- 1.5*Interquartile range, extentent of wiskers PointPairList barList = new PointPairList(); //outliers PointPairList outs = new PointPairList(); //Add the values DescriptiveStats ds = new DescriptiveStats(); ds.getStats(iv); double median = ds.Median; medians.Add(0, median); double hivalue = percentile(iv, 75); double lovalue = percentile(iv, 25); hiLowList.Add(0, hivalue, lovalue); double iqr = 1.5 * (hivalue - lovalue); double upperLimit = hivalue + iqr; double lowerLimit = lovalue - iqr; //The wiskers must end on an actual data point double wiskerlo = ValueNearestButGreater(iv, lowerLimit); double wiskerhi = ValueNearestButLess(iv, upperLimit); barList.Add(0, wiskerlo, wiskerhi); var upperouts = (from kv in datevalue where kv.Value > upperLimit select kv); foreach (var v in upperouts) { outs.Add(0, v.Value, v.Key); } var lowerouts = (from kv in datevalue where kv.Value < lowerLimit select kv); foreach (var v in lowerouts) { outs.Add(0, v.Value, v.Key); } //Plot the items, first the median values CurveItem meadian = gp.AddCurve("", medians, Color.Black, SymbolType.HDash); LineItem myLine = (LineItem)meadian; myLine.Line.IsVisible = false; myLine.Symbol.Fill.Type = FillType.Solid; //Box HiLowBarItem myCurve = gp.AddHiLowBar("", hiLowList, Color.Black); myCurve.Bar.Fill.Type = FillType.None; //Wiskers ErrorBarItem myerror = gp.AddErrorBar("", barList, Color.Black); //Outliers CurveItem upper = gp.AddCurve(_dt.Columns[intSelectedcol].ColumnName + " outliers", outs, Color.Green, SymbolType.Circle); LineItem bLine = (LineItem)upper; bLine.Line.IsVisible = false; gp.YAxis.Title.Text = _dt.Columns[intSelectedcol].ColumnName; gp.BarSettings.Type = BarType.Overlay; gp.XAxis.IsVisible = false; gp.Legend.IsVisible = true; gp.Tag = "BWPlot"; gp.Title.Text = "BoxWhisker Plot"; return(gp); }
/// <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(); }
//IN PROGRESS #region ANNOTATION GRAPH private void CreateDiaryGraph(GraphPane gp, string filepath, string dirpath_colors, string title, int yoffset, string type) { gp.BarSettings.Base = BarBase.Y; gp.BarSettings.ClusterScaleWidth = 200.0; gp.BarSettings.Type = BarType.Overlay; PointPairList labelList = new PointPairList(); if (filepath.Contains(".csv")) { string[] values = FileReadWrite.ReadLinesFromFile(filepath); for (int i = 1; i < values.Length; i++) { try { string[] split = values[i].Split(','); DateTime dtStart = DateTime.MinValue; DateTime dtEnd = DateTime.MaxValue; double startx = 0; double endx = 0; if (split.Length > 0 && split[0].Length > 0) { dtStart = DateTimeParse(split[0]); startx = (double)new XDate(dtStart); } if (split.Length > 1 && split[1].Length > 0) { dtEnd = DateTimeParse(split[1]); endx = (double)new XDate(dtEnd); } Color color = Color.White; bool isSolid = false; string clabel = ""; if (startx >= startX && endx >= endX) { if (split.Length > 2 && split[2].Length > 0) { clabel = split[2]; if (!DataViewForm.annotationColorMap.ContainsKey(clabel)) { DataViewForm.annotationColorMap.Add(clabel, DataViewForm._annotationColorPalette[DataViewForm.annotationColorMap.Count]); } color = DataViewForm.annotationColorMap[clabel]; isSolid = true; labelList = new PointPairList(); labelList.Add(endx, yoffset, startx, String.Format("{3}: {0} - {1}\n {2}", dtStart.ToLongTimeString(), dtEnd.ToLongTimeString(), clabel, title)); HiLowBarItem myBar = gp.AddHiLowBar(title, labelList, color); myBar.Bar.Border.IsVisible = false; if (isSolid) { myBar.Bar.Fill.Type = FillType.Solid; } else { myBar.Bar.Fill.Type = FillType.None; } } } } catch { } } } else if (filepath.Contains(".xml")) { XmlDocument doc = new XmlDocument(); doc.Load(filepath); XmlNodeList nodes = doc.GetElementsByTagName("ANNOTATION"); foreach (XmlNode xn in nodes) { try { DateTime dtStart = DateTimeParse(xn["START_DT"].InnerText); DateTime dtEnd = DateTimeParse(xn["STOP_DT"].InnerText); double startx = (double)new XDate(dtStart); double endx = (double)new XDate(dtEnd); Color color = Color.White; bool isSolid = false; string clabel = xn["LABEL"].InnerText; if (startx >= (double)startX && endx >= (double)endX) { if (!DataViewForm.annotationColorMap.ContainsKey(clabel)) { DataViewForm.annotationColorMap.Add(clabel, DataViewForm._annotationColorPalette[DataViewForm.annotationColorMap.Count]); } color = DataViewForm.annotationColorMap[clabel]; isSolid = true; labelList = new PointPairList(); labelList.Add(endx, yoffset, startx, String.Format("{3}: {0} - {1}\n {2}", dtStart.ToLongTimeString(), dtEnd.ToLongTimeString(), clabel, title)); HiLowBarItem myBar = gp.AddHiLowBar(title, labelList, color); myBar.Bar.Border.IsVisible = false; if (isSolid) { myBar.Bar.Fill.Type = FillType.Solid; } else { myBar.Bar.Fill.Type = FillType.None; } } } catch { } } } }
private void DrawCurveGraph() { GraphPane myPane = zedGraphControl1.GraphPane; myPane.CurveList.Clear(); myPane.GraphObjList.Clear(); zedGraphControl1.RestoreScale(zedGraphControl1.GraphPane); m_dBaseAlt = System.Convert.ToDouble(textBoxBaseAlt.Text); myPane.Legend.IsVisible = false; PointPairList listHLAbove = new PointPairList(); PointPairList listAbove = new PointPairList(); PointPairList listHLBelow = new PointPairList(); PointPairList listBelow = new PointPairList(); PointPairList listEqual = new PointPairList(); PointPairList listBase = new PointPairList(); ArrayList arryHLAbove = new ArrayList(); ArrayList arryHLBelow = new ArrayList(); ArrayList arryAbove = new ArrayList(); ArrayList arryBelow = new ArrayList(); int nPointCount = m_pnt3ds.Count; double dOneSegLen = m_dXTotalLength / (nPointCount - 1); int nSegmentType = -1; //0=m_dBaseAlt,1=above,2=below for (int i = 0; i < m_pnt3ds.Count; i++) { double x = i * dOneSegLen; double y = (int)(Math.Round(m_pnt3ds[i].Z * 100)) / 100.0; // 精确到厘米就行了 if (y > m_dBaseAlt) { // 如果当前段是基准线下面的段 if (nSegmentType == 2) { arryHLBelow.Add(listHLBelow); arryBelow.Add(listBelow); listHLBelow = new PointPairList(); listBelow = new PointPairList(); } nSegmentType = 1; listAbove.Add(x, y); listHLAbove.Add(x, y, m_dBaseAlt); } else if (y < m_dBaseAlt) { if (nSegmentType == 1) { arryHLAbove.Add(listHLAbove); arryAbove.Add(listAbove); listHLAbove = new PointPairList(); listAbove = new PointPairList(); } nSegmentType = 2; listBelow.Add(x, y); listHLBelow.Add(x, m_dBaseAlt, y); } else { if (nSegmentType == 2) { arryHLBelow.Add(listHLBelow); arryBelow.Add(listBelow); listHLBelow = new PointPairList(); listBelow = new PointPairList(); } else if (nSegmentType == 1) { arryHLAbove.Add(listHLAbove); arryAbove.Add(listAbove); listHLAbove = new PointPairList(); listAbove = new PointPairList(); } nSegmentType = 0; listEqual.Add(x, y, m_dBaseAlt); } } if (nSegmentType == 2) { arryHLBelow.Add(listHLBelow); arryBelow.Add(listBelow); } else if (nSegmentType == 1) { arryHLAbove.Add(listHLAbove); arryAbove.Add(listAbove); } listBase.Add(0, m_dBaseAlt); listBase.Add(m_dXTotalLength, m_dBaseAlt); LineItem myCurveBase = myPane.AddCurve("基线剖面", listBase, Color.Blue, SymbolType.None); myCurveBase.Line.IsAntiAlias = true; myCurveBase.Line.Width = 2; int k = 0; for (k = 0; k < arryHLAbove.Count; k++) { LineItem myCurveAbove = myPane.AddCurve("高于基线剖面", (PointPairList)arryAbove[k], Color.Red, SymbolType.None); myCurveAbove.Line.IsAntiAlias = true; myCurveAbove.Line.Width = 2; myCurveAbove.Line.IsSmooth = true; HiLowBarItem hlAboveItem = myPane.AddHiLowBar("高于基线", (PointPairList)arryHLAbove[k], Color.Red); hlAboveItem.Bar.Border.Color = Color.Red; } for (k = 0; k < arryHLBelow.Count; k++) { LineItem myCurveBelow = myPane.AddCurve("低于基线剖面", (PointPairList)arryBelow[k], Color.Green, SymbolType.None); myCurveBelow.Line.IsAntiAlias = true; myCurveBelow.Line.Width = 2; myCurveBelow.Line.IsSmooth = true; HiLowBarItem hlBolowItem = myPane.AddHiLowBar("低于基线", (PointPairList)arryHLBelow[k], Color.Green); hlBolowItem.Bar.Border.Color = Color.Green; } /* * * LineItem myCurveAbove = myPane.AddCurve("高于基线剖面", listAbove, Color.Red, SymbolType.None); * //myCurve.Symbol.Fill = new Fill(Color.White); * myCurveAbove.Line.IsAntiAlias = true; * myCurveAbove.Line.Width = 2; * myCurveAbove.Line.IsSmooth = true; * * * * * // myCurveAbove.Line.Fill = new Fill(Color.Yellow, Color.LightGray, 45.0f); * * * LineItem myCurveBelow = myPane.AddCurve("低于基线剖面", listBelow, Color.Blue, SymbolType.None); * //myCurve.Symbol.Fill = new Fill(Color.White); * myCurveBelow.Line.IsAntiAlias = true; * myCurveBelow.Line.Width = 2; * myCurveBelow.Line.IsSmooth = true; * * * //myCurveBelow.Line.Fill = new Fill(Color.Yellow, Color.LightGray, 45.0f); * * * LineItem myCurveEqual = myPane.AddCurve("等于基线剖面", listEqual, Color.DarkOrange, SymbolType.None); * //myCurve.Symbol.Fill = new Fill(Color.White); * myCurveEqual.Line.IsAntiAlias = true; * myCurveEqual.Line.Width = 2; * //myCurveEqual.Line.Fill = new Fill(Color.Yellow, Color.LightGray, 45.0f); * * * // LineItem myCurveBase = myPane.AddCurve("基线剖面", listBase, Color.Green, SymbolType.None); * //myCurveBase.Line.IsAntiAlias = true; * //myCurveBase.Line.Width = 2; * */ // Show the x axis grid myPane.XAxis.MajorGrid.IsVisible = true; myPane.XAxis.IsAxisSegmentVisible = true; if (m_bSetMinX) { myPane.XAxis.Scale.Min = 0; } if (m_bSetMinY) { myPane.YAxis.Scale.Min = m_pntMin.Z; } //myPane.XAxis.Scale.Min = 0; myPane.YAxis.MajorGrid.IsVisible = true; // 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 = -1000; // myPane.YAxis.Scale.Max = 1000; // Fill the axis background with a gradient myPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0f); // Enable scrollbars if needed //zedGraphControl1.IsShowHScrollBar = true; //zedGraphControl1.IsShowVScrollBar = true; zedGraphControl1.IsAutoScrollRange = true; // OPTIONAL: Show tooltips when the mouse hovers over a point zedGraphControl1.IsShowPointValues = true; zedGraphControl1.PointValueEvent += new ZedGraphControl.PointValueHandler(MyPointValueHandler); // OPTIONAL: Handle the Zoom Event zedGraphControl1.ZoomEvent += new ZedGraphControl.ZoomEventHandler(MyZoomEvent); zedGraphControl1.AxisChange(); if (m_bXYSameScale) { graphPane_AxisChangeEvent(); } // Make sure the Graph gets redrawn zedGraphControl1.Invalidate(); }
/// <summary> /// Add a hi-low bar type 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="ZeeGraph.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 Trio's that define /// the X, Y, and lower dependent values for this curve</param> /// <param name="color">The color to used to fill the bars</param> /// <returns>A <see cref="HiLowBarItem"/> class for the newly created bar curve. /// This can then be used to access all of the curve properties that /// are not defined as arguments to the /// <see cref="AddHiLowBar(string,IPointList,Color)"/> method.</returns> public HiLowBarItem AddHiLowBar( string label, IPointList points, Color color ) { HiLowBarItem curve = new HiLowBarItem( label, points, color ); _curveList.Add( curve ); return curve; }
/// <summary> /// Add a "High-Low" bar type curve (<see cref="HiLowBarItem"/> 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="ZeeGraph.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="baseVal">An array of double precision values that define the /// base value (the bottom) of the bars for this curve. /// </param> /// <param name="color">The color to used for the bars</param> /// <returns>A <see cref="HiLowBarItem"/> class for the newly created bar curve. /// This can then be used to access all of the curve properties that /// are not defined as arguments to the /// <see cref="AddHiLowBar(string,double[],double[],double[],Color)"/> method.</returns> public HiLowBarItem AddHiLowBar( string label, double[] x, double[] y, double[] baseVal, Color color ) { HiLowBarItem curve = new HiLowBarItem( label, x, y, baseVal, color ); _curveList.Add( curve ); return curve; }
/// <summary> /// Copy the properties of this <see cref="ZedGraphWebHiLowBarItem"/> to the specified /// <see cref="ZedGraph.HiLowBarItem"/> object. /// </summary> /// <param name="item">The destination <see cref="ZedGraph.HiLowBarItem"/> object</param> internal void CopyTo( HiLowBarItem item ) { base.CopyTo( item ); }