最近想做个C#程序,用于根据数据绘制折线图,但要求以下功能
1.能放大、缩小、拖拽;
2.鼠标指向数据点显示该数据点的数值;
3.可以手工在折线图上画线;
4.折线图中连续两点的值上升和下降用不同颜色来绘制折线图的线条;
用GDI做恐怕很麻烦,关键是第一次做绘图的程序;
用ZedGraph做,但ZedGraph可能解决不了2、4的问题,也不知道能不能修改ZedGraph源码来实现这两个功能。
高手指点,到底用什么方式比较便捷一点?谢谢!
------解决方案--------------------
zedgraph画线、放大缩小、显示数值都没问题吧,至于最后一条没做过,不太清楚了
//鼠标移动显示所以数值
zedGraphControl1.IsShowCursorValues = true;
//只显示点的数值
zedGraphControl1.IsShowPointValues = true;
详细资料:
http://www.codeproject.com/Articles/5431/A-flexible-charting-library-for-NET
------解决方案--------------------
GDI绘图并不复杂,无非就是 MoveTo Lineto
------解决方案--------------------
利用折线分析商品价格走势
protected void Page_Load(object sender, EventArgs e)
{
int ID = Convert.ToInt32(Request["ID"].ToString());
this.CreateImage(ID);
}
private void CreateImage(int ID)
{
int height = 440, width = 600;
System.Drawing.Bitmap image = new System.Drawing.Bitmap(width,height);
Graphics g = Graphics.FromImage(image);
try
{
//清空图片背景色
g.Clear(Color.White);
Font font = new System.Drawing.Font("Arial", 9,FontStyle.Regular);
Font font1 = new System.Drawing.Font("宋体", 20, FontStyle.Regular);
Font font2 = new System.Drawing.Font("Arial", 8, FontStyle.Regular);
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue,Color.Blue, 1.2f, true);
g.FillRectangle(Brushes.AliceBlue, 0, 0, width, height);
Brush brush1 = new SolidBrush(Color.Blue);
Brush brush2 = new SolidBrush(Color.SaddleBrown);
string str = "SELECT * FROM tb_Ware WHERE ID=" + Request["ID"] + "";
SqlConnection Con = new SqlConnection(ConfigurationManager.AppSettings["ConSql"]);
Con.Open();
SqlCommand Com = new SqlCommand(str, Con);
SqlDataReader dr = Com.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
g.DrawString(""+dr["Name"].ToString()+"各月份价格走势", font1, brush1, new PointF(130, 30));
}
dr.Close();
//画图片的边框线
g.DrawRectangle(new Pen(Color.Blue), 0,0, image.Width - 1, image.Height - 1);
Pen mypen = new Pen(brush,1);
Pen mypen2 = new Pen(Color.Red,2);
//绘制线条
//绘制纵向线条
int x = 60;
for (int i = 0; i < 12; i++)
{
g.DrawLine(mypen,x, 80, x, 340);
x = x+40;
}