50分求ASP.NET生成折线图(注明不调用组件,不调用OWC!)

解决方案 »

  1.   

    public void CreateImage() 

    System.Drawing.Bitmap image = new System.Drawing.Bitmap(750, 746); 
    Graphics g = Graphics.FromImage(image); 
      g.SmoothingMode = SmoothingMode.HighQuality; 

    Font f = new System.Drawing.Font("Arial", 1, System.Drawing.FontStyle.Regular); 

    Brush b = new System.Drawing.SolidBrush(Color.White);
    Rectangle rect = new Rectangle(0, 0, 750, 746);


      HatchBrush hatchBrush = new HatchBrush(HatchStyle.Cross,Color.White,Color.White);
     
    g.FillRectangle(hatchBrush, rect);


    //下面数组的数据可以从数据库中提取,作为画点
    Point[] myArray = new Point[4000];
    for(int i = 0;i < 4000;i++)
    {
    Random rd = new Random();
        int intI = rd.Next(100);
    if((i+2)%2 == 0)
    {
    myArray[i] = new Point(i+50,i+intI);
    }
    else
    {
    myArray[i] = new Point(i+30,i+intI+20);
    }
    }
    Pen myPen = new Pen(Color.Blue, 1); 
    GraphicsPath myPath = new GraphicsPath(); 
    myPath.AddBeziers(myArray); 
    g.DrawPath(myPen, myPath); 

    System.IO.MemoryStream ms = new System.IO.MemoryStream(); 
    image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); 
    g.Dispose(); 
    image.Dispose(); 
    Response.ClearContent(); 
    Response.ContentType = "image/Jpeg"; 
    Response.BinaryWrite(ms.ToArray());
    }
      

  2.   

    用个httpHandler专门生成图片  生成bytes流发往Response.OutputStream
    Flush()之 就可以鸟
      

  3.   

    用GDI+做,一个坐标一个坐标的绘上去就行了啥!
      

  4.   

    //绘制曲线图的类;
    class LineChart
    {
    public Bitmap b ;
    public string Title = "1999年-2005年项目资金分布发展趋势图" ;
    public ArrayList chartValues = new ArrayList ( ) ;
    public float Xorigin = 0 ;
    public float Yorigin = 0 ;
    public float ScaleX ;
    public float ScaleY ;
    public float Xdivs = 2 ;
    public float Ydivs = 2 ;
    //public Color GetColor=Color.Red ;
    private int Width , Height ;
    private Graphics g ;
    private Page p ;struct datapoint 
    {
    public float x ;
    public float y ;
    public bool  valid;
    public Color color;
    }//初始化
    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 , float y ,Color z,bool b) 
    {
    datapoint myPoint ;
    myPoint.color=z;
    myPoint . x = x ;
    myPoint . y = y ;
    myPoint . valid=b ;
    chartValues . Add ( myPoint ) ;
    }public void Draw ( ) 
    {
    int i ;
    float x , y , x0 , y0 ;
    string myLabel ;
    Pen xPen=new Pen( Color.Black, 2);
    //Pen blackPen = new Pen ( myPoint.color, 2) ;
    Brush blackBrush = new SolidBrush ( Color . Black ) ;
    Font axesFont = new Font ( "arial" , 10 ) ;//首先要创建图片的大小
    p . Response . ContentType = "image/jpeg" ;
    g.SmoothingMode = SmoothingMode.AntiAlias;
    g . FillRectangle ( new SolidBrush ( Color.LightGray) , 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 ( "arial" , 14 ) , blackBrush , Width / 5 , 10 ) ;
    //沿X坐标写入X标签
    for ( i = 0;i <= Xdivs;i++) 
    {
    x = ChartInset + ( i * ChartWidth ) / Xdivs ; 
    y = ChartHeight + ChartInset ;
    myLabel = (Xorigin+i) . ToString ( )+"年" ;
    g . DrawString ( myLabel , axesFont , blackBrush , x - 10 , y + 10 ) ; 
    g . DrawLine ( xPen , x , y + 2 , x , y - 2 ) ; 
    }
    //沿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 ( xPen , x + 2 , y , x - 2 , y ) ;
    }
    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 ;
    Pen blackPen=new Pen(myPoint.color,2);
    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 ) ;
    }
    prevPoint = myPoint ;
    }b . Save ( p . Response . OutputStream , ImageFormat . Jpeg ) ;
    }~LineChart ( ) 
    {
    g . Dispose ( ) ;
    b . Dispose ( ) ;
    }
    }
      

  5.   

    不错,很多,HOHO,还有的话更好