asp.net 畫曲線圖程式

來源:互聯網
上載者:User

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();
        }
    }

}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.