예제 #1
0
        public PlotCircular()
        {
            infoText  = "";
            infoText += "Circular Example. Demonstrates - \n";
            infoText += "  * PiAxis, Horizontal and Vertical Lines. \n";
            infoText += "  * Placement of legend";

            plotSurface.Clear();
            plotSurface.Add(new HorizontalLine(0.0, Color.LightGray));
            plotSurface.Add(new VerticalLine(0.0, Color.LightGray));

            const int    N     = 400;
            const double start = -Math.PI * 7.0;
            const double end   = Math.PI * 7.0;

            double[] xs = new double[N];
            double[] ys = new double[N];

            for (int i = 0; i < N; ++i)
            {
                double t = ((double)i * (end - start) / (double)N + start);
                xs[i] = 0.5 * (t - 2.0 * Math.Sin(t));
                ys[i] = 2.0 * (1.0 - 2.0 * Math.Cos(t));
            }

            LinePlot lp = new LinePlot(ys, xs);

            lp.Pen   = new Pen(Color.DarkBlue, 2.0f);
            lp.Label = "Circular Line";             // no legend, but still useful for copy data to clipboard.
            plotSurface.Add(lp);

            plotSurface.XAxis1 = new PiAxis(plotSurface.XAxis1);

            plotSurface.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            plotSurface.Legend = new Legend();
            plotSurface.Legend.AttachTo(XAxisPosition.Bottom, YAxisPosition.Right);
            plotSurface.Legend.HorizontalEdgePlacement = Legend.Placement.Inside;
            plotSurface.Legend.VerticalEdgePlacement   = Legend.Placement.Inside;
            plotSurface.Legend.XOffset = -10;
            plotSurface.Legend.YOffset = -10;

            plotSurface.Refresh();
        }
예제 #2
0
        public static void TestDoublePlot()
        {
            // the PlotView is a WPF control that's created in the .xaml code
            OxyPlot.Wpf.PlotView examplePlotView = new OxyPlot.Wpf.PlotView();

            // just some example data to plot
            var datapoint1 = new Datum(0, 1);
            var datapoint2 = new Datum(2, 3);

            // create the plot
            LinePlot plot = new LinePlot(examplePlotView, new List <Datum> {
                datapoint1, datapoint2
            });

            var datapoint3 = new Datum(4, 5);
            var datapoint4 = new Datum(4, 6);

            plot.AddScatterPlot(new List <Datum> {
                datapoint3, datapoint4
            });

            // check to make sure the data was plotted
            // the chart should have a line plot and a scatter plot on the same chart
            Assert.That(plot.Model.Series.Count == 2);

            var lineSeries       = plot.Model.Series[0];
            var lineSeriesPoints = ((LineSeries)lineSeries).Points;

            Assert.That(lineSeriesPoints.Count == 2);
            Assert.That(lineSeriesPoints[0].X == 0);
            Assert.That(lineSeriesPoints[0].Y == 1);
            Assert.That(lineSeriesPoints[1].X == 2);
            Assert.That(lineSeriesPoints[1].Y == 3);

            var scatterSeries = plot.Model.Series[1];
            var scatterPoints = ((ScatterSeries)scatterSeries).Points;

            Assert.That(scatterPoints.Count == 2);
            Assert.That(scatterPoints[0].X == 4);
            Assert.That(scatterPoints[0].Y == 5);
            Assert.That(scatterPoints[1].X == 4);
            Assert.That(scatterPoints[1].Y == 6);
        }
예제 #3
0
        /// <summary>
        /// Might need Refresh () afterwards!
        /// </summary>
        /// <param name="table2D">
        /// A <see cref="Table2D"/>
        /// </param>
        public void Draw(Table2D table2D)
        {
            float[] valuesY = table2D.GetValuesYasFloats();

            // clear everything. reset fonts. remove plot components etc.
            this.plotSurface2D.Clear();
            plotSurface2D.Padding       = 0;
            plotSurface2D.SmoothingMode = SmoothingMode;

            // y-values, x-values (!)
            LinePlot lp = new LinePlot(valuesY, table2D.ValuesX);

            lp.Pen = pen;

            PointPlot pp = new PointPlot(marker);

            pp.AbscissaData = table2D.ValuesX;
            pp.OrdinateData = valuesY;

            Grid myGrid = new Grid();

            myGrid.VerticalGridType   = Grid.GridType.Coarse;
            myGrid.HorizontalGridType = Grid.GridType.Coarse;

            plotSurface2D.Add(myGrid);
            plotSurface2D.Add(lp);
            plotSurface2D.Add(pp);

            plotSurface2D.TitleFont = titleFont;
            plotSurface2D.Title     = table2D.Title;

            plotSurface2D.XAxis1.LabelFont = labelFont;
            plotSurface2D.XAxis1.Label     = AxisText(table2D.NameX, table2D.UnitX);
            // could use ex: plotSurface2D.YAxis1.NumberFormat = "0.000";
            plotSurface2D.XAxis1.TickTextFont = tickTextFont;

            plotSurface2D.YAxis1.LabelFont    = labelFont;
            plotSurface2D.YAxis1.Label        = AxisText(table2D.Title, table2D.UnitY);
            plotSurface2D.YAxis1.TickTextFont = tickTextFont;

            // Refresh () not part of interface!
        }
예제 #4
0
        public void CreatePlot(InteractivePlotSurface2D plotSurface)
        {
            plotSurface.Clear();

            System.Random r = new Random();

            int len = 35;

            double[] a = new double[len];
            double[] b = new double[len];

            for (int i = 0; i < len; ++i)
            {
                int j = len - 1 - i;
                a[i] = (double)Math.Exp(-(double)(i - len / 2) * (double)(i - len / 2) / 50.0f);
                b[i] = a[i] + (r.Next(10) / 50.0f) - 0.05f;
                if (b[i] < 0.0f)
                {
                    b[i] = 0;
                }
            }

            HistogramPlot sp = new HistogramPlot();

            sp.DataSource     = b;
            sp.Pen            = Pens.DarkBlue;
            sp.Filled         = true;
            sp.RectangleBrush = new RectangleBrushes.HorizontalCenterFade(Color.Lavender, Color.Gold);
            sp.BaseWidth      = 0.5f;
            sp.Label          = "Random Data";
            LinePlot lp = new LinePlot();

            lp.DataSource = a;
            lp.Pen        = new Pen(Color.Blue, 3.0f);
            lp.Label      = "Gaussian Function";
            plotSurface.Add(sp);
            plotSurface.Add(lp);
            plotSurface.Legend          = new Legend();
            plotSurface.YAxis1.WorldMin = 0.0f;
            plotSurface.Title           = "Histogram Plot";
            plotSurface.Refresh();
        }
