ASP.NET 通过GDI+编程画曲线图,如何实现对数坐标和拟和曲线,欢迎有经验的朋友进来指教。

Seeko0 2004-09-28 12:01:09
如题:在我的项目中的图表采用GD+自己写了控件,但是还有对数坐标和拟和曲线这两个问题一直困扰我,特此求教!
...全文
707 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovebanyi 2005-08-08
  • 打赏
  • 举报
回复
控件在哪里可以下载啊
lixqChina 2005-01-22
  • 打赏
  • 举报
回复
ddd
Seeko0 2004-10-13
  • 打赏
  • 举报
回复
好了,整个控件已经完成到
Seeko0 2004-10-08
  • 打赏
  • 举报
回复
感谢 luoyankun0216(静坐小河边) 以及各位的回复,我现在需要的是关于拟合曲线的算法,对数坐标以及找到方法,实际上控件的制作已经完成,现在需要加强功能
noahart 2004-09-29
  • 打赏
  • 举报
回复
http://www.codeproject.com/cs/miscctrl/DataPlotter.asp
luoyankun0216 2004-09-29
  • 打赏
  • 举报
回复
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Drawing.Imaging;

namespace 实现简单曲线图
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class LineChart : System.Web.UI.Page
{
public Bitmap b ;
public string Title = "在ASP.NET中实现数据图表" ;
public ArrayList chartValues = new ArrayList ( ) ;
public float Xorigin = 0 , Yorigin = 0 ;
public float ScaleX , ScaleY ;
public float Xdivs = 2 , Ydivs = 2 ;

private int Width , Height ;
private Graphics g ;
private Page p ;

struct datapoint
{
public float x;
public float y;
public bool valid;
}

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
LineChart c= new LineChart ( 640 , 480 , Page ) ;
c.Title = " 在ASP.NET中实现数据图表" ;
c.Xorigin = 0 ; c.ScaleX = 500 ; c . Xdivs = 5 ;
c . Yorigin = 0 ; c . ScaleY = 1000 ; c . Ydivs = 5 ;
c . AddValue ( 0 , 150 ) ;
c . AddValue ( 50 , 50 ) ;
c . AddValue ( 100 , 700 ) ;
c . AddValue ( 200 , 150 ) ;
c . AddValue ( 300 , 450 ) ;
c . AddValue ( 400 , 75 ) ;
c . AddValue ( 450 , 450 ) ;
c . AddValue ( 500 , 250 ) ;
c . Draw ( ) ;
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
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 , 2 ) ;//定义画笔
Brush blackBrush = new SolidBrush ( Color . Black ) ;//定义画刷
Font axesFont = new Font ( "arial" , 10 ) ;//定义字体

//首先要创建图片的大小
p . Response . ContentType = "image/jpeg" ;
g . FillRectangle ( new SolidBrush ( Color . LightGreen ) , 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 / 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 - 4 , y + 10 ) ;
g . DrawLine ( blackPen , 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 ( blackPen , 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 ;
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 ( ) ;
}


}
}
luoyankun0216 2004-09-29
  • 打赏
  • 举报
回复
不太明白你的意思,我到用GDI+绘制过曲线。不知道这对你有没有用?
MyXQ 2004-09-29
  • 打赏
  • 举报
回复
up & mark
luaiping 2004-09-29
  • 打赏
  • 举报
回复
我以前看过在.net中应用MATLAB
http://info.tlw.cn/11970.htm,希望对你有帮助
105910556 2004-09-29
  • 打赏
  • 举报
回复
GDI+ 是图形设备接口,程序员可利用它来编写设备无关的应用程序。GDI+ 服务通过一套托管类来展现。 ... ...
详见:

http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpguide/html/_gdiplus_introduction_to_gdi__about.asp

也许对你有用
softchao 2004-09-29
  • 打赏
  • 举报
回复
我有同事做过 我只能做简单的东西
先帮你顶一下 我看他能不能上来回答
yt_net 2004-09-29
  • 打赏
  • 举报
回复
没有做过,学习一下
Seeko0 2004-09-29
  • 打赏
  • 举报
回复
谢谢楼上各位
eboywy 2004-09-28
  • 打赏
  • 举报
回复
UP,MARK
happyjun2000 2004-09-28
  • 打赏
  • 举报
回复
没有作过,帮你顶!
mobydick 2004-09-28
  • 打赏
  • 举报
回复
取出特定的点,然后用平滑曲线连接。

4,816

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 图表区
社区管理员
  • 图表区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