예제 #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (DataReady)//(DataReady)
            {
                string errstring;
                Graphics myGraphics = e.Graphics;
                mygrapher = new Grapher(new GraphDimension(25, this.Size.Width - 25, 200, this.Size.Height - 100), "Position versus time", yvalue);
                DataSeries series1 = new DataSeries(Data, "time", "position", Color.Red, 3.0f);

                mygrapher.AddDataSeries(series1);
                if ((errstring = mygrapher.PaintEvent(ref myGraphics, this.Font, yshift)) != "")
                {
                    MessageBox.Show(errstring);
                }
            }
            base.OnPaint(e);
        }
예제 #2
0
        private void DrawBackGround(ref Graphics graphics, Font f, DataSeries D, double shift)
        {
            int vertical_divisions = 10;
            int horizontal_divisions = 8;

            int Hpixelsperdivision = (GraphBottom - GraphTop - 50) / horizontal_divisions;

            SolidBrush mybrush = new SolidBrush(Color.White);
            graphics.FillRectangle(mybrush, GraphLeftSide, GraphTop, GraphRightSide - GraphLeftSide, GraphBottom - GraphTop);
            mybrush.Dispose();

            TextFormatFlags flags = TextFormatFlags.Bottom | TextFormatFlags.EndEllipsis;
            TextRenderer.DrawText(graphics, GraphTitle, f,
                new Rectangle(GraphLeftSide + 2, GraphTop + 2, GraphRightSide - GraphLeftSide, 15), SystemColors.ControlText, flags);

            Pen myPen = new Pen(Color.Black, 1.0f);
            graphics.DrawRectangle(myPen, GraphLeftSide, GraphTop, GraphRightSide - GraphLeftSide, GraphBottom - GraphTop);
            graphics.DrawRectangle(myPen, GraphLeftSide + 25, GraphTop + 25, GraphRightSide - GraphLeftSide - 50, GraphBottom - GraphTop - 50);
            //draw horizontal lines and labels
            for (int i = 0; i <= horizontal_divisions; i++)
            {
                double maxVal = (double)(GraphBottom - GraphTop - 50) / PixelsPerUnit;
                double horizontal_value = maxVal / (horizontal_divisions) * (horizontal_divisions - i) - shift;
                string horizontal_value_str = horizontal_value.ToString();
                int LineLeft = GraphLeftSide + 25;
                int LineRight = GraphRightSide - 25;
                int LineHeight = GraphTop + ((GraphBottom - GraphTop - 50) / horizontal_divisions) * i + 25;
                graphics.DrawLine(myPen, LineLeft, LineHeight, LineRight, LineHeight);
                TextRenderer.DrawText(graphics, horizontal_value_str, f,
                    new Rectangle(LineLeft - 25, LineHeight - 4, 50, 12), SystemColors.ControlText, flags);
            }
            for (int i = 0; i < vertical_divisions; i++)//draw vertical lines and labels
            {

                if (D.Xtype == Type.GetType("System.DateTime"))
                {
                    double totalseconds = CastValue(D.Xmax, D.Xtype) - CastValue(D.Xmin, D.Xtype);
                    double secondsPerDiv = totalseconds / vertical_divisions;
                    DateTime minval = (DateTime)D.Xmin;
                    string vertical_value_str = String.Format("{0:HH}:{0:mm}:{0:ss}", minval.AddSeconds(secondsPerDiv * i));
                    int LineTop = GraphTop + 25;
                    int LineBottom = GraphBottom - 25;
                    int LinePos = GraphLeftSide + ((GraphRightSide - GraphLeftSide - 50) / (vertical_divisions)) * i + 25;
                    graphics.DrawLine(myPen, LinePos, LineTop, LinePos, LineBottom);
                    TextRenderer.DrawText(graphics, vertical_value_str, f,
                        new Rectangle(LinePos - 4, LineBottom + 10, 50, 12), SystemColors.ControlText, flags);
                }
                else if (D.Xtype == Type.GetType("System.Int32") || D.Xtype == Type.GetType("System.Int16") || D.Xtype == Type.GetType("System.Double"))
                {
                    double maxVal = CastValue(D.Xmax, D.Xtype) - CastValue(D.Xmin, D.Xtype);
                    double vertical_value = maxVal / (vertical_divisions) * i;// -shift;
                    string vertical_value_str = vertical_value.ToString();
                    int LineTop = GraphTop + 25;
                    int LineBottom = GraphBottom - 25;
                    int LinePos = GraphLeftSide + ((GraphRightSide - GraphLeftSide - 50) / vertical_divisions) * i + 25;
                    graphics.DrawLine(myPen, LinePos, LineTop, LinePos, LineBottom);
                    TextRenderer.DrawText(graphics, vertical_value_str, f,
                        new Rectangle(LinePos - 4, LineBottom + 10, 50, 12), SystemColors.ControlText, flags);

                }
            }
            myPen.Dispose();
            mybrush.Dispose();
        }
예제 #3
0
 public void AddDataSeries(DataSeries dataseries)
 {
     if (dataseries.seriesRows[0].x != null)
     {
         DataSeriesCollection.Add(dataseries);
     }
 }