예제 #5
0
        private void btnPlot_Click(object sender, EventArgs e)
        {
            List <ulong> keys = new List <ulong>(chkAllPoints.CheckedItems.OfType <ulong>());

            plot.Clear();

            plot.AddInteraction(new PlotSurface2D.Interactions.HorizontalDrag());
            plot.AddInteraction(new PlotSurface2D.Interactions.VerticalDrag());
            plot.AddInteraction(new PlotSurface2D.Interactions.AxisDrag(false));

            if (keys.Count == 0)
            {
                return;
            }
            SnapClient client = SnapClient.Connect(m_archiveFile.Host);
            ClientDatabaseBase <HistorianKey, HistorianValue> db = client.GetDatabase <HistorianKey, HistorianValue>("");

            Dictionary <ulong, SignalDataBase> results = db.GetSignals(0, ulong.MaxValue, keys, TypeSingle.Instance);

            foreach (ulong point in keys)
            {
                List <double>  y    = new List <double>();
                List <double>  x    = new List <double>();
                SignalDataBase data = results[point];

                for (int i = 0; i < data.Count; i++)
                {
                    data.GetData(i, out ulong time, out double value);

                    x.Add(time);
                    y.Add(value);
                }

                LinePlot lines = new LinePlot(y, x);

                plot.Add(lines);
            }

            plot.Refresh();
            db.Dispose();
            client.Dispose();
        }
예제 #6
0
        private void button10_Click(object sender, EventArgs e)
        {
            LinePlot lp2 = new LinePlot();

            int[] p2 = new int[10] {
                2, 4, 6, 8, 7, 3, 2, 1, 3, 1
            };
            int[] X = new int[10] {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            };
            lp2.OrdinateData = p2;
            lp2.AbscissaData = X;
            lp2.Pen          = new Pen(Color.Green);
            lp2.Pen.Width    = 2;
            lp2.Label        = "销售量";
            //添加到第二横纵坐标轴上
            // this.myPlot.Add(lp2, NPlot.PlotSurface2D.XAxisPosition.Top, NPlot.PlotSurface2D.YAxisPosition.Right);
            //添加到第一横纵坐标轴
            this.myPlot.Add(lp2, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left);
        }
예제 #7
0
        void lv_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                int i = lv.SelectedIndices[0];
                wb.DocumentText = arrStr[i];
                ps.Clear();
                double[] arrP, arrL;
                arrL = StatInspection.GetL(arrN[i], arrAc[i], out arrP);

                LinePlot lp = new LinePlot(arrL, arrP);
                lp.Color = Color.Red;
                ps.Add(lp);
                ps.Title        = "Оперативная характеристика (по закону Пуассона)";
                ps.XAxis1.Label = "Уровень качества, q";
                ps.YAxis1.Label = "Оперативная характеристика, L";
                ps.Refresh();
            }
            catch { }
        }
예제 #8
0
        public void Plot(Table table)
        {
            plotSurface.Clear();

            // draw a fine grid.
            Grid fineGrid = new Grid();

            fineGrid.VerticalGridType   = Grid.GridType.Fine;
            fineGrid.HorizontalGridType = Grid.GridType.Fine;
            plotSurface.Add(fineGrid);

            //plotSurface.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalGuideline());
            plotSurface.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalRangeSelection());
            plotSurface.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(true));

            plotSurface.Add(new HorizontalLine(0.0, Color.LightBlue));

            System.Double[] data = new Double[200];
            System.Double[] axis = new Double[200];

            double step = (table.GetUpperKey(1) - table.GetLowerKey(1)) / 200.0;
            int    i    = 0;

            for (double key = table.GetLowerKey(1); key <= table.GetUpperKey(1); key += step)
            {
                data[i] = table.GetValue(key);
                axis[i] = key;
                i++;
            }

            LinePlot lp = new LinePlot();

            lp.OrdinateData = data;
            lp.AbscissaData = axis;
            lp.Pen          = new Pen(Color.Red);
            plotSurface.Add(lp);

            plotSurface.YAxis1.FlipTicksLabel = true;

            plotSurface.Refresh();
        }
예제 #9
0
        LinePlot GetLine(string name)
        {
            LinePlot r;

            if (!_lines.ContainsKey(name))
            {
                var tmp = new LinePlot();
                tmp.Color        = colorSample[_lines.Count];
                tmp.Pen.Width    = 2;
                tmp.AbscissaData = new List <double>();
                tmp.OrdinateData = new List <double>();
                _lines.Add(name, tmp);
                _base.Add(tmp);
                r = tmp;
            }
            else
            {
                r = _lines[name];
            }
            return(r);
        }
예제 #10
0
        private double updateCoolingPower()
        {
            state = simulator.State;
            Cooler cooler = null;

            for (int i = 0; i < coolers.Length; i++)
            {
                if (coolers[i].Name == state.coolerName)
                {
                    cooler = coolers[i];
                    break;
                }
            }
            if (cooler == null)
            {
                string msg = string.Format("Can't find cooler \"{0}\"", state.coolerName);
                throw new Exception(msg);
            }
            double[] x   = new double[2];
            double[] y   = new double[2];
            double   max = cooler.CPM[1].data;

            x[0] = 300 - (300 - cooler.CPM[0].temp) * state.powerFactor;
            x[1] = 300;
            for (int i = 0; i < 2; i++)
            {
                y[i] = cooler.OutputPower(cooler.CPM[i].temp, state.powerFactor);
            }


            LinePlot lp = new LinePlot();

            lp.Pen          = Pens.Orange;
            lp.AbscissaData = x;
            lp.OrdinateData = y;

            plot.Add(lp, PlotSurface2D.XAxisPosition.Bottom, PlotSurface2D.YAxisPosition.Right);

            return(max);
        }
예제 #11
0
        public GraphItemAdapter(string name, Color color, double windowSize, DataItemAdapter dataItemAdapter)
        {
            // store values
            this.dataItemAdapter = dataItemAdapter;
            this.name            = name;

            // get the source units
            this.sourceUnits = UnitConverter.GetUnit(dataItemAdapter.DataItemUnits);

            // create the queues
            plotQueue = new TimeWindowQueue(windowSize);
            recvQueue = new TimeWindowQueue(windowSize);

            // create the plot object
            plot       = new LinePlot(plotQueue.ValueList, plotQueue.TimestampList);
            plot.Color = color;
            plot.Label = name;

            // subscribe to relevant events
            Services.RunControlService.RenderCycle += RunControlService_RenderCycle;
            dataItemAdapter.DataValueReceived      += dataItemAdapter_DataValueReceived;
        }
