g . TranslateTransform ( 0 , - Height+300 ) ;
g . TranslateTransform ( - ChartInset , ChartInset ) ;
g . ScaleTransform (  -1 , -1 ) ;

解决方案 »

  1.   

    已解决,自己随便加了点:)
    <%@ Import Namespace = "System" %>
    <%@ Import Namespace = "System.Drawing" %>
    <%@ Import Namespace = "System.Drawing.Drawing2D" %>
    <%@ Import Namespace = "System.Drawing.Imaging" %> 
    <script language = "C#" runat = "server" >class LineChart
    {
    public Bitmap b ;
    public string Title = "" ;
    public ArrayList chartValues = new ArrayList ( ) ;//要传递过来的值
    public float Xorigin = 0 , Yorigin = 0 ;//起始值
    public float ScaleX , ScaleY ;//最大值
    public float Xdivs = 2 , Ydivs = 2 ;//要分成几断
    public string s_x="月";
    public string s_y="Kg";private int Width , Height ;//图表的宽度高度
    private Graphics g ;
    private Page p ;struct datapoint {
    public float x ;
    public float y ;
    public bool valid ;
    }//初始化
    public LineChart ( int myWidth , int myHeight , Page myPage ) {//构造函数
    Width = myWidth ; Height = myHeight ;
    ScaleX = myWidth ; ScaleY = myHeight ;
    b = new Bitmap ( myWidth , myHeight ) ;
    g = Graphics . FromImage ( b ) ;
    p = myPage ;
    }public void AddValue ( int x , int y ) {//增加点函数
    datapoint myPoint ;
    myPoint . x = x ;
    myPoint . y = y ;
    myPoint . valid = true ;
    chartValues . Add ( myPoint ) ;
    }public void Draw ( ) {
    int i ;
    float x , y , x0 , y0 ;
    string myLabel ;
    Pen blackPen = new Pen ( Color . Blue , 1 ) ;///划线的颜色和宽度
    Brush blackBrush = new SolidBrush ( Color . Black ) ;
    Font axesFont = new Font ( "宋体" , 9 ) ;//用到的字体及大小//首先要创建图片的大小
    p . Response . ContentType = "image/jpeg" ;
    g . FillRectangle ( new SolidBrush ( Color . LightBlue ) , 0 , 0 , Width , Height ) ;
    int ChartInset = 50 ;
    int ChartWidth = Width - ( 2 * ChartInset ) ;
    int ChartHeight = Height - ( 2 * ChartInset ) ;
    g . DrawRectangle ( new Pen ( Color . Black , 1 ) , ChartInset , ChartInset , ChartWidth , ChartHeight ) ;///画出矩形
    //写出图片上面的图片内容文字
    g . DrawString ( Title , new Font ( "宋体" , 15 ) , blackBrush , Width / 3 , 10 ) ;
    //沿X坐标写入X标签
    for ( i = 0 ; i <= Xdivs ; i++ ) {
    x = ChartInset + ( i * ChartWidth ) / Xdivs ;
    y = ChartHeight + ChartInset ;
    myLabel = ( Xorigin + ( ScaleX * i / Xdivs ) ) . ToString ( );
    g . DrawString ( myLabel , axesFont , blackBrush , x - 5 , y + 10 ) ;//写入0-12等数字
    g . DrawLine ( blackPen , x , y + 2 , x , y - 2 ) ;//划出分解点
    }
    g . DrawString ( "("+s_x+")" , axesFont , blackBrush , ChartWidth +ChartInset+10 , ChartHeight +ChartInset+ 10 ) ;//写入单位
    //沿Y坐标写入Y标签
    for ( i = 0 ; i <= Ydivs ; i++ )
    {
    x = ChartInset ;
    y = ChartHeight + ChartInset - ( i * ChartHeight / Ydivs ) ;
    myLabel = ( Yorigin + ( ScaleY * i / Ydivs ) ) . ToString ( ) ;
    g . DrawString ( myLabel , axesFont , blackBrush , 5 , y - 6 ) ;
    g . DrawLine ( blackPen , x + 2 , y , x - 2 , y ) ;
    }
    g . DrawString ( "("+s_y+")" , axesFont , blackBrush ,5 , 20 ) ;//写入单位
    //////////////////////////////////////
    foreach(datapoint pt in chartValues){
    x = ChartWidth * ( pt . x - Xorigin ) / ScaleX+50 ;
    y = Height-ChartHeight * ( pt . y - Yorigin ) / ScaleY-50 ;g . DrawString ( ""+pt . y+"" , axesFont , blackBrush ,x+5 , y-10 ) ;//写入数值
    }
    //////////////////////////////////////g . RotateTransform ( 180 ) ;
    g . TranslateTransform ( 0 , - Height ) ;
    g . TranslateTransform ( - ChartInset , ChartInset ) ;
    g . ScaleTransform ( - 1 , 1 ) ;//画出图表中的数据
    datapoint prevPoint = new datapoint ( ) ;
    prevPoint . valid = false ;
    foreach ( datapoint myPoint in chartValues ) {
    if ( prevPoint . valid == true ) {
    x0 = ChartWidth * ( prevPoint . x - Xorigin ) / ScaleX ;
    y0 = ChartHeight * ( prevPoint . y - Yorigin ) / ScaleY ;
    x = ChartWidth * ( myPoint . x - Xorigin ) / ScaleX ;
    y = ChartHeight * ( myPoint . y - Yorigin ) / ScaleY ;
    g . DrawLine ( blackPen , x0 , y0 , x , y ) ;
    g . FillEllipse ( blackBrush , x0 - 2 , y0 - 2 , 4 , 4 ) ;
    g . FillEllipse ( blackBrush , x - 2 , y - 2 , 4 , 4 ) ;//g . DrawString ( "("+myPoint . y+")" , axesFont , blackBrush ,x-2 , y-2 ) ;//写入数值
    }
    prevPoint = myPoint ;
    }//最后以图片形式来浏览
    b . Save ( p . Response . OutputStream , ImageFormat . Jpeg ) ;
    }~LineChart ( ) {
    g . Dispose ( ) ;
    b . Dispose ( ) ;
    }
    }
    void Page_Load ( Object sender , EventArgs e ) 
    {
    LineChart c = new LineChart ( 640 , 480 , Page ) ;
    c . Title = " 热工分析" ;
    c . Xorigin = 0 ; c . ScaleX = 12 ; c . Xdivs = 12 ;
    c . Yorigin = 0 ; c . ScaleY = Convert.ToSingle(1000) ; c . Ydivs = 5 ;
    c.s_x="月";
    c.s_y="kg";
    c . AddValue ( 0 , 150 ) ;
    c . AddValue ( 1 , 50 ) ;
    c . AddValue ( 2 , 700 ) ;
    c . AddValue ( 3 , 150 ) ;
    c . AddValue ( 4 , 450 ) ;
    c . AddValue ( 5 , 75 ) ;
    c . AddValue ( 6 , 450 ) ;
    c . AddValue ( 7 , 250 ) ;
    c . AddValue ( 8 , 150 ) ;
    c . AddValue ( 9 , 300 ) ;
    c . AddValue ( 10 , 200 ) ;
    c . AddValue ( 11 , 400 ) ;
    c . AddValue ( 12 , 500 ) ;
    c . Draw ( ) ;
    }
    </script >