当前位置:编程学习 > C#/ASP.NET >>

高人请进,有要事相商

我要在VB.NET中写一段指令,实现对数组(由数据库传过来,可假设数组为S,即所谓的一系列x,y坐标)的曲线生成,请高人帮忙写个代码,感谢
(我感觉思路是这样的:假定一个数组S,用Line指令画连接数组中两点的直线,做个循环,生成曲线)

以下内容可供参考:

Dim x0, y0, h, w

Dim I as integer

x0 = Shape1.Left

y0 = Shape1.Top + Shape1.Height

h = Shape1.Height / 1

w = Shape1.Width / 300

Picture1.ForeColor = QBColor(1)

Picture1.Cls

Y1 = Shape1.Height

For I=0 to 600

Picture1.Line (x0 + i * w, y0 - dqsj(i) * h)-(x0 + (i + 1) * w,y0 - dqsj(i + 1, Q) * h )

Next 

//说明:其中,dqsj是记录10分钟内实时采集速度值的数组。
--------------------编程问答-------------------- --------------------编程问答-------------------- 你的思路可以,把两两相邻的点用line连接起来就形成曲线了
//这是一段画曲线以及x坐标和y坐标的代码,你可以参考一下,有点多
    private void DrawPowerData(Graphics g)
        {
            Pen pen = null;
            SolidBrush brush = new SolidBrush(Color.Black);
            float leftMargin = 20;
            float topMargin = 20;
            float xOffSet = this.Width / 2;
            float yOffSet = this.Height / 2 + 10;

            float OneCardWidth = this.Width / 2;
            float OneCardHeight = this.Height / 2 - 10;

            int YMax = ((int)Math.Ceiling((double)(m_powerData.maxY / 10f))) * 10;
            int YMin = ((int)Math.Floor((double)(m_powerData.minY / 10f))) * 10;
            int XMax = (int)Math.Ceiling((double)m_powerData.maxX);
            int XMin = ((int)Math.Floor((double)(m_powerData.minX / 10f))) * 10;
            if (XMax == XMin || YMax == YMin)
                return;

            float XUnit = (OneCardWidth - leftMargin * 1.5f) / ((float)(XMax - XMin));
            float YUnit = (OneCardHeight - topMargin * 2) / ((float)(YMax - YMin));

            pen = new Pen(Color.Black);
            //X轴
            g.DrawLine(pen, leftMargin + xOffSet , (YMax - YMin) * YUnit + topMargin + yOffSet, XMax * XUnit + leftMargin + xOffSet, (YMax - YMin) * YUnit + topMargin + yOffSet);
            for (int i = 0; i <= XMax; i++)
            {
                SizeF s = g.MeasureString(i.ToString(), this.Font);
                g.DrawString(i.ToString(), this.Font, brush, i * XUnit + leftMargin + xOffSet - s.Width / 2, (YMax - YMin) * YUnit + topMargin + yOffSet + 5);

                if (i == 1)
                {
                    pen.DashStyle = DashStyle.Dash;
                }
                g.DrawLine(pen, i * XUnit + leftMargin + xOffSet, (YMax - YMin) * YUnit + topMargin + yOffSet, i * XUnit + leftMargin + xOffSet, topMargin + yOffSet);
            }

            //画y轴
            for (int i = YMin; i <= YMax; i = i + 10)
            {
                SizeF s = g.MeasureString(i.ToString(), this.Font);
                g.DrawString(i.ToString(), this.Font, brush, leftMargin + xOffSet - s.Width, (YMax - i) * YUnit + topMargin + yOffSet - s.Height / 2);
                g.DrawLine(pen, leftMargin + xOffSet, (YMax - i) * YUnit + topMargin + yOffSet, XMax * XUnit + leftMargin + xOffSet, (YMax - i) * YUnit + topMargin + yOffSet);
            }

            //写标题
            brush.Color = Color.Red;
            SizeF st = g.MeasureString(m_powerData.GetTitle(), this.Font);
            g.DrawString(m_powerData.GetTitle(), this.Font, brush, (OneCardWidth - st.Width) / 2 + xOffSet, yOffSet + 3);


            //画曲线
            pen = new Pen(Color.Red);
            float x1 = (m_powerData.mPos[m_powerData.mPos.Length - 1] * XUnit) + leftMargin + xOffSet;
            float y1 = (m_powerData.maxY - m_powerData.mLoad[m_powerData.mPos.Length - 1]) * YUnit + topMargin + yOffSet;
            for (int i = 0; i < m_powerData.mPos.Length; i++)
            {
                float x2 = x1;
                x1 = (m_powerData.mPos[i] * XUnit) + leftMargin + xOffSet;
                float y2 = y1;
                y1 = (m_powerData.maxY - m_powerData.mLoad[i]) * YUnit + topMargin + yOffSet;
                g.DrawLine(pen, x1, y1, x2, y2);
            }
            brush.Dispose();
            brush = null;

        }
补充:.NET技术 ,  VB.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,