【www.gdgbn.com--安卓教程】
asp教程.net 画曲线图程序
*/
using system;
using system.data;
using system.configuration;
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.drawing2d;public partial class _default : system.web.ui.page
{
protected void page_load(object sender, eventargs e)
{
this.createimage();
}private void createimage()
{
int height = 600, width = 800;
bitmap image = new bitmap(width, height);
graphics graphics = graphics.fromimage(image);
stringformat sf = new stringformat();
try
{
graphics.clear(color.white);
font font = new font("arial", 9, fontstyle.regular);
font font1 = new font("宋体", 20, fontstyle.regular);
lineargradientbrush brush = new lineargradientbrush(new rectangle(0, 0, image.width, image.height), color.blue, color.blue, 1.2f, true);
graphics.fillrectangle(brushes.whitesmoke, 0, 0, width, height);
brush brush1 = new solidbrush(color.blue);
string p_str_sum = "2010-11-10";graphics.drawstring("分析年资比例", font1, brush1, new pointf(130, 30));
//画图片的边框线
graphics.drawrectangle(new pen(color.blue), 0, 0, image.width - 1, image.height - 1);
pen mypen = new pen(brush, 1);
//绘制横向线条
int x = 100;
for (int i = 0; i < 21; i++)
{
graphics.drawline(mypen, x, 24, x, 340);
x = x + 20;
}
pen mypen1 = new pen(color.blue, 2);
pen mypen2 = new pen(color.red, 2);
graphics.drawline(mypen1, x - 480, 24, x - 480, 340);
//绘制纵向线条
int y = 106;
for (int i = 0; i < 22; i++)
{
graphics.drawline(mypen, 30, y, 600, y);
y = y + 26;
}
graphics.drawline(mypen1, 30, y, 600, y);
//x轴
string[] n = { "0-3个月", "3个月以上", " 6个月以上", " 1年", " 2年", " 3年", " 4年", " 5年", " 6年", " 7年", " 8年", " 9年", " 10年", " 11年", " 12年", " 13年", " 14年", " 15年", " 16年", " 17年" };
x = 35;
for (int i = 0; i < 20; i++)
{
graphics.drawstring(n[i].tostring(), font, brushes.red, x, 348); //设置文字内容及输出位置
x = x + 40;
}
//y轴
string[] m = { " 20人", " 40人", " 60人", " 80人", " 100人", " 120人", " 140人",
" 160人", " 180人", " 200人", " 220人", " 240人", "260人", " 280人", " 300人", " 320人", " 340人",
" 360人", " 380人", " 400人"," 600人"};
y = 98;
for (int i = 0; i < 10; i++)
{
graphics.drawstring(m[i].tostring(), font, brushes.red, 10, y); //设置文字内容及输出位置
y = y + 26;
}
int[] count = new int[20];
string p_year = "2010-11-10";
//qldataadapter myda = new sqldataadapter(p_year, sqlcon);
//dataset myds = new dataset();
//myda.fill(myds);
for (int i = 0; i < 20; i++)
{count[i] = i;
}
solidbrush mybrush = new solidbrush(color.red);
point[] mypoint = new point[20];
mypoint[0].x = 30; mypoint[0].y = 340 - count[0];
mypoint[1].x = 50; mypoint[1].y = 340 - count[1];
mypoint[2].x = 70; mypoint[2].y = 340 - count[2];
mypoint[3].x = 90; mypoint[3].y = 340 - count[3];
mypoint[4].x = 110; mypoint[4].y = 340 - count[4];
mypoint[5].x = 130; mypoint[5].y = 340 - count[5];
mypoint[6].x = 150; mypoint[6].y = 340 - count[6];
mypoint[7].x = 170; mypoint[7].y = 340 - count[7];
mypoint[8].x = 190; mypoint[8].y = 340 - count[8];
mypoint[9].x = 210; mypoint[9].y = 340 - count[9];
mypoint[10].x = 230; mypoint[10].y = 340 - count[10];
mypoint[11].x = 250; mypoint[11].y = 340 - count[11];
mypoint[12].x = 270; mypoint[12].y = 340 - count[12];
mypoint[13].x = 290; mypoint[13].y = 340 - count[13];
mypoint[14].x = 310; mypoint[14].y = 340 - count[14];
mypoint[15].x = 330; mypoint[15].y = 340 - count[15];
mypoint[16].x = 350; mypoint[16].y = 340 - count[16];
mypoint[17].x = 370; mypoint[17].y = 340 - count[17];
mypoint[18].x = 390; mypoint[18].y = 340 - count[18];
mypoint[19].x = 420; mypoint[19].y = 340 - count[19];graphics.drawstring("", new font("宋体", 15), new solidbrush(color.red), new rectangle(0, 360, 120, 220), sf);
graphics.drawlines(mypen2, mypoint); //绘制折线
system.io.memorystream mstream = new system.io.memorystream();
image.save(mstream, system.drawing.imaging.imageformat.gif);
response.clearcontent();
response.contenttype = "image/gif";
response.binarywrite(mstream.toarray());
}
finally
{
graphics.dispose();
image.dispose();
}
}}