public void CreatePlot(InteractivePlotSurface2D plotSurface) { // first of all, generate some mockup data. DataTable info = new DataTable("Store Information"); info.Columns.Add("Index", typeof(int)); info.Columns.Add("IndexOffsetLeft", typeof(float)); info.Columns.Add("IndexOffsetRight", typeof(float)); info.Columns.Add("StoreName", typeof(string)); info.Columns.Add("BarBase", typeof(float)); info.Columns.Add("StoreGrowth", typeof(float)); info.Columns.Add("AverageGrowth", typeof(float)); info.Columns.Add("ProjectedSales", typeof(float)); float barBase = 185.0f; Random r = new Random(); for (int i = 0; i < 18; ++i) { DataRow row = info.NewRow(); row["Index"] = i; row["IndexOffsetLeft"] = (float)i - 0.1f; row["IndexOffsetRight"] = (float)i + 0.1f; row["StoreName"] = "Store " + (i + 1).ToString(); row["BarBase"] = barBase; row["StoreGrowth"] = barBase + ((r.NextDouble() - 0.1) * 20.0f); row["AverageGrowth"] = barBase + ((r.NextDouble() - 0.1) * 15.0f); row["ProjectedSales"] = barBase + (r.NextDouble() * 15.0f); info.Rows.Add(row); barBase += (float)r.NextDouble() * 4.0f; } plotSurface.Clear(); plotSurface.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // generate the grid Grid grid = new Grid(); grid.VerticalGridType = Grid.GridType.Coarse; grid.HorizontalGridType = Grid.GridType.None; grid.MajorGridPen = new Pen(Color.Black, 1.0f); plotSurface.Add(grid); // generate the trendline LinePlot trendline = new LinePlot(); trendline.DataSource = info; trendline.AbscissaData = "Index"; trendline.OrdinateData = "BarBase"; trendline.Pen = new Pen(Color.Black, 3.0f); trendline.Label = "Trendline"; plotSurface.Add(trendline); // draw store growth bars BarPlot storeGrowth = new BarPlot(); storeGrowth.DataSource = info; storeGrowth.AbscissaData = "IndexOffsetLeft"; storeGrowth.OrdinateDataTop = "StoreGrowth"; storeGrowth.OrdinateDataBottom = "BarBase"; storeGrowth.Label = "Store Growth"; storeGrowth.FillBrush = Florence.RectangleBrushes.Solid.Black; //storeGrowth.BorderPen = new Pen( Color.Black, 2.0f ); plotSurface.Add(storeGrowth); // draw average growth bars BarPlot averageGrowth = new BarPlot(); averageGrowth.DataSource = info; averageGrowth.AbscissaData = "IndexOffsetRight"; averageGrowth.OrdinateDataBottom = "BarBase"; averageGrowth.OrdinateDataTop = "AverageGrowth"; averageGrowth.Label = "Average Growth"; averageGrowth.FillBrush = Florence.RectangleBrushes.Solid.Gray; //averageGrowth.BorderPen = new Pen( Color.Black, 2.0f ); plotSurface.Add(averageGrowth); // generate the projected sales step line. StepPlot projected = new StepPlot(); projected.DataSource = info; projected.AbscissaData = "Index"; projected.OrdinateData = "ProjectedSales"; projected.Pen = new Pen(Color.Orange, 3.0f); projected.HideVerticalSegments = true; projected.Center = true; projected.Label = "Projected Sales"; projected.WidthScale = 0.7f; plotSurface.Add(projected); // generate the minimum target line. HorizontalLine minimumTargetLine = new HorizontalLine(218, new Pen(Color.Green, 3.5f)); minimumTargetLine.Label = "Minimum Target"; minimumTargetLine.LengthScale = 0.98f; minimumTargetLine.ShowInLegend = true; // off by default for lines. plotSurface.Add(minimumTargetLine); // generate the preferred target line. HorizontalLine preferredTargetLine = new HorizontalLine(228, new Pen(Color.Blue, 3.5f)); preferredTargetLine.Label = "Preferred Target"; preferredTargetLine.LengthScale = 0.98f; preferredTargetLine.ShowInLegend = true; // off by default for lines. plotSurface.Add(preferredTargetLine); // make some modifications so that chart matches requirements. // y axis. plotSurface.YAxis1.TicksIndependentOfPhysicalExtent = true; plotSurface.YAxis1.TickTextNextToAxis = false; plotSurface.YAxis1.TicksAngle = 3.0f * (float)Math.PI / 2.0f; ((LinearAxis)plotSurface.YAxis1).LargeTickStep = 10.0; ((LinearAxis)plotSurface.YAxis1).NumberOfSmallTicks = 0; // x axis plotSurface.XAxis1.TicksIndependentOfPhysicalExtent = true; plotSurface.XAxis1.TickTextNextToAxis = false; plotSurface.XAxis1.TicksAngle = (float)Math.PI / 2.0f; LabelAxis la = new LabelAxis(plotSurface.XAxis1); for (int i = 0; i < info.Rows.Count; ++i) { la.AddLabel((string)info.Rows[i]["StoreName"], Convert.ToInt32(info.Rows[i]["Index"])); } la.TicksLabelAngle = (float)90.0f; la.TicksBetweenText = true; plotSurface.XAxis1 = la; plotSurface.XAxis2 = (Axis)plotSurface.XAxis1.Clone(); plotSurface.XAxis2.HideTickText = true; plotSurface.XAxis2.LargeTickSize = 0; Legend l = new Legend(); l.NumberItemsVertically = 2; l.AttachTo(Florence.PlotSurface2D.XAxisPosition.Bottom, Florence.PlotSurface2D.YAxisPosition.Left); l.HorizontalEdgePlacement = Florence.Legend.Placement.Outside; l.VerticalEdgePlacement = Florence.Legend.Placement.Inside; l.XOffset = 5; l.YOffset = 50; l.BorderStyle = Florence.LegendBase.BorderType.Line; plotSurface.Legend = l; plotSurface.Title = "Sales Growth Compared to\n" + "Average Sales Growth by Store Size - Rank Order Low to High"; plotSurface.Refresh(); }
public void CreatePlot(InteractivePlotSurface2D plotSurface) { plotSurface.Clear(); // clear everything. reset fonts. remove plot components etc. System.Random r = new Random(); double[] a = new double[100]; double[] b = new double[100]; double mult = 0.00001f; for (int i = 0; i < 100; ++i) { a[i] = ((double)r.Next(1000) / 5000.0f - 0.1f) * mult; if (i == 50) { b[i] = 1.0f * mult; } else { b[i] = (double)Math.Sin((((double)i - 50.0f) / 4.0f)) / (((double)i - 50.0f) / 4.0f); b[i] *= mult; } a[i] += b[i]; } Marker m = new Marker(Marker.MarkerType.Cross1, 6, new Pen(Color.Blue, 2.0F)); PointPlot pp = new PointPlot(m); pp.OrdinateData = a; pp.AbscissaData = new StartStep(-500.0, 10.0); pp.Label = "Random"; plotSurface.Add(pp); LinePlot lp = new LinePlot(); lp.OrdinateData = b; lp.AbscissaData = new StartStep(-500.0, 10.0); lp.Pen = new Pen(Color.Red, 2.0f); plotSurface.Add(lp); plotSurface.Title = "Sinc Function"; plotSurface.YAxis1.Label = "Magnitude"; plotSurface.XAxis1.Label = "Position"; Legend legend = new Legend(); legend.AttachTo(PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Left); legend.VerticalEdgePlacement = Legend.Placement.Inside; legend.HorizontalEdgePlacement = Legend.Placement.Inside; legend.YOffset = 8; plotSurface.Legend = legend; plotSurface.LegendZOrder = 1; // default zorder for adding idrawables is 0, so this puts legend on top. plotSurface.Refresh(); }
public void CreatePlot(InteractivePlotSurface2D plotSurface) { plotSurface.Clear(); double[] y = new double[1] { 1.0f }; foreach (object i in Enum.GetValues(typeof(Marker.MarkerType))) { Marker m = new Marker((Marker.MarkerType)Enum.Parse(typeof(Marker.MarkerType), i.ToString()), 8); double[] x = new double[1]; x[0] = (double)m.Type; PointPlot pp = new PointPlot(); pp.OrdinateData = y; pp.AbscissaData = x; pp.Marker = m; pp.Label = m.Type.ToString(); plotSurface.Add(pp); } plotSurface.Title = "Markers"; plotSurface.YAxis1.Label = "Index"; plotSurface.XAxis1.Label = "Marker"; plotSurface.YAxis1.WorldMin = 0.0f; plotSurface.YAxis1.WorldMax = 2.0f; plotSurface.XAxis1.WorldMin -= 1.0f; plotSurface.XAxis1.WorldMax += 1.0f; Legend legend = new Legend(); legend.AttachTo(PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Right); legend.VerticalEdgePlacement = Legend.Placement.Outside; legend.HorizontalEdgePlacement = Legend.Placement.Inside; legend.XOffset = 5; // note that these numbers can be negative. legend.YOffset = 0; plotSurface.Legend = legend; plotSurface.Refresh(); }
private void Init() { drawables_ = new ArrayList(); xAxisPositions_ = new ArrayList(); yAxisPositions_ = new ArrayList(); zPositions_ = new ArrayList(); ordering_ = new SortedList(); try { FontFamily fontFamily = new FontFamily("Arial"); TitleFont = new Font(fontFamily, 14, FontStyle.Regular, GraphicsUnit.Pixel); } catch (System.ArgumentException) { throw new FlorenceException("Error: Arial font is not installed on this system"); } padding_ = 10; title_ = ""; autoScaleTitle_ = false; autoScaleAutoGeneratedAxes_ = false; xAxis1_ = null; xAxis2_ = null; yAxis1_ = null; yAxis2_ = null; pXAxis1Cache_ = null; pYAxis1Cache_ = null; pXAxis2Cache_ = null; pYAxis2Cache_ = null; titleBrush_ = new SolidBrush( Color.Black ); plotBackColor_ = Color.White; outerBackColor = null; this.legend_ = null; smoothingMode_ = System.Drawing.Drawing2D.SmoothingMode.None; axesConstraints_ = new ArrayList(); }