62,266
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Imaging;
public partial class Estate_ZheXianTu : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//存月
string[] month = new string[6] { "2007.01", "2007.02", "2007.03", "2007.04", "2007.05", "2007.06" };
float[] d = new float[6] { 7000, 7219, 7500, 11000, 7000, 7650 }; //图中的点的数据
int Max_d2 = MaxNum(d); //点最大值
//画图初始化
System.Drawing.Bitmap bmap = new System.Drawing.Bitmap(325,265);
Graphics gph = Graphics.FromImage(bmap);
gph.Clear(Color.White);
PointF cpt = new PointF(40, 200);//中心点
//画x轴
gph.DrawLine(Pens.Black, cpt.X, cpt.Y, cpt.Y+100, cpt.Y);
gph.DrawString("月份", new Font("宋体", 12), Brushes.Black, new PointF(cpt.Y + 80, cpt.Y + 10));
//画y轴
gph.DrawLine(Pens.Black, cpt.X, cpt.Y, cpt.X, cpt.X);
gph.DrawString("单位(元)", new Font("宋体", 12), Brushes.Black, new PointF(0, 7));
//画y轴刻度
int r = (int)Math.Ceiling(Convert.ToDecimal(Max_d2 / 1000));
for (int i = 1; i <= r + 1; i++)
{
if (i <= 6)
{
gph.DrawString(Convert.ToString((r + 1) * 1000 - (6 - i) * 1000), new Font("宋体", 11), Brushes.Black, new PointF(cpt.X - 40, cpt.Y - (i - 1) * 30 - 5));
gph.DrawLine(Pens.Black, cpt.X - 3, cpt.Y - (i - 1) * 30, cpt.X, cpt.Y - (i - 1) * 30);
}
}
//画x轴项目
for (int j = 1; j <= 6; j++)
{
gph.DrawString(month[j - 1].Substring(5, 2), new Font("宋体", 11), Brushes.Black, new PointF(cpt.X + j * 40 - 5, cpt.Y + 5));
//画点
Pen pen2 = new Pen(Color.Orange, 6);
gph.DrawEllipse(pen2, cpt.X + j * 40 - 1.5f, cpt.Y - d[j - 1], 3, 3);
string price = (d[j - 1]).ToString();
gph.DrawString(price, new Font("宋体", 12), Brushes.Black, new PointF(cpt.X + j * 40 - 1.5f, 0));
}
//输出到浏览器
System.IO.MemoryStream ms = new System.IO.MemoryStream();
bmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ClearContent();
Response.ContentType = "image/Gif";
Response.BinaryWrite(ms.ToArray());
gph.Dispose();
bmap.Dispose();
}
public int MinNum(float[] str)
{
int min = Int32.Parse(str[0].ToString());
for (int i = 0; i < str.Length; i++)
{
if (min > Int32.Parse(str[i].ToString()))
{
min = Int32.Parse(str[i].ToString());
}
}
return min;
}
public int MaxNum(float[] str)
{
int max = Int32.Parse(str[0].ToString());
for (int i = 0; i < str.Length; i++)
{
if (max < Int32.Parse(str[i].ToString()))
{
max = Int32.Parse(str[i].ToString());
}
}
return max;
}
}