예제 #12
0
 void lbTran_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         int        index = lbTran.SelectedIndex;
         TranSample ts    = arrTranSmp[index];
         Regression reg   = arrReg[index];
         ps.Clear();
         LinePlot lp = new LinePlot();
         lp.AbscissaData = ts.CloneArray();
         lp.OrdinateData = reg.CloneArray();
         ps.Add(lp);
         PointPlot pp = new PointPlot();
         pp.AbscissaData = ts.CloneArray();
         pp.OrdinateData = smpY.CloneArray();
         ps.Add(pp);
         ps.XAxis1.Label = string.Format("{0} [{1}]", smpX.GetName(), arrTranName[index]);
         ps.YAxis1.Label = smpY.GetName();
         ps.Refresh();
     }
     catch { }
 }
예제 #13
0
        public Gdk.Pixbuf CreateIcon2D(Table2D table)
        {
            if (table.Ymin == table.Ymax)
            {
                return(GetNoDataPixBuf);
            }

            plotSurface.Clear();
            // needs to be set each time after Clear()
            plotSurface.Padding       = padding;
            plotSurface.SmoothingMode = SmoothingMode;

            float[] valuesY = table.GetValuesYasFloats();

            // y-values, x-values (!)
            LinePlot lp = new LinePlot(valuesY, table.ValuesX);

            lp.Pen = pen;

            plotSurface.Add(lp);

            plotSurface.XAxis1.Hidden = true;
            plotSurface.YAxis1.Hidden = true;

            using (System.Drawing.Graphics g = Graphics.FromImage(bitmap_cache)) {
                plotSurface.Draw(g, bounds);
            }

            if (memoryStream == null)
            {
                memoryStream = new System.IO.MemoryStream(MemoryStreamCapacity);
            }
            memoryStream.Position = 0;
            bitmap_cache.Save(memoryStream, imageFormat);
            memoryStream.Position = 0;
            // TODO create Pixbuf directly from bitmap if possible, avoiding MemoryStream
            return(new Gdk.Pixbuf(memoryStream));
        }
예제 #14
0
        private void lbFlatOrders_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = lbFlatOrders.SelectedIndex;

            if (index == -1)
            {
                return;
            }
            if (!(cbFlatOrders.Checked || cbFlatOrdersFit.Checked || cbFlatNorm.Checked))
            {
                return;
            }
            plotFlatNorm.Clear();
            if (cbFlatOrders.Checked)
            {
                LinePlot lp = new LinePlot(orders_flat.Fluxes[index], orders_flat.Pixels);
                plotFlatNorm.Add(lp);
            }
            if (cbFlatOrdersFit.Checked)
            {
                LinePlot lp = new LinePlot(orders_flat_fit.Fluxes[index], orders_flat_fit.Pixels);
                lp.Color = Color.Red;
                plotFlatNorm.Add(lp);
            }
            if (cbFlatNorm.Checked)
            {
                LinePlot lp = new LinePlot(orders_flat_norm.Fluxes[index], orders_flat_norm.Pixels);
                plotFlatNorm.Add(lp);
            }

            plotFlatNorm.XAxis1.Label = "Pixel Number";
            plotFlatNorm.YAxis1.Label = "Flux";
            plotFlatNorm.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag());
            plotFlatNorm.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalDrag());
            plotFlatNorm.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(true));
            //plotFlatNorm.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.RubberBandSelection());
            plotFlatNorm.Refresh();
        }
예제 #15
0
        void Refresh(object sender, EventArgs e)
        {
            _plotSurface.Clear();
            _plotSurface.BackColor = Color.Black;

            if (!_component.ComputeProfile())
            {
                _plotSurface.Refresh();
                return;
            }

            LinePlot linePlot = new LinePlot();

            linePlot.AbscissaData = _component.PixelIndices;
            linePlot.OrdinateData = _component.PixelValues;
            linePlot.Pen          = new Pen(ClearCanvasStyle.ClearCanvasBlue);

            _plotSurface.Add(linePlot);
            _plotSurface.PlotBackColor = Color.Black;
            _plotSurface.XAxis1.Color  = Color.White;
            _plotSurface.YAxis1.Color  = Color.White;
            _plotSurface.Refresh();
        }
예제 #16
0
        private void Refresh(object sender, EventArgs e)
        {
            _plotSurface.Clear();
            _plotSurface.BackColor = Color.Black;

            if (!_component.ComputeProfile())
            {
                _plotSurface.Refresh();
                return;
            }

            LinePlot linePlot = new LinePlot();

            linePlot.AbscissaData = _component.PixelIndices;
            linePlot.OrdinateData = _component.PixelValues;
            linePlot.Pen          = new Pen(Application.CurrentUITheme.Colors.StandardColorBase);

            _plotSurface.Add(linePlot);
            _plotSurface.PlotBackColor = Color.Black;
            _plotSurface.XAxis1.Color  = Color.White;
            _plotSurface.YAxis1.Color  = Color.White;
            _plotSurface.Refresh();
        }
예제 #17
0
        public static void TestEmptyDataCharts()
        {
            // the PlotView is a WPF control that's created in the .xaml code
            OxyPlot.Wpf.PlotView examplePlotView = new OxyPlot.Wpf.PlotView();

            List <Datum> data = new List <Datum>();

            Plot plot = new ScatterPlot(examplePlotView, data);

            Assert.That(plot.Model.Series.Count == 0);

            plot = new LinePlot(examplePlotView, data);
            Assert.That(plot.Model.Series.Count == 0);

            plot = new BarPlot(examplePlotView, data);
            Assert.That(plot.Model.Series.Count == 0);

            plot = new HistogramPlot(examplePlotView, data, 10);
            Assert.That(plot.Model.Series.Count == 0);

            plot = new SpectrumPlot(examplePlotView, data);
            Assert.That(plot.Model.Series.Count == 0);
        }
