给你一个思路:
namespace TrxControlNS {
using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Imaging; public class DrawLineChart{
int[] xArray = null;
int[] yArray = null; public int[] X{
get{
return xArray;
}
set{
xArray = value;
}
}
public int[] Y{
get{
return yArray;
}
set{
yArray = value;
}
}
public DrawLineChart() {
}
public DrawLineChart(int[] X,int[] Y) {
xArray = X;
yArray = Y;
}
public Bitmap DrawLineMethod(){
int width = 300;
int height = 200;
Bitmap bitmap = new Bitmap(width,height);
Graphics graphics = Graphics.FromImage( bitmap );
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
SolidBrush brush = new SolidBrush(Color.LightYellow);
graphics.FillRectangle(brush,0,0,width,height);//fill into a white rectangle;
Point[] point = new Point[ X.Length ];
for(int i=0;i< point.Length;i++){
int xInt = X[i];
int yInt = height - Y[i] ;
point[i] = new Point( xInt,yInt );
}
Pen pen = new Pen(Color.Red);
for(int i=0;i< point.Length-1;i++){
pen.Color = Color.Red;
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
graphics.DrawLine(pen, point[i],point[i+1]); pen.Color = Color.LightGray;
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
graphics.DrawLine(pen, new Point(0,point[i+1].Y) ,point[i+1]);
brush.Color = Color.Blue;
graphics.DrawString( (height - point[i].Y).ToString(),new Font("verdana",8),brush,Convert.ToSingle( point[i].X + 3 ),Convert.ToSingle( point[i].Y - 3 ) );
if( i == point.Length-1-1 ){
graphics.DrawString( (height - point[i+1].Y).ToString(),new Font("verdana",8),brush,Convert.ToSingle( point[i+1].X + 3 ),Convert.ToSingle( point[i+1].Y - 3 ) );
}
}
return bitmap;
}
}
}
namespace TrxControlNS {
using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Imaging; public class DrawLineChart{
int[] xArray = null;
int[] yArray = null; public int[] X{
get{
return xArray;
}
set{
xArray = value;
}
}
public int[] Y{
get{
return yArray;
}
set{
yArray = value;
}
}
public DrawLineChart() {
}
public DrawLineChart(int[] X,int[] Y) {
xArray = X;
yArray = Y;
}
public Bitmap DrawLineMethod(){
int width = 300;
int height = 200;
Bitmap bitmap = new Bitmap(width,height);
Graphics graphics = Graphics.FromImage( bitmap );
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
SolidBrush brush = new SolidBrush(Color.LightYellow);
graphics.FillRectangle(brush,0,0,width,height);//fill into a white rectangle;
Point[] point = new Point[ X.Length ];
for(int i=0;i< point.Length;i++){
int xInt = X[i];
int yInt = height - Y[i] ;
point[i] = new Point( xInt,yInt );
}
Pen pen = new Pen(Color.Red);
for(int i=0;i< point.Length-1;i++){
pen.Color = Color.Red;
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
graphics.DrawLine(pen, point[i],point[i+1]); pen.Color = Color.LightGray;
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
graphics.DrawLine(pen, new Point(0,point[i+1].Y) ,point[i+1]);
brush.Color = Color.Blue;
graphics.DrawString( (height - point[i].Y).ToString(),new Font("verdana",8),brush,Convert.ToSingle( point[i].X + 3 ),Convert.ToSingle( point[i].Y - 3 ) );
if( i == point.Length-1-1 ){
graphics.DrawString( (height - point[i+1].Y).ToString(),new Font("verdana",8),brush,Convert.ToSingle( point[i+1].X + 3 ),Convert.ToSingle( point[i+1].Y - 3 ) );
}
}
return bitmap;
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货