如题,在GDI+中利用多点绘制曲线折线一般用DrawCurve(Pen, Point[])和DrawLines(Pen, Point[])之类的函数,可是这两个函数的第二个参数都要求是纯Point[]数组类型,在绘制动态曲线的时候,显然是要等到程序运行之后才能确定数据,并且数组里的个数也一直在变(第一秒钟有两个点,第二秒钟有三个点,以此类推的增加)。我的想法自然是先定义动态数组 List<Point> myPoints = new List<Point>();需要点的时候直接Add()就行了,但是你把泛型的myPoints传到DrawCurve(Pen, Point[])里面程序是会报错的,myPoints.ToArray();之后也一样不行。
另外,就算使用下下策最开始的时候定义几个足够大的数组(就暂时不考虑内存浪费了)也不行,比方开始Point[] myPoints=new Point[100](想后面把泛型里面数传会数组)当数组里面的数据点没有100个的时候,里面会有很多的(0,0),那样绘制的曲线后面就有一大堆没用的(0,0)直线。怎么办?怎么办?
问题应该已经描述清楚了,请教各位大侠,在教师节里,各位也当当好老师吧!
另外,就算使用下下策最开始的时候定义几个足够大的数组(就暂时不考虑内存浪费了)也不行,比方开始Point[] myPoints=new Point[100](想后面把泛型里面数传会数组)当数组里面的数据点没有100个的时候,里面会有很多的(0,0),那样绘制的曲线后面就有一大堆没用的(0,0)直线。怎么办?怎么办?
问题应该已经描述清楚了,请教各位大侠,在教师节里,各位也当当好老师吧!
解决方案 »
- 这种数据包怎么模拟发送
- C#字符串分割:字符串"AAABBBBCCFFFF"输出为"A3B4C2F4"怎么做?
- 如何对webBrowser.Navigate同步调用?
- winform中datagrid 如何转换excel
- 高手请进:数据访问组件madc安装问题
- 用C#开发一个基于WEB的图书管理系统请问谁有这方面的资料?帮帮我这个菜烏!!!
- 巨难:用程序算法如果区别两图片的相似百分比(是否是同一张图片)
- 请问:<?IMPORT namespace="dynMenu" implementation="menu.htc"> 在C#中怎么写?
- 请问怎么样从服务器硬盘上(非Web目录)下读取一个文件(如Word、zip等格式文件)并发送给客户端,客户端可正常浏览或下载?
- 如何接收POP3邮件?
- WinForm中DataGridView排序问题?
- winform做一个显示文本信息的界面
这样也行?按照net的风格不至于非要把人往这路上逼吧!另外,画折线的话这样是可以,可我要画的是圆滑曲线啊?还有什么高招没,求教求教~
private void DrawLines(Graphics grp, List<Point> pointList)
{
Point one, two;
for (int i = 0; i < pointList.Count-1; i++)
{
one = pointList[i];
two = pointList[i + 1];
grp.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
grp.DrawLine(new Pen(Color.Red, 2), one,two);
}
grp.Dispose();
}
高手们不愿意露面,我自个儿依葫芦画瓢学着上面的写了个,一并贴出来和大家分享。private void DrawCurves(Graphics grp, List<Point> pointList)
{
Point[] temps = new Point[pointList.Count];
for (int i = 0; i < pointList.Count; i++)
{
temps[i] = pointList[i];
}
grp.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
grp.DrawCurve(new Pen(Color.Red, 2), temps);
grp.Dispose();
}
如此,问题大致算解决了,大家还有什么新奇的好的想法,欢迎提出来交流交流……
using ZedGraph;GraphPane myPan = new GraphPane();
PointPairList list = new PointPairList();
Random ran = new Random();
LineItem myCurve;
DataSet ds = new DataSet();
SqlConnection myConnection = null;
SqlCommand myCommand = null;
SqlDataAdapter adapt = null;
SqlDataReader reader = null;
public Form1()
{
InitializeComponent();
}
public string GetConnectString(string server, string database, string username, string password)
{
return "Server=" + server + ";Database=" + database + ";UID=" + username + ";PWD=" + password;
} public void Exc()
{
double x, y;
myConnection = new SqlConnection();
myConnection.ConnectionString = GetConnectString("192.168.0.101", "AMR", "sa", "123");
myCommand = new SqlCommand("select MSID,UpdateTime from Tab_BS_Dailyfile", myConnection);
myCommand.CommandType = CommandType.Text;
myConnection.Open(); adapt = new SqlDataAdapter(); try
{
//myCommand.ExecuteNonQuery(); reader = myCommand.ExecuteReader();
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; )
{
y = double.Parse(reader[i++].ToString());
x = (double)new XDate(DateTime.Parse(reader[i++].ToString()));
list.Add(x, y);
}
} }
catch (SqlException ex)
{
MessageBox.Show("插入错误!" + ex.Message.ToString());
}
myCommand.Clone();
myConnection.Close();
} private void Form1_Load(object sender, EventArgs e)
{
this.zedGraphControl1.GraphPane.Title.Text = "动态折线图"; this.zedGraphControl1.GraphPane.XAxis.Title.Text = "时间";
this.zedGraphControl1.GraphPane.X2Axis.Scale.FontSpec.Size = 28; this.zedGraphControl1.GraphPane.YAxis.Title.Text = "数量";
this.zedGraphControl1.GraphPane.YAxis.Scale.FontSpec.Size = 8;
myPan.XAxis.Scale.IsVisible = true;
this.zedGraphControl1.GraphPane.XAxis.Type = ZedGraph.AxisType.DateAsOrdinal;
Exc(); DateTime dt = DateTime.Now; myCurve = zedGraphControl1.GraphPane.AddCurve("My Curve", list, Color.DarkGreen, SymbolType.None); this.zedGraphControl1.AxisChange(); this.zedGraphControl1.Refresh(); }
/// <summary>
/// 动起来
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Tick(object sender, EventArgs e)
{
zedGraphControl1.GraphPane.XAxis.Scale.MaxAuto = true; double x = (double)new XDate(DateTime.Now); double y = ran.NextDouble(); list.Add(x, y);//改成你数据库的数据就可以了
list.RemoveAt(0); this.zedGraphControl1.AxisChange(); this.zedGraphControl1.Refresh(); }
Point[] points=new Point[myPoints.Count],再挨个赋值呗