예제 #18
0
        public void RefreshSpeed()
        {
            List <double> xVal = new List <double>();
            List <double> yVal = new List <double>();

            for (int x = 0; x < 100000; x++)
            {
                xVal.Add(x);
                yVal.Add(1 - x);
            }
            Stopwatch sw  = new Stopwatch();
            Stopwatch sw2 = new Stopwatch();
            LinePlot  p1  = new LinePlot(yVal, xVal);

            PlotSurface2D plot = new PlotSurface2D(640, 480);

            sw.Start();

            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);

            sw2.Start();
            plot.Refresh();
            sw2.Stop();
            sw.Stop();

            Console.WriteLine(sw2.Elapsed.TotalSeconds.ToString() + " seconds to refresh");
            Console.WriteLine(sw.Elapsed.TotalSeconds.ToString() + " seconds To add and refresh");
        }
        protected NPlot.Windows.PlotSurface2D CreateDefaultPlot()
        {
            NPlot.Windows.PlotSurface2D plotSurface2D = new NPlot.Windows.PlotSurface2D();
            plotSurface2D.Clear();
            plotSurface2D.Add(new Grid
            {
                VerticalGridType   = Grid.GridType.Fine,
                HorizontalGridType = Grid.GridType.Fine
            });
            plotSurface2D.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalGuideline());
            LinePlot linePlot = new LinePlot();

            linePlot.Color = Color.Green;
            plotSurface2D.Add(linePlot);
            DateTimeAxis xaxis = new DateTimeAxis(plotSurface2D.XAxis1);

            plotSurface2D.XAxis1 = xaxis;
            plotSurface2D.XAxis1.SmallTickSize = 0;
            plotSurface2D.XAxis1.LargeTickSize = 0;
            plotSurface2D.XAxis1.WorldMin      = (double)DateTime.Now.Ticks;
            plotSurface2D.XAxis1.WorldMax      = (double)(DateTime.Now.Ticks + 108000000000L);
            LinearAxis yaxis = new LinearAxis(plotSurface2D.YAxis1);

            plotSurface2D.YAxis1               = yaxis;
            plotSurface2D.YAxis1.WorldMin      = 0.0;
            plotSurface2D.YAxis1.WorldMax      = 10000.0;
            plotSurface2D.YAxis1.SmallTickSize = 0;
            plotSurface2D.YAxis1.LargeTickSize = 0;
            plotSurface2D.YAxis1.NumberFormat  = "{0}";
            plotSurface2D.PlotBackColor        = Color.OldLace;
            plotSurface2D.SmoothingMode        = SmoothingMode.AntiAlias;
            plotSurface2D.DateTimeToolTip      = true;
            plotSurface2D.Remove(linePlot, false);
            plotSurface2D.Refresh();
            return(plotSurface2D);
        }
예제 #20
0
        public override Gdk.Pixbuf CreateIcon(Tables.Denso.Table table)
        {
            var t = (Tables.Denso.Table2D)table;

            if (t.IsDataConst)
            {
                return(ConstDataIcon);
            }

            plotSurface.Clear();
            plotSurface.SmoothingMode = SmoothingMode;

            // y-values, x-values (!)
            LinePlot lp = new LinePlot(t.GetValuesYasFloats(), t.ValuesX);

            lp.Pen = pen;

            plotSurface.Add(lp);

            plotSurface.XAxis1.Hidden = true;
            plotSurface.YAxis1.Hidden = true;

            return(DrawAndConvert());
        }
예제 #21
0
파일: Form1.cs 프로젝트: arneb89/RECONS
        void lbSpecs_SelectedIndexChanged(object sender, EventArgs e)
        {
            int      n     = lbSpecs.SelectedIndex;
            LinePlot lpObs = new LinePlot();

            lpObs.AbscissaData = lambs[n];
            lpObs.OrdinateData = intes_obs[n];
            lpObs.Color        = Color.Black;
            LinePlot lpMod = new LinePlot();

            lpMod.AbscissaData = lambs[n];
            lpMod.OrdinateData = intes_mod[n];
            lpMod.Color        = Color.Red;
            LinePlot lpImm = new LinePlot();

            lpImm.AbscissaData = lambs[n];
            lpImm.OrdinateData = intes_imm[n];
            lpImm.Color        = Color.Green;
            plot.Clear();
            plot.Add(lpObs);
            plot.Add(lpMod);
            plot.Add(lpImm);
            plot.Refresh();
        }
