50分求ASP.NET生成折线图(注明不调用组件,不调用OWC!)
解决方案 »
- 我想写一个网站后台操作说明书 明天要给编辑做培训 大家最好能给个word模板我参考 进者给分
- CheckBoxList
- 传入一个参数去给函数,返回四个值我这里该怎么整?
- 能否在页面PostBack的时候判断是哪个控件触发了这次PostBack
- 请教这样的统计如何实现?
- 关于登录的问题??急
- ASP.NET中操作DataGrid时怎么总是出现这个毛病,哪个高手晓得,求救啊?
- 如何设置使网页可以接受第三方cookie
- DATATABLE里,怎么样一次性修改或删除多个数据
- DropDownList中如何动态显示listitem的内容?马上结帖
- 全部可用分奉上问个问题:为什么我这个页面的提交在IE里面一点反应都没有?
- ASP.NET程序怎么做成安装包来部署到别的服务器上去?
{
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());
}
Flush()之 就可以鸟
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 ( ) ;
}
}