Exemplo n.º 1
0
        private void DrawGraph()
        {
            if (DataAvailable)
            {
                Graphics g = Graphics.FromImage(_gridBitmap);
                g.PageUnit = GraphicsUnit.Pixel;

                int xo = UnitsConverter.MM2Pixel(_drawingArea.Left);
                int yo = UnitsConverter.MM2Pixel(_drawingArea.Bottom);
                for (int i = 0; i < _xVector.Length; i++)
                {
                    int x = (int)((_xVector[i] - _xVector[0]) * _xScale);
                    if (_yVector[i] > 0)    // binned histogram might have zero frequencies
                    {
                        int y = (int)(_yScale * Math.Log10(_yVector[i]));
                        g.DrawLine(new Pen(ForeColor), xo + x, yo, xo + x, yo - y);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void CreateGridBitmap()
        {
            float axesOffset = _drawAxes ? _axesOffset : 0;

            // create the bitmap object
            _gridBitmap = new Bitmap(ClientRectangle.Width, ClientRectangle.Height, PixelFormat.Format32bppArgb);
            Graphics g = Graphics.FromImage(_gridBitmap);

            g.PageUnit = GraphicsUnit.Millimeter;

            // clear its background
            Brush br = new SolidBrush(BackColor);

            g.FillRectangle(br, 0F, 0F, _gridBitmap.Width, _gridBitmap.Height);

            _origin = new PointF(axesOffset, UnitsConverter.Pixel2MM(ClientRectangle.Bottom) - axesOffset);
            // I'm subtracting 1 from width as the 3d frame of the control overrites the last pixel (odd! it shouldn't be part of the client area
            // but this what i noticed). This issue started to show up once i changed to 3D frame and wasn't these with thin frame.
            _drawingArea = new RectangleF(axesOffset, 0, UnitsConverter.Pixel2MM(ClientRectangle.Width - 1) - axesOffset, UnitsConverter.Pixel2MM(ClientRectangle.Height) - axesOffset);
            int axesOffsetPixels = UnitsConverter.MM2Pixel(axesOffset);

            _drawingAreaPixels = new Rectangle(axesOffsetPixels, 0, ClientRectangle.Width - axesOffsetPixels - 1, ClientRectangle.Height - axesOffsetPixels);

            // draw 2 axes
            if (_drawAxes)
            {
                Pen axisPen = new Pen(AxisColor, AxisThickness);
                g.DrawLine(Pens.Black, UnitsConverter.Pixel2MM(ClientRectangle.Left), UnitsConverter.Pixel2MM(ClientRectangle.Bottom) - axesOffset + AxisThickness, UnitsConverter.Pixel2MM(ClientRectangle.Right), UnitsConverter.Pixel2MM(ClientRectangle.Bottom) - axesOffset + AxisThickness);
                g.DrawLine(Pens.Black, UnitsConverter.Pixel2MM(ClientRectangle.Left) + axesOffset - AxisThickness, UnitsConverter.Pixel2MM(ClientRectangle.Top), UnitsConverter.Pixel2MM(ClientRectangle.Left) + axesOffset - AxisThickness, UnitsConverter.Pixel2MM(ClientRectangle.Bottom));
            }

            // draw grid. I draw starting from axes so I'm sure both axis wil be snapped to the grid
            Pen   p = new Pen(GridColor, GridLineThickness);
            float x = _drawingArea.Left;

            while (x <= _drawingArea.Right)
            {
                x += GridSpacing;
                g.DrawLine(p, x, 0, x, _gridBitmap.Height);
            }
            if (!_logYScale)
            {
                float y = _drawingArea.Bottom;
                while (y > _drawingArea.Top)
                {
                    y -= GridSpacing;
                    g.DrawLine(p, 0, y, _drawingArea.Right, y);
                }
            }
            else
            {
                float decades = 4;
                float dy      = _drawingArea.Height / decades;
                for (float yy = _drawingArea.Bottom; yy > _drawingArea.Top; yy -= dy)
                {
                    for (int i = 1; i <= 10; i++)
                    {
                        float y = yy - (float)Math.Log10(i) * dy;
                        g.DrawLine(p, 0, y, _drawingArea.Right, y);
                    }
                }
            }
        }