ASP.NET實現資料圖表a

來源:互聯網
上載者:User
asp.net|資料|圖表 public void DrawString (
string s ,
Font font ,
Brush brush ,
float x ,
float y
) ;


"s"是要輸出的字串,"font"是字串的字型,"brush"是定義刷子,後面二個參數是產生字串的位置座標。在程式中產生字串的具體語句如下:



Font axesFont = new Font ( "arial" , 10 ) ;
Brush blackBrush = new SolidBrush ( Color . Red ) ;
g . DrawString ( "在圖片上面寫入文字,呵呵" , axesFont , blackBrush , 90 , 20 ) ;


 
  要在圖片上畫線要使用到"Graphic"對象的DrawLine ( )方法,具體的使用文法如下:



public void DrawLines (
Pen pen ,
Point [ ] points
) ;



  其中"points"是定義點的位置,當然你也可以使用本文中使用的方法來調用,就是定義每畫一道線,這樣我感覺更方法些。下面是在產生的圖片上畫出三條線:



Pen redPen = new Pen ( Color . Red , 1 ) ;
Pen blackPen = new Pen ( Color . Blue , 2 ) ;
//以下語句是在此圖片對象上畫出各種線條,可以定義線條的粗細、起點、終點等
g . DrawLine ( blackPen , 0 , 2 , 210 , 250 ) ;
g . DrawLine ( blackPen , 210 , 250 , 310 , 50 ) ;
g . DrawLine ( redPen , 310 , 50 , 210 , 350 ) ;



  知道了這些基本知識,在定製圖片形狀,給圖片上色,在圖片上寫字、畫線就顯得比較容易了,下面代碼(chart2.aspx)的功能就是定製一個正方形圖片,並在圖片上畫線、寫字、上色,具體如下:



<%@ Page Language = "C#" ContentType = "image/jpeg" %>
<%@ Import Namespace = "System" %>
<%@ Import Namespace = "System.Drawing" %>
<%@ Import Namespace = "System.Drawing.Drawing2D" %>
<%@ Import Namespace = "System.Drawing.Imaging" %>
<html >
<head >
<script language = "C#" runat = "server" >
void Page_Load ( object sender , EventArgs e )
{
Bitmap image = new Bitmap ( 400 , 400 ) ;
Font axesFont = new Font ( "arial" , 10 ) ;
Brush blackBrush = new SolidBrush ( Color . Red ) ;
Pen redPen = new Pen ( Color . Red , 1 ) ;
Pen blackPen = new Pen ( Color . Blue , 2 ) ;
Graphics g = Graphics . FromImage ( image ) ;
g . Clear ( Color . White ) ;
g . FillRectangle ( new SolidBrush ( Color . LightGreen ) , 0 , 0 , 400 , 400 ) ;
//在此圖片對象中畫出圖片,可以定義文字大小、位置、色彩等
g . DrawString ( "在圖片上面寫入文字,呵呵" , axesFont , blackBrush , 90 , 20 ) ;
//以下語句是在此圖片對象上畫出各種線條,可以定義線條的粗細、起點、終點等
g . DrawLine ( blackPen , 0 , 2 , 210 , 250 ) ;
g . DrawLine ( blackPen , 210 , 250 , 310 , 50 ) ;
g . DrawLine ( redPen , 310 , 50 , 210 , 350 ) ;
//以"Jpeg"格式儲存此圖片對象,在用戶端顯示出來
// image . Save ( Response . OutputStream , ImageFormat . Jpeg ) ;
image . Save ( Response . OutputStream , ImageFormat . Jpeg ) ;
}
</script >
</head >
<body >
</body >
</html >






聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.