コード例 #1
0
        public void DrawLine(Pen pen, bool bLineLable)
        {
            //画出图表中的数据
            datapoint prevPoint = new datapoint( );
            float     x, y, x0, y0;
            int       ChartInset  = 50;
            int       ChartWidth  = Width - (2 * ChartInset);
            int       ChartHeight = Height - (2 * ChartInset);

            prevPoint.valid = false;
            Brush penBrush = new SolidBrush(pen.Color);

            foreach (datapoint myPoint in chartValues)
            {
                x0 = ChartWidth * (prevPoint.x - Xorigin) / ScaleX;
                y0 = ChartHeight * (prevPoint.y - Yorigin) / ScaleY;
                x  = ChartWidth * (myPoint.x - Xorigin) / ScaleX;
                y  = ChartHeight * (myPoint.y - Yorigin) / ScaleY;
                if (prevPoint.valid == true)
                {
                    g.DrawLine(pen, x0, y0, x, y);
                    g.FillEllipse(penBrush, x0 - 2, y0 - 2, 4, 4);
                }
                g.FillEllipse(penBrush, x - 2, y - 2, 4, 4);
//				if(bLineLable)
//				{
//					RectangleF recF = new RectangleF(x-10,y+10,40,15);
//					g.DrawString(myPoint.y.ToString(),new Font ( "arial" , 10 ),new SolidBrush ( Color.BlueViolet),recF);
//				}
                prevPoint = myPoint;
            }
        }
コード例 #2
0
        public void updateDisplay(datapoint mostRecent)
        {
            if (Application.Current != null)
            {
                Application.Current.Dispatcher.InvokeAsync(() =>
                {
                    float powerPercent = (mostRecent.battery - 5.28f).Remap(0.1f, -0.8f, 0, 100);
                    int motorProgL     = (int)((float)mostRecent.currentMotorL).Remap(-255, 255, 0, 100);
                    int motorProgR     = (int)((float)mostRecent.currentMotorR).Remap(-255, 255, 0, 100);

                    if (powerPercent < 0.6 && powerPercent > -4)
                    {
                        powerPercent = 0;
                    }

                    tick.Content         = string.Format("{0:0} ups | {1:0} ms | {2:0.##} v | {3:0.##} cm", sensorData.averageUPS, sensorData.averageLatencyMS, mostRecent.battery, mostRecent.range);
                    motorL.Content       = "" + mostRecent.currentMotorL;
                    motorR.Content       = "" + mostRecent.currentMotorR;
                    motorProgressL.Value = motorProgL;
                    motorProgressR.Value = motorProgR;
                    try
                    {
                        Frame.Source = datapoint.BitmapToImageSource(datapoint.BitmapFromData(mostRecent.imageData, sensorData.blackOffset));
                    }
                    catch (Exception e)
                    {
                        Trace.WriteLine("Image decode error: " + e.Message);
                    }
                });
            }
        }
コード例 #3
0
 public void AddValue(long x, float y)
 {
     datapoint myPoint = new datapoint();
     myPoint.x=x;
     myPoint.y=y;
     myPoint.valid=true;
     chartValues.Add(myPoint);
 }
