日期:2014-05-18 浏览次数:20428 次
protected void Page_Load(object sender, EventArgs e)
{
showline();
}
protected void showline()
{
//数据初始化
string[] month = new string[6] { "1", "2", "3", "4", "5", "6"};
float[] d = new float[6] { 1.2f, 1.0f, 1.3f, 1.1f, 1.0f, 1.1f };
//画图初始化
Bitmap bMap = new Bitmap(800, 500);
Graphics gph = Graphics.FromImage(bMap);
gph.Clear(Color.LightCyan);
//画边框
Pen p = new Pen(Color.Black, 2);
gph.DrawRectangle(p, 1, 1, 798, 498);
//中心点
PointF cPt = new PointF(140, 380);
//X轴三角形
PointF[] xPt = new PointF[3] { new PointF(700 + 15, cPt.Y), new PointF(700, cPt.Y - 4), new PointF(700, cPt.Y + 4) };
//Y轴三角形
PointF[] yPt = new PointF[3] { new PointF(cPt.X, cPt.X - 15), new PointF(cPt.X - 4, cPt.X), new PointF(cPt.X + 4, cPt.X) };
//图表标题
gph.DrawString("完美国际价格指数", new Font("宋体", 9), Brushes.Black, new PointF(cPt.X + 60, cPt.X));
//画X轴
gph.DrawLine(Pens.Black, cPt.X, cPt.Y, 700, cPt.Y);
gph.DrawPolygon(Pens.Black, xPt);
gph.FillPolygon(new SolidBrush(Color.Black), xPt);
gph.DrawString("日期", new Font("宋体", 9), Brushes.Black, new PointF(720, 455));
//画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("宋体", 9), Brushes.Black, new PointF(25, 30));
//画Y轴刻度
for (int i = 1; i <= 5; i++)
{
gph.DrawString((i * 0.6).ToString(), new Font("宋体", 9), Brushes.Black, new PointF(cPt.X - 30, cPt.Y - i * 50 - 6));
gph.DrawLine(Pens.Black, cPt.X - 3, cPt.Y - i * 50, cPt.X, cPt.Y - i * 50);
}
//画X轴刻度
for (int i = 1; i <= month.Length; i++)
{
gph.DrawString(month[i - 1], new Font("宋体", 9), Brushes.Black, new PointF(cPt.X + i * 50 - 5, cPt.Y + 10));
gph.DrawLine(Pens.Black, cPt.X + i * 50, cPt.Y, cPt.X + i * 50, cPt.Y - 3);
}
//画数据走势图
for (int i = 1; i <= 6; i++)
{
//画折线
if (i < 6)
{
gph.DrawLine(new Pen(Color.GreenYellow, 2), cPt.X + i * 50, cPt.Y - d[i - 1]* 50