예제 #22
0
        public PlotMockup()
        {
            infoText  = "";
            infoText += "THE TEST (can your charting library handle this?) - \n";
            infoText += "NPlot demonstrates it can handle real world charting requirements.";

            // 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 = NPlot.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 = NPlot.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; // Not required if TicksAngle bug #2000693 fixed
            ((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; // Not required if TicksAngle bug #2000693 fixed
            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(XAxisPosition.Bottom, YAxisPosition.Left);
            l.HorizontalEdgePlacement = NPlot.Legend.Placement.Outside;
            l.VerticalEdgePlacement   = NPlot.Legend.Placement.Inside;
            l.XOffset     = 5;
            l.YOffset     = 50;
            l.BorderStyle = NPlot.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();
        }
예제 #23
0
        public string RenderBitmap(string path)
        {
            path = Path.GetDirectoryName(path);

            string Filename  = string.Format("{0}-{1}.png", this.Title, this.Id.ToString());
            string ImagePath = Path.Combine(path, @"img", Filename);

            StringBuilder sb;

            if (!GetHeaderTable(out sb))//no charts? skip the rest
            {
                return(sb.ToString());
            }

            NPlot.Bitmap.PlotSurface2D npSurface;
            Font AxisFont;
            Font TickFont;

            NPlot.Grid p;
            InitPlot(out npSurface, out AxisFont, out TickFont, out p, 700, 500);

            foreach (Series s in this.Series)
            {
                if (s.Title.ToUpperInvariant() == "ERRORS")
                {
                    continue;
                }
                else
                {
                    NPlot.LinePlot npPlot = new LinePlot();
                    //Weight:
                    npPlot.AbscissaData = s.XAxis;
                    npPlot.OrdinateData = s.YAxis;
                    npPlot.Label        = s.Title;
                    npPlot.Color        = s.Color;
                    npSurface.Add(npPlot, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left);
                }
            }
            SetAxes(npSurface, AxisFont, TickFont);
            double iMin = npSurface.XAxis1.WorldMin;
            double iMax = npSurface.XAxis1.WorldMax;

            if (!Directory.Exists(Path.GetDirectoryName(ImagePath)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(ImagePath));
            }

            //Save image and add it to the report
            npSurface.Bitmap.Save(ImagePath, System.Drawing.Imaging.ImageFormat.Png);
            sb.AppendFormat("<img src=\"img/{0}\" alt=\"{1}\" />", Filename, this.Title);

            //Generate error graph if needed
            if (this.Errors > 0)
            {
                Filename  = "errors." + Filename;
                ImagePath = Path.Combine(path, "img", Filename);
                npSurface.Clear();

                InitPlot(out npSurface, out AxisFont, out TickFont, out p, 700, 300);

                foreach (Series s in this.Series)
                {
                    if (s.Title.ToUpperInvariant() == "ERRORS")
                    {
                        NPlot.LinePlot npPlot = new LinePlot();
                        npPlot.AbscissaData = s.XAxis;
                        npPlot.OrdinateData = s.YAxis;
                        npPlot.Label        = s.Title;
                        npPlot.Color        = s.Color;

                        npSurface.Add(npPlot, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left);
                        break;
                    }
                }
                //Set min/max to same values as main plot
                npSurface.XAxis1.WorldMin = iMin;
                npSurface.XAxis1.WorldMax = iMax;
                SetAxes(npSurface, AxisFont, TickFont);

                //Save image and add it to the report
                npSurface.Bitmap.Save(ImagePath, System.Drawing.Imaging.ImageFormat.Png);
                sb.AppendFormat("<img src=\"img/{0}\" alt=\"{1}\" />", Filename, this.Title);
            }
            AddLinkToTop(sb);

            return(sb.ToString());
        }
예제 #24
0
        private void PlotChart(QueryResultsEventArgs e, PlotSurface2D plot, List <KeyValuePair <int, Guid> > signals, bool cacheAxis)
        {
            if (cacheAxis)
            {
                double minX, maxX, minY, maxY;

                plot.Title = m_plotTitle;
                maxX       = plot.XAxis1.WorldMax;
                minX       = plot.XAxis1.WorldMin;
                maxY       = plot.YAxis1.WorldMax;
                minY       = plot.YAxis1.WorldMin;

                foreach (IDrawable drawing in plot.Drawables.ToArray())
                {
                    plot.Remove(drawing, false);
                }

                foreach (KeyValuePair <int, Guid> freq in signals)
                {
                    SignalDataBase data = e.Results[freq.Value];

                    List <double> y = new List <double>(data.Count);
                    List <double> x = new List <double>(data.Count);

                    for (int i = 0; i < data.Count; i++)
                    {
                        ulong  time;
                        double value;
                        data.GetData(i, out time, out value);

                        x.Add(time);
                        y.Add(value * m_scalingFactor);
                    }

                    LinePlot lines = new LinePlot(y, x);
                    lines.Pen = m_colorWheel.TryGetPen(freq.Key);

                    plot.Add(lines);
                }

                plot.XAxis1.WorldMax = maxX;
                plot.XAxis1.WorldMin = minX;
                plot.YAxis1.WorldMax = maxY;
                plot.YAxis1.WorldMin = minY;

                plot.Refresh();
            }
            else
            {
                plot.Clear();
                plot.Title = m_plotTitle;
                AddInteractions();

                foreach (KeyValuePair <int, Guid> freq in signals)
                {
                    SignalDataBase data = e.Results[freq.Value];

                    List <double> y = new List <double>(data.Count);
                    List <double> x = new List <double>(data.Count);

                    for (int i = 0; i < data.Count; i++)
                    {
                        ulong  time;
                        double value;
                        data.GetData(i, out time, out value);

                        x.Add(time);
                        y.Add(value * m_scalingFactor);
                    }

                    LinePlot lines = new LinePlot(y, x);
                    lines.Pen = m_colorWheel.TryGetPen(freq.Key);

                    plot.Add(lines);
                }

                if (plot.XAxis1 != null)
                {
                    plot.XAxis1.WorldMax = e.EndTime.Ticks;
                    plot.XAxis1.WorldMin = e.StartTime.Ticks;
                }
                plot.Refresh();
            }
        }
예제 #25
0
        public PlotLogLin()
        {
            infoText  = "";
            infoText += "LogLin Example. Demonstrates - \n";
            infoText += "  * How to chart data against log axes and linear axes at the same time. \n";
            infoText += "  * Click a Start point and drag to an End point to Measure the plots";

            plotSurface.Clear();

            // draw a fine grid.
            Grid fineGrid = new Grid();

            fineGrid.VerticalGridType   = Grid.GridType.Fine;
            fineGrid.HorizontalGridType = Grid.GridType.Fine;
            plotSurface.Add(fineGrid);

            const int npt = 101;

            float[] x    = new float[npt];
            float[] y    = new float[npt];
            float   step = 0.1f;

            for (int i = 0; i < npt; ++i)
            {
                x[i] = i * step - 5.0f;
                y[i] = (float)Math.Pow(10.0, x[i]);
            }
            float xmin = x[0];
            float xmax = x[npt - 1];
            float ymin = (float)Math.Pow(10.0, xmin);
            float ymax = (float)Math.Pow(10.0, xmax);

            LinePlot lp = new LinePlot();

            lp.OrdinateData = y;
            lp.AbscissaData = x;
            lp.Pen          = new Pen(Color.Red);
            plotSurface.Add(lp);

            LogAxis loga = new LogAxis(plotSurface.YAxis1);

            loga.WorldMin      = ymin;
            loga.WorldMax      = ymax;
            loga.AxisColor     = Color.Red;
            loga.LabelColor    = Color.Red;
            loga.TickTextColor = Color.Red;
            loga.LargeTickStep = 1.0f;
            loga.Label         = "10^x";
            plotSurface.YAxis1 = loga;

            Measure m1 = new Measure(Color.Black);

            plotSurface.AddInteraction(m1);

            LinePlot lp1 = new LinePlot();

            lp1.OrdinateData = y;
            lp1.AbscissaData = x;
            lp1.Pen          = new Pen(Color.Blue);
            plotSurface.Add(lp1, XAxisPosition.Bottom, YAxisPosition.Right);
            LinearAxis lin = new LinearAxis(plotSurface.YAxis2);

            lin.WorldMin       = ymin;
            lin.WorldMax       = ymax;
            lin.AxisColor      = Color.Blue;
            lin.LabelColor     = Color.Blue;
            lin.TickTextColor  = Color.Blue;
            lin.Label          = "10^x";
            plotSurface.YAxis2 = lin;

            LinearAxis lx = (LinearAxis)plotSurface.XAxis1;

            lx.WorldMin = xmin;
            lx.WorldMax = xmax;
            lx.Label    = "x";

            //((LogAxis)plotSurface.YAxis1).LargeTickStep = 2;

            plotSurface.Title = "Mixed Linear/Log Axes";

            //plotSurface.XAxis1.LabelOffset = 20.0f;

            plotSurface.Refresh();
        }
        public void OnLoadingFinished(Dictionary <ChannelInfo, DataTable> tables)
        {
            graph.Clear();

            Grid myGrid = new Grid();

            myGrid.VerticalGridType   = Grid.GridType.Fine;
            myGrid.HorizontalGridType = Grid.GridType.Coarse;
            graph.Add(myGrid);

            Color[] availableColors = new Color[]
            {
                Color.Blue,
                Color.Red,
                Color.Violet,
                Color.Black,
                Color.Cyan,
                Color.Brown,
                Color.Yellow
            };

            int trendNum = 0;

            foreach (ChannelInfo channelInfo in tables.Keys)
            {
                int        valueColumnIndex = tables[channelInfo].Columns.IndexOf("Value");
                int        timeColumnIndex  = tables[channelInfo].Columns.IndexOf("Time");
                int        valueCount       = tables[channelInfo].Rows.Count;
                double[]   values           = new double[valueCount];
                DateTime[] labels           = new DateTime[valueCount];
                for (int i = 0; i < valueCount; i++)
                {
                    double.TryParse(tables[channelInfo].Rows[i].ItemArray[valueColumnIndex].ToString(), out values[i]);
                    DateTime.TryParse(tables[channelInfo].Rows[i].ItemArray[timeColumnIndex].ToString(), out labels[i]);
                }

                LinePlot lp = new LinePlot();
                lp.DataSource   = values;
                lp.AbscissaData = labels;
                lp.Color        = availableColors[trendNum % availableColors.Length];
                lp.Label        = channelInfo.ChannelName;

                graph.Add(lp);

                trendNum++;
            }

            Legend legend = new Legend();

            legend.AttachTo(PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Right);
            legend.HorizontalEdgePlacement = Legend.Placement.Inside;
            legend.VerticalEdgePlacement   = Legend.Placement.Outside;
            legend.XOffset = 10;
            legend.YOffset = -10;

            graph.Legend       = legend;
            graph.LegendZOrder = 1;

            graph.Visible  = true;
            label1.Visible = false;

            Cursor = Cursors.Default;
        }
예제 #27
0
        private void PlotChart(QueryResultsEventArgs e, PlotSurface2D plot, List <Guid> signals, bool cacheAxis)
        {
            if (cacheAxis)
            {
                maxX = plot.XAxis1.WorldMax;
                minX = plot.XAxis1.WorldMin;
                maxY = plot.YAxis1.WorldMax;
                minY = plot.YAxis1.WorldMin;

                foreach (IDrawable drawing in plot.Drawables.ToArray())
                {
                    plot.Remove(drawing, false);
                }

                ColorWheel.Reset();
                foreach (Guid freq in signals)
                {
                    SignalDataBase data = e.Results[freq];

                    List <double> y = new List <double>(data.Count);
                    List <double> x = new List <double>(data.Count);

                    for (int i = 0; i < data.Count; i++)
                    {
                        data.GetData(i, out ulong time, out double value);

                        x.Add(time);
                        y.Add(value);
                    }

                    LinePlot lines = new LinePlot(y, x);
                    lines.Pen = ColorWheel.GetPen();

                    plot.Add(lines);
                }

                plot.XAxis1.WorldMax = maxX;
                plot.XAxis1.WorldMin = minX;
                plot.YAxis1.WorldMax = maxY;
                plot.YAxis1.WorldMin = minY;

                plot.Refresh();
            }
            else
            {
                plot.Clear();

                plot.AddInteraction(new PlotSurface2D.Interactions.HorizontalDrag());
                plot.AddInteraction(new PlotSurface2D.Interactions.VerticalDrag());
                plot.AddInteraction(new PlotSurface2D.Interactions.AxisDrag(false));

                ColorWheel.Reset();
                foreach (Guid freq in signals)
                {
                    SignalDataBase data = e.Results[freq];

                    List <double> y = new List <double>(data.Count);
                    List <double> x = new List <double>(data.Count);

                    for (int i = 0; i < data.Count; i++)
                    {
                        data.GetData(i, out ulong time, out double value);

                        x.Add(time);
                        y.Add(value);
                    }

                    LinePlot lines = new LinePlot(y, x);
                    lines.Pen = ColorWheel.GetPen();

                    plot.Add(lines);
                }
                plot.Refresh();
            }
        }
예제 #28
0
        void doCalcToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                string            expr     = tbExpr.Text;
                double            tMax     = double.Parse(tbTMax.Text);
                int               n        = int.Parse(tbN.Text);
                double            cSt      = double.Parse(tbCSt.Text);
                double            cDl      = double.Parse(tbCDl.Text);
                double[]          arrTFunc = null, arrVFunc = null;
                DeliveryOptimizer opt;
                if (rbAn.Checked)
                {
                    opt = new DeliveryOptimizer(expr, tMax, n, cSt, cDl);
                }
                else
                {
                    arrTFunc = new double[dgvFn.RowCount - 1];
                    arrVFunc = new double[dgvFn.RowCount - 1];
                    for (int i = 0; i < dgvFn.RowCount - 1; i++)
                    {
                        arrTFunc[i] = (double)dgvFn.Rows[i].Cells[0].Value;
                        arrVFunc[i] = (double)dgvFn.Rows[i].Cells[1].Value;
                    }
                    opt = new DeliveryOptimizer(arrTFunc, arrVFunc, n, cSt, cDl);
                }
                double[] arrTPrev = null, arrV = null;
                for (int i = 0; i < 10; i++)
                {
                    opt.Optimize(arrTPrev, out arrT, out arrQ, out arrV,
                                 out cStSum, out cDlSum);
                    arrTPrev = arrT;
                }
                opt.GetTheorFunc(out arrTFunc, out arrVFunc);
                ps.Clear();
                LinePlot lp = new LinePlot();
                lp.AbscissaData = arrT;
                lp.OrdinateData = arrV;
                ps.Add(lp);
                LinePlot lpFunc = new LinePlot();
                lpFunc.AbscissaData = arrTFunc;
                lpFunc.OrdinateData = arrVFunc;
                lpFunc.Pen          = Pens.Red;
                ps.Add(lpFunc);
                ps.XAxis1.Label = "t";
                ps.YAxis1.Label = "V(t)";
                ps.Refresh();

                dgvTQ.Rows.Clear();
                dgvTQ.RowCount = n;
                for (int i = 0; i < n; i++)
                {
                    dgvTQ.Rows[i].Cells["t"].Value = arrT[i];
                    dgvTQ.Rows[i].Cells["Q"].Value = arrQ[i];
                }
                tbCStSum.Text = cStSum.ToString();
                tbCDlSum.Text = cDlSum.ToString();
                QSum          = 0;
                for (int i = 0; i < arrQ.Length; i++)
                {
                    QSum += arrQ[i];
                }
                tbQSum.Text = QSum.ToString();
            }
            catch
            {
                MessageBox.Show("Проверьте исходные данные");
            }
        }
