using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Imaging;
public partial class Curve_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DrawLine();
}
public void DrawLine()
{
//初始化数据
string[] month = new string[12] { "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月" };
float[] d = new float[12] { 20.5F, 30.8F, 14.7F, 17.9F, 23.9F, 78.5F, 56.4F, 39.8F, 47.8F, 10.5F, 29.5F, 41.3F };
//画图初始化
Bitmap bmap = new Bitmap(500, 500);
Graphics gph = Graphics.FromImage(bmap);
gph.Clear(Color.White);
PointF cp = new PointF(40, 420);//中心点
PointF[] xpt = new PointF[3] { new PointF(cp.Y+15,cp.Y),new PointF(cp.Y,cp.Y-8),new PointF(cp.Y,cp.Y+8)};//X轴三角形
PointF[] ypt = new PointF[3] { new PointF(cp.X,cp.X-15),new PointF(cp.X-8,cp.X), new PointF(cp.X+8,cp.X)};//Y轴三角形
gph.DrawString("某工厂某产品月生产量图", new Font("宋体", 14), Brushes.Black, new PointF(cp.X + 60, cp.X));//图表标题
//画X轴
gph.DrawLine(Pens.Black, cp.X, cp.Y, cp.Y, cp.Y);
gph.DrawPolygon(Pens.Black, xpt);
gph.FillPolygon(new SolidBrush(Color.Black), xpt);
gph.DrawString("月份", new Font("宋体", 12), Brushes.Black, new PointF(cp.Y + 10, cp.Y + 10));
//画Y轴
gph.DrawLine(Pens.Black, cp.X, cp.Y, cp.X, cp.X);
gph.DrawPolygon(Pens.Black, ypt);
gph.FillPolygon(new SolidBrush(Color.Black), ypt);
gph.DrawString("单位:万", new Font("宋体", 12), Brushes.Black, new PointF(0, 7));
for (int i = 1; i <= 12; i++)
{
if (i < 11)
{
gph.DrawString((i * 10).ToString(), new Font("宋体", 11), Brushes.Black, new PointF(cp.X - 30, cp.Y - i * 30 - 6));
gph.DrawLine(Pens.Black, cp.X - 3, cp.Y - i * 30, cp.X, cp.Y - i * 30);
}
//画X轴项目
gph.DrawString(month[i - 1].Substring(0, 1), new Font("宋体", 11), Brushes.Black, new PointF(cp.X + i * 30 - 5, cp.Y + 5));
gph.DrawString(month[i - 1].Substring(1, 1), new Font("宋体", 11), Brushes.Black, new PointF(cp.X + i * 30 - 5, cp.Y +20));
if (month[i - 1].Length > 2) gph.DrawString(month[i-1].Substring(2,1),new Font("宋体",11),Brushes.Black,new PointF(cp.X+i*30-5,cp.Y+35));
//画点
gph.DrawEllipse(Pens.Black, cp.X + i * 30 - 1.5F, cp.Y - d[i - 1] * 3 - 1.5F, 3, 3);
gph.FillEllipse(new SolidBrush(Color.Black), cp.X + i * 30 - 1.5F, cp.Y - d[i - 1] * 3 - 1.5F, 3, 3);
//画数值
gph.DrawString(d[i-1].ToString(),new Font("宋体",11),Brushes.Black,new PointF(cp.X+i*30,cp.Y-d[i-1]*3));
//画折线
if (i > 1)
gph.DrawLine(Pens.Red, cp.X + (i - 1) * 30, cp.Y - d[i - 2] * 3, cp.X + i * 30, cp.Y - d[i - 1] * 3);
}
bmap.Save(Response.OutputStream, ImageFormat.Gif);
}
}
求帮助:
目前只有一条数据线,
就是想再增加2条横线、最大值和最小值。求解、
------解决方案--------------------------------------------------------