急!在线等!!C#中ZedGraph怎样画销量曲线

我想用ZedGraph画出这样一条曲线,数据库表中有一年中12个月份的一种产品的销量,横坐标为月份,纵坐标为销量,该怎么画,请高手指点。... 我想用ZedGraph画出这样一条曲线,数据库表中有一年中12个月份的一种产品的销量,横坐标为月份,纵坐标为销量,该怎么画,请高手指点。 展开
 我来答
百度网友6600a9880
2009-03-03 · TA获得超过587个赞
知道小有建树答主
回答量:118
采纳率:0%
帮助的人:84万
展开全部
施行代码
{ DateTime dtstart = Convert.ToDateTime(this.ddlstartyear.SelectedValue.Trim() + "-" + this.ddlstartmonth.SelectedValue.Trim() + "-01");
DateTime dtend = Convert.ToDateTime(this.ddlendyear.SelectedValue.Trim() + "-" + this.ddlendmonth.SelectedValue.Trim() + "-01");
createimgprice(ref dtstart, dtend);}
页面显示是()年()月到()年()月的时间端
和一个显示图片的控件
去调用下面的方法

protected void createimgprice(ref DateTime starttime, DateTime endtime)
{

int arraycount = (endtime.Year - starttime.Year) * 12 + (endtime.Month - starttime.Month) + 1; //月总数
string[] montharray = new string[arraycount];
string[] month = new string[12];
float[] dprice = new float[arraycount];
int ii = 0;
int ibili = Convert.ToInt32(this.ddlbili.SelectedValue); //比例

while (starttime != endtime.AddMonths(1))
{
ProSellStatDal psd = new ProSellStatDal();
string search = " 1=1 ";
DataRow dr = psd.selProCGTJ(starttime.Year.ToString(), starttime.Month.ToString(), search);
montharray[ii] = starttime.Year.ToString().Substring(2, 2) + "年" + starttime.Month.ToString() + "月"; //月份
dprice[ii] = float.Parse(dr.ItemArray[0].ToString().Trim());
ii++;
starttime = starttime.AddMonths(1);
}

int imgcount = 0;

if (arraycount % 24 == 0)
{
imgcount = arraycount % 24;
}
else
{
imgcount = (arraycount % 24) + 1;
}
//画图初始化
Bitmap bMap = new Bitmap(ii * 30 + 140, 540);
Graphics gph = Graphics.FromImage(bMap);
gph.Clear(Color.White);
PointF cPt = new PointF(70, 420); //中心点
PointF[] xPt = new PointF[3] { new PointF(cPt.X + (arraycount * 30) + 25, cPt.Y), new PointF(cPt.X + (arraycount * 30) + 10, cPt.Y + 8), new PointF(cPt.X + (arraycount * 30) + 10, cPt.Y - 8) };//Y轴三角形
PointF[] yPt = new PointF[3] { new PointF(cPt.X, cPt.X - 15), new PointF(cPt.X - 8, cPt.X), new PointF(cPt.X + 8, cPt.X) };//Y轴三角形
//画X轴
gph.DrawLine(Pens.Black, cPt.X, cPt.Y, cPt.X + arraycount * 30 + 15, cPt.Y);
gph.DrawPolygon(Pens.Black, xPt);
gph.FillPolygon(new SolidBrush(Color.Black), xPt);
//画Y轴
gph.DrawLine(Pens.Black, cPt.X, cPt.Y, cPt.X, cPt.X);
gph.DrawPolygon(Pens.Black, yPt);
gph.FillPolygon(new SolidBrush(Color.Black), yPt);
gph.DrawString("单位 ¥", new Font("宋体", 12), Brushes.Black, new PointF(0, 7));
//画Y轴刻度
for (int y = 0; y < 10; y++)
{
gph.DrawString(((y + 1) * ibili).ToString(), new Font("宋体", 11), Brushes.Black, new PointF(cPt.X - 60, cPt.Y - (y + 1) * 30 - 6));
gph.DrawLine(Pens.Black, cPt.X - 3, cPt.Y - (y + 1) * 30, cPt.X, cPt.Y - (y + 1) * 30);
}
for (int i = 0; i < montharray.Length; i++)
{
for (int y = 0; y < montharray[i].Length; y++)
{
//画X轴项目
gph.DrawString(montharray[i].Substring(y, 1), new Font("宋体", 11), Brushes.Black, new PointF(cPt.X + ((i + 1) * 30) - 5, cPt.Y + 5 + (y) * 20));
}
//画点
gph.DrawEllipse(Pens.Black, cPt.X + (i + 1) * 30 - 1.5F, cPt.Y - (30 * dprice[i] / ibili) - 1.5F, 3, 3);
gph.FillEllipse(new SolidBrush(Color.Black), cPt.X + (i + 1) * 30 - 1.5F, cPt.Y - (30 * dprice[i] / ibili) - 1.5F, 3, 3);
//画数值
gph.DrawString(dprice[i].ToString(), new Font("宋体", 11), Brushes.Black, new PointF(cPt.X + (i + 1) * 30, cPt.Y - (30 * dprice[i] / ibili) - 15));
//画折线
if (i > 0)
{
gph.DrawLine(Pens.Red, cPt.X + (i + 1) * 30, cPt.Y - (30 * dprice[i] / ibili), cPt.X + (i) * 30, cPt.Y - (30 * dprice[i - 1] / ibili));
}
}
//保存输出图片
bMap.Save(Server.MapPath("ProSellStatprice.gif"));
this.ImgPro.ImageUrl = "ProSellStatprice.gif";
}
产考一下。记住:sql要查某月的总数量,月的条件再用上面的循环就可以显示效果了;看不明白的话QQ(284345316)我,代码发给你
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式