コード例 #4
0
ファイル: AdminController.cs プロジェクト: nghianguyen125/PM
        [OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")] // This is for output cache false
        public FileResult Draw()
        {
            LineChart(640, 480);
            Title   = "Hit counter Chart";
            Xorigin = 0; ScaleX = 500; Xdivs = 5;
            Yorigin = 0; ScaleY = 1000; Ydivs = 5;
            AddValue(50, 50);
            AddValue(100, 100);
            AddValue(200, 150);
            AddValue(450, 450);

            int    i;
            float  x, y, x0, y0;
            string myLabel;
            Pen    blackPen   = new Pen(Color.Black, 1);
            Brush  blackBrush = new SolidBrush(Color.Black);
            Font   axesFont   = new Font("arial", 10);

            //first establish working area
            //p.Response.ContentType = "image/jpeg";
            g.FillRectangle(new
                            SolidBrush(Color.LightYellow), 0, 0, Width, Height);
            int ChartInset  = 50;
            int ChartWidth  = Width - (2 * ChartInset);
            int ChartHeight = Height - (2 * ChartInset);

            g.DrawRectangle(new Pen(Color.Black, 1), ChartInset, ChartInset, ChartWidth, ChartHeight);

            //must draw all text items before doing the rotate below
            g.DrawString(Title, new Font("arial", 14), blackBrush, Width / 3, 10);
            //draw X axis labels
            for (i = 0; i <= Xdivs; i++)
            {
                x       = ChartInset + (i * ChartWidth) / Xdivs;
                y       = ChartHeight + ChartInset;
                myLabel = (Xorigin + (ScaleX * i / Xdivs)).ToString();
                g.DrawString(myLabel, axesFont, blackBrush, x - 4, y + 10);
                g.DrawLine(blackPen, x, y + 2, x, y - 2);
            }
            //draw Y axis labels
            for (i = 0; i <= Ydivs; i++)
            {
                x       = ChartInset;
                y       = ChartHeight + ChartInset - (i * ChartHeight / Ydivs);
                myLabel = (Yorigin + (ScaleY * i / Ydivs)).ToString();
                g.DrawString(myLabel, axesFont, blackBrush, 5, y - 6);
                g.DrawLine(blackPen, x + 2, y, x - 2, y);
            }

            //transform drawing coords to lower-left (0,0)
            g.RotateTransform(180);
            g.TranslateTransform(0, -Height);
            g.TranslateTransform(-ChartInset, ChartInset);
            g.ScaleTransform(-1, 1);

            //draw chart data
            datapoint prevPoint = new datapoint();

            prevPoint.valid = false;
            foreach (datapoint myPoint in chartValues)
            {
                if (prevPoint.valid == true)
                {
                    x0 = ChartWidth * (prevPoint.x - Xorigin) / ScaleX;
                    y0 = ChartHeight * (prevPoint.y - Yorigin) / ScaleY;
                    x  = ChartWidth * (myPoint.x - Xorigin) / ScaleX;
                    y  = ChartHeight * (myPoint.y - Yorigin) / ScaleY;
                    g.DrawLine(blackPen, x0, y0, x, y);
                    g.FillEllipse(blackBrush, x0 - 2, y0 - 2, 4, 4);
                    g.FillEllipse(blackBrush, x - 2, y - 2, 4, 4);
                }
                prevPoint = myPoint;
            }

            //finally send graphics to browser
            //b.Save(p.Response.OutputStream, ImageFormat.Jpeg);
            MemoryStream stream = new MemoryStream();

            b.Save(stream, ImageFormat.Jpeg);
            stream.Seek(0, SeekOrigin.Begin);
            var vvv = new FileStreamResult(stream, "image/jpeg");

            return(vvv);
        }
コード例 #5
0
        public void Draw(Graphics g)
        {
            int i;
            float y;
            long x;
            string myLabel;
            Pen blackPen = new Pen(Color.Black, 1);
            Pen grayPen = new Pen(Color.LightGray, (float)0.5);
            Pen redPen = new Pen(Color.Red, 2);
            Brush blackBrush = new SolidBrush(Color.Black);
            Font axesFont = new Font("arial",10);

            //first establish working area
            g.FillRectangle(new SolidBrush(Color.Khaki), 0, 0, width, height);
            int ChartInset = 50;
            int Chartwidth = width-(2*ChartInset);
            int Chartheight = height-(2*ChartInset);
            g.FillRectangle(new SolidBrush(Color.White), ChartInset, ChartInset, Chartwidth, Chartheight);
            g.DrawRectangle(new Pen(Color.Black,2),ChartInset,ChartInset,Chartwidth,Chartheight);

            //must draw all text items before doing the rotate below
            g.DrawString(Title, new Font("arial",14), blackBrush, width/3, 10);

            //draw X axis labels
            DateTime MyDate;
            for(i=0; i<=Xdivs; i++)
            {
                x=ChartInset+(i*Chartwidth)/Xdivs;
                y=Chartheight+ChartInset;
                MyDate = new DateTime(Xorigin + (ScaleX * i / Xdivs));
                myLabel = MyDate.Month + "/" + MyDate.Day + "/" + MyDate.Year;
                g.DrawString(myLabel, axesFont, blackBrush, x-25, y+10);
                g.DrawLine(new Pen(Color.Black, 2), x, y + 2, x, y - 2);

            }

            //draw Y axis labels
            for(i=0; i<=Ydivs; i++)
            {
                x=ChartInset;
                y=Chartheight+ChartInset-(i*Chartheight/Ydivs);
                myLabel = (Yorigin + (ScaleY*i/Ydivs)).ToString();
                g.DrawString(myLabel, axesFont, blackBrush, 5, y-6);
                g.DrawLine(new Pen(Color.Black, 2), x + 2, y, x - 2, y);
            }

            //transform drawing coords to lower-left (0,0)
            g.RotateTransform(180);
            g.TranslateTransform(0,-height);
            g.TranslateTransform(-ChartInset,ChartInset);
            g.ScaleTransform(-1, 1);

            //draw gridlines
            for (i = 1; i < gridLines; i++)
            {
                y = Chartheight * (ScaleY*i/(gridLines)) / ScaleY;
                g.DrawLine(grayPen, 1, y, Chartwidth - 2, y);
                x = Chartwidth * (ScaleX*i/(gridLines)) / ScaleX;
                g.DrawLine(grayPen, x, 2, x, Chartheight - 1);
            }

            //draw control limits (LCL, UCL)
            y = Chartheight * (UCL - Yorigin) / ScaleY;
            g.DrawLine(redPen, 0, y, Chartwidth, y);
            y = Chartheight * (LCL - Yorigin) / ScaleY;
            g.DrawLine(redPen, 0, y, Chartwidth, y);

            //draw chart data
            datapoint prevPoint = new datapoint();
            prevPoint.valid=false;

            double scaleX = (ScaleX - Xorigin) / Chartwidth; //pane.GetScaleFactor(pane.XAxis);
            double scaleY = (ScaleY - Yorigin) / Chartheight;  //pane.GetScaleFactor(pane.YAxis);

            PointF p1 = new PointF();
            PointF p2 = new PointF();

            datapoint prev = null;
            foreach (datapoint p in chartValues) {
                if (prev != null) {
                    p1.X = (float)(prev.x * scaleX);
                    p1.Y = (float)(prev.y * scaleY);
                    p2.X = (float)(p.x * scaleX);
                    p2.Y = (float)(p.y * scaleY);
                    g.DrawLine(blackPen, p1, p2);
                }
                prev = p;
            }

            //foreach(datapoint myPoint in chartValues)
            //{
            //    if(prevPoint.valid==true)
            //    {
            //        x0=Chartwidth*(prevPoint.x-Xorigin)/ScaleX;
            //        y0=Chartheight*(prevPoint.y-Yorigin)/ScaleY;
            //        x=Chartwidth*(myPoint.x-Xorigin)/ScaleX;
            //        y=Chartheight*(myPoint.y-Yorigin)/ScaleY;
            //        g.DrawLine(blackPen,x0,y0,x,y);
            //        g.FillEllipse(blackBrush,x0-2,y0-2,6,6);
            //        g.FillEllipse(blackBrush,x-2,y-2,6,6);
            //    }
            //    prevPoint = myPoint;
            //}
        }