예제 #29
0
        private void listBox1_SelectedValueChanged(object sender, EventArgs e)
        {
            ListBoxDateWrapper      dateWrapper = (ListBoxDateWrapper)listBox1.SelectedItem;
            List <DexTimelineEntry> entries     = DexcomHistoryService.GetDexTimelineEntries(dateWrapper.Value).ToList();

            entries.Sort((x, y) => x.Timestamp.CompareTo(y.Timestamp));

            List <DexTimelineEntry> glucoseEvents = entries.FindAll(x => x.GlucoseSpecified);
            List <DexTimelineEntry> events        = entries.FindAll(x => x.InsulinSpecified || x.CarbsSpecified || x.EventTypeSpecified || x.MeterGlucoseSpecified || x.SessionStateSpecified);

            plotSurface2D1.Clear();

            if (glucoseEvents.Count == 0)
            {
                plotSurface2D1.Refresh();
                plotSurface2D1.Update();
                return;
            }

            plotSurface2D1.XAxis1 = new DateTimeAxis(dateWrapper.Value.Date, dateWrapper.Value.Date.AddHours(24));
            plotSurface2D1.YAxis1 = new LinearAxis(0, 400);

            DateTime[] xValues;
            double[]   yValues;

            xValues = new DateTime[glucoseEvents.Count];
            yValues = new double[glucoseEvents.Count];
            for (int i = 0; i < glucoseEvents.Count; i++)
            {
                xValues[i] = glucoseEvents[i].Timestamp;
                yValues[i] = (double)glucoseEvents[i].Glucose.Value;
            }

            DateTime lastEvent = DateTime.MaxValue;
            double   angle     = 90.0;

            foreach (DexTimelineEntry theEvent in events)
            {
                string msg = "???";
                if (theEvent.CarbsSpecified)
                {
                    msg = String.Format("{0} BE", theEvent.Carbs.Value / 12);
                }
                else if (theEvent.InsulinSpecified)
                {
                    msg = String.Format("{0} IE", theEvent.Insulin.Value);
                }
                else if (theEvent.SessionStateSpecified)
                {
                    msg = theEvent.SessionState.Value.ToString();
                }
                else if (theEvent.ExerciseEventSpecified)
                {
                    msg = String.Format("{0} Exercise", theEvent.ExerciseEvent.Value);
                }
                else if (theEvent.HealthEventSpecified)
                {
                    msg = theEvent.HealthEvent.ToString();
                }
                else if (theEvent.MeterGlucoseSpecified)
                {
                    msg = String.Format("Calibration: {0}", theEvent.MeterGlucose.Value);
                }

                if ((theEvent.Timestamp - lastEvent).TotalMinutes < 10)
                {
                    angle += 10;
                }

                PointD    pt         = new PointD(theEvent.Timestamp.Ticks, GuessYValue(glucoseEvents, theEvent.Timestamp));
                ArrowItem annotation = new ArrowItem(pt, angle, msg);
                angle += 5;
                plotSurface2D1.Add(annotation);
            }

            LinePlot glucosePlot = new LinePlot(yValues, xValues);

            plotSurface2D1.Add(glucosePlot);

            plotSurface2D1.Refresh();
            plotSurface2D1.Update();

            /*chart1.ChartAreas[0].AxisX.Minimum = dateWrapper.Value.Date.ToOADate();
             * chart1.ChartAreas[0].AxisX.Maximum = (dateWrapper.Value.Date + new TimeSpan(24, 0, 0)).ToOADate();
             * chart1.Series.Clear();
             * chart1.Annotations.Clear();
             *
             * Series glucoseSeries = new Series();
             * glucoseSeries.ChartType = SeriesChartType.Line;
             * glucoseSeries.XValueType = ChartValueType.Time;
             * chart1.Series.Add(glucoseSeries);
             * Series eventSeries = new Series();
             * eventSeries.ChartType = SeriesChartType.Point;
             * eventSeries.XValueType = ChartValueType.Time;
             * chart1.Series.Add(eventSeries);
             * DataPoint lastDataPoint = new DataPoint(0, 200);
             * foreach (DexTimelineEntry dte in entries)
             * {
             *  if (dte.Glucose != null)
             *  {
             *      lastDataPoint = new DataPoint();
             *      lastDataPoint.XValue = dte.Timestamp.ToOADate();
             *      lastDataPoint.YValues = new double[] { dte.Glucose.Value };
             *      glucoseSeries.Points.Add(lastDataPoint);
             *  }
             *  if (dte.Insulin != null)
             *  {
             *      DataPoint eventPoint = new DataPoint();
             *      eventPoint.XValue = dte.Timestamp.ToOADate();
             *      eventPoint.YValues = lastDataPoint.YValues;
             *      eventSeries.Points.Add(eventPoint);
             *      CalloutAnnotation insulinAnnotation = new CalloutAnnotation();
             *      insulinAnnotation.Text = String.Format("{0} IE", dte.Insulin);
             *      insulinAnnotation.AnchorDataPoint = eventPoint;
             *      chart1.Annotations.Add(insulinAnnotation);
             *  }
             *  if (dte.Carbs != null)
             *  {
             *      DataPoint eventPoint = new DataPoint();
             *      eventPoint.XValue = dte.Timestamp.ToOADate();
             *      eventPoint.YValues = lastDataPoint.YValues;
             *      eventSeries.Points.Add(eventPoint);
             *      CalloutAnnotation insulinAnnotation = new CalloutAnnotation();
             *      insulinAnnotation.Text = String.Format("{0} BE", dte.Carbs / 12);
             *      insulinAnnotation.AnchorDataPoint = eventPoint;
             *      chart1.Annotations.Add(insulinAnnotation);
             *  }
             *  if (dte.EventType != null)
             *  {
             *      DataPoint eventPoint = new DataPoint();
             *      eventPoint.XValue = dte.Timestamp.ToOADate();
             *      eventPoint.YValues = lastDataPoint.YValues;
             *      eventSeries.Points.Add(eventPoint);
             *      switch (dte.EventType)
             *      {
             *          case moe.yo3explorer.azusa.dex.Schema.Enums.EventType.Exercise:
             *              CalloutAnnotation exerciseAnnotation = new CalloutAnnotation();
             *              exerciseAnnotation.Text = String.Format(dte.ExerciseEvent.Value.ToString());
             *              exerciseAnnotation.AnchorDataPoint = eventPoint;
             *              chart1.Annotations.Add(exerciseAnnotation);
             *              break;
             *          case moe.yo3explorer.azusa.dex.Schema.Enums.EventType.Health:
             *              CalloutAnnotation healthAnnotation = new CalloutAnnotation();
             *              healthAnnotation.Text = String.Format(dte.HealthEvent.Value.ToString());
             *              healthAnnotation.AnchorDataPoint = eventPoint;
             *              chart1.Annotations.Add(healthAnnotation);
             *              break;
             *      }
             *  }
             *  if (dte.MeterGlucose != null)
             *  {
             *      DataPoint eventPoint = new DataPoint();
             *      eventPoint.XValue = dte.Timestamp.ToOADate();
             *      eventPoint.YValues = new double[] { dte.MeterGlucose.Value };
             *      eventSeries.Points.Add(eventPoint);
             *      CalloutAnnotation calibrationAnnotation = new CalloutAnnotation();
             *      calibrationAnnotation.Text = String.Format("Kalibration: {0}", dte.MeterGlucose);
             *      calibrationAnnotation.AnchorDataPoint = eventPoint;
             *      chart1.Annotations.Add(calibrationAnnotation);
             *  }
             *  if (dte.SessionState != null && lastDataPoint != null)
             *  {
             *      DataPoint eventPoint = new DataPoint();
             *      eventPoint.XValue = dte.Timestamp.ToOADate();
             *      eventPoint.YValues = lastDataPoint.YValues;
             *      eventSeries.Points.Add(eventPoint);
             *      CalloutAnnotation sessionStateAnnotation = new CalloutAnnotation();
             *      sessionStateAnnotation.Text = String.Format(dte.SessionState.Value.ToString());
             *      sessionStateAnnotation.AnchorDataPoint = lastDataPoint;
             *      chart1.Annotations.Add(sessionStateAnnotation);
             *  }
             * }*/

            toolStripButton1.Enabled = listBox1.SelectedIndex > 0;
            toolStripButton2.Enabled = listBox1.SelectedIndex < listBox1.Items.Count - 1;
            toolStripTextBox1.Text   = ((ListBoxDateWrapper)listBox1.SelectedItem).Value.ToShortDateString();
        }
예제 #30
0
        public StockChart()
        {
            DataTable emptyTable = new DataTable();

            emptyTable.Columns.Add("Time", typeof(DateTime));
            emptyTable.Columns.Add("Price", typeof(float));

            // Create the price line for the plot
            priceLine              = new LinePlot();
            priceLine.DataSource   = emptyTable;
            priceLine.AbscissaData = TIME_DATA_TAG;
            priceLine.OrdinateData = PRICE_DATA_TAG;
            priceLine.Color        = PRICE_COLOR_POSITIVE;

            // Create the origin open price line
            openLine                 = new LinePlot();
            openLine.DataSource      = emptyTable;
            openLine.AbscissaData    = TIME_DATA_TAG;
            openLine.OrdinateData    = PRICE_DATA_TAG;
            openLine.Pen             = new System.Drawing.Pen(GUIDE_COLOR);
            openLine.Pen.DashPattern = new float[] { 2.0f, 2.0f };
            openLine.Pen.DashCap     = System.Drawing.Drawing2D.DashCap.Round;
            openLine.Pen.Width       = 1.5f;

            // Create the surface used to draw the plot
            stockPricePlot = new NPlot.Swf.InteractivePlotSurface2D();
            stockPricePlot.Add(priceLine);
            stockPricePlot.Add(openLine);
            stockPricePlot.SmoothingMode             = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            stockPricePlot.ShowCoordinates           = false;
            stockPricePlot.XAxis1.TicksCrossAxis     = false;
            stockPricePlot.XAxis1.TickTextNextToAxis = true;
            stockPricePlot.XAxis1.SmallTickSize      = 0;
            stockPricePlot.XAxis1.LargeTickSize      = 0;
            stockPricePlot.XAxis1.HideTickText       = false;
            //stockPricePlot.XAxis1.NumberFormat = " h";
            stockPricePlot.XAxis1.TickTextColor   = openLine.Pen.Color;
            stockPricePlot.XAxis1.TickTextFont    = new System.Drawing.Font("monospace", 8.0f, System.Drawing.FontStyle.Bold);
            stockPricePlot.XAxis1.AxisColor       = System.Drawing.Color.Transparent;
            stockPricePlot.XAxis1.TicksLabelAngle = (float)0;
            TradingDateTimeAxis tradeAxis = new TradingDateTimeAxis(stockPricePlot.XAxis1);

            tradeAxis.StartTradingTime               = new TimeSpan(9, 30, 0);
            tradeAxis.EndTradingTime                 = new TimeSpan(16, 0, 0);
            stockPricePlot.XAxis1                    = tradeAxis;
            stockPricePlot.YAxis1.HideTickText       = false;
            stockPricePlot.YAxis1.Color              = System.Drawing.Color.Transparent;
            stockPricePlot.YAxis1.TickTextNextToAxis = true;
            stockPricePlot.YAxis1.TicksIndependentOfPhysicalExtent = true;
            stockPricePlot.YAxis1.TickTextColor = openLine.Pen.Color;
            stockPricePlot.PlotBackColor        = BACKGROUND_COLOR;
            stockPricePlot.SurfacePadding       = 5;

            // Create the interaction for the chart
            stockPricePlot.AddInteraction(new PlotDrag(true, false));
            stockPricePlot.AddInteraction(new AxisDrag());
            stockPricePlot.AddInteraction(new HoverInteraction(this));

            // Create the text controls
            priceText           = new Label();
            priceText.Location  = new System.Drawing.Point((stockPricePlot.Canvas.Width - 100) / 2, 10);
            priceText.Font      = new System.Drawing.Font("monoprice", 12.0f, System.Drawing.FontStyle.Regular);
            priceText.ForeColor = System.Drawing.Color.White;
            priceText.BackColor = System.Drawing.Color.Transparent;
            priceText.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            stockPricePlot.Canvas.Controls.Add(priceText);
            priceText.BringToFront();

            stockPricePlot.Refresh();
        }
예제 #31
0
 internal void AddLine(PlotSurface2D plot, double[] x, double[] y, string name)
 {
     ArrayAdapter data = new ArrayAdapter(x,y);
     Color c= NextColor();
     LinePlot line = new LinePlot(data);
     line.Label = name;
     Pen p = new Pen(c,2);
     line.Pen = p;
     plot.Add(line);
 }