怎样在网页的Panel控件中画曲线图?

自由之眼 2004-02-01 11:53:50
根据指定的数据画出曲线图。
我使用的是继承Drawing类的方法绘制曲线,但是如何将曲线显示在网页的Panel控件中呢?
我查了MSDN,都是针对WinForm的。有没有针对WebForm的?
代码如下:

System.Drawing.Drawing2D.GraphicsPath gpath = new GraphicsPath(new Point[]{new Point(40, 140),new Point(275, 200)},new byte[] {(byte)PathPointType.Start,(byte)PathPointType.Line});
System.Drawing.Drawing2D.PathGradientBrush pgb = new PathGradientBrush(gpath);
pgb.SurroundColors = new System.Drawing.Color [] {System.Drawing.Color.Green};

请教了
...全文
144 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wwl1981 2004-02-02
  • 打赏
  • 举报
回复
转贴

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.IO;

namespace WebApplication1.dataview
{
/// <summary>
/// dataShow 的摘要说明。
/// </summary>
public class dataShow : System.Web.UI.Page
{
OWC10.ChChart objChart;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string strCategory,strValue;
int ty;
strCategory=Request.QueryString["strCategory"];
strCategory=strCategory.Replace(':','\t');
//Response.Write("<script language=javascript>alert('" + strCategory + "');</script>");
strValue=Request.QueryString["strValue"];
strValue=strValue.Replace(':','\t');
ty=Convert.ToInt32(Request.QueryString["ty"]);
//创建ChartSpace对象来放置图表
OWC10.ChartSpaceClass owcCS=new OWC10.ChartSpaceClass();
//在ChartSpace对象中添加图表,Add方法返回chart对象
objChart=owcCS.Charts.Add(0);
//objChart.Type=ChartChartTypeEnum.chChartTypeArea;
//指定图表的类型。类型由OWC.ChartChartTypeEnum枚举值得到
objChart.Type=GetChartType(ty);
//指定图表是否需要图例
objChart.HasLegend=true;
//给定标题
objChart.HasTitle=true;
objChart.Title.Caption="数据图";
//objChart.Axes[0].HasTitle=true;
//objChart.Axes[0].Title.Caption="X轴";
//objChart.Axes[1].HasTitle=true;
//objChart.Axes[1].Title.Caption="Y轴";


string strSeriesName = "图例 1";
//添加一个series
objChart.SeriesCollection.Add(0);
//objChart.SeriesCollection[0].Line.Color=Color.Blue;
//给定series的名字
objChart.SeriesCollection[0].SetData (OWC10.ChartDimensionsEnum.chDimSeriesNames,
+ (int)OWC10.ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName);

//给定分类
objChart.SeriesCollection[0].SetData (OWC10.ChartDimensionsEnum.chDimCategories,
+ (int)OWC10.ChartSpecialDataSourcesEnum.chDataLiteral, strCategory);

//给定值
objChart.SeriesCollection[0].SetData
(OWC10.ChartDimensionsEnum.chDimValues,
(int)OWC10.ChartSpecialDataSourcesEnum.chDataLiteral, strValue);
//输出成GIF文件.
//string strAbsolutePath = (Server.MapPath(".")) + "\\i\\test.gif";
//owcCS.ExportPicture(strAbsolutePath, "GIF", 600, 350);
//Response.Write("<script language=javascript>alert('" + strAbsolutePath + "');</script>");
//Response.Write(strAbsolutePath);
//创建GIF文件的相对路径.
//string strRelativePath = "./i/test.gif";
Response.Buffer = true;
//Response.Clear();
Byte[] imagePics;
imagePics=(Byte[])owcCS.GetPicture("gif",500,300);
Response.ContentType="image/gif";
Response.BinaryWrite(imagePics);
//Response.End();



//把图片添加到placeholder.
//string strImageTag = "<IMG SRC='" + strRelativePath + "'/>";
//ChartHolder.Controls.Add(new LiteralControl(strImageTag));
//Image1.ImageUrl="i/test.gif";

}

private OWC10.ChartChartTypeEnum GetChartType(int typeIndex)
{
int i;
OWC10.ChartChartTypeEnum myTE;
i=typeIndex;

switch(i)
{
case 0:
myTE=OWC10.ChartChartTypeEnum.chChartTypeColumnClustered;
return myTE;
case 1:
myTE=OWC10.ChartChartTypeEnum.chChartTypePie;
return myTE;
case 2:
myTE=OWC10.ChartChartTypeEnum.chChartTypeSmoothLine;
return myTE;
case 3:
myTE=OWC10.ChartChartTypeEnum.chChartTypeArea;
return myTE;
case 4:
myTE=OWC10.ChartChartTypeEnum.chChartTypeRadarLine;
return myTE;
default:
myTE=OWC10.ChartChartTypeEnum.chChartTypeColumnClustered;
return myTE;
}


}

#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
}
}

laodeng72586 2004-02-01
  • 打赏
  • 举报
回复
使用GDI+来实现.
自由之眼 2004-02-01
  • 打赏
  • 举报
回复
GDI+是可以的,并且可以实现,但是我无法控制图像的显示位置。(怎样把图片显示在固定的Panel控件中?)
代码如下:
SolidBrush mySolidBrush = new SolidBrush(Color.Aqua);
System.Drawing.Bitmap objbitbmp = new System.Drawing.Bitmap(300,300);
System.Drawing.Graphics MyGraphic = Graphics.FromImage(objbitbmp);
System.Drawing.Drawing2D.GraphicsPath gpath = new GraphicsPath();
System.Drawing.Pen myPen = new Pen(new SolidBrush(Color.Blue));

Point[] myPointArray = {
new Point(10, 200),
new Point(20, 100),
new Point(100, 50)};

gpath.AddCurve(myPointArray);

//MyGraphic.FillPath(mySolidBrush, gpath);
MyGraphic.FillRectangle(new SolidBrush(Color.Yellow),0,0,300,300);
MyGraphic.DrawPath(myPen, gpath);
objbitbmp.Save(Response.OutputStream,ImageFormat.Jpeg);

MyGraphic.Dispose();
objbitbmp.Dispose();

MSChart控件可以在网页中调用吗?(MSChart是ActiveX控件,应该可以被使用吧)
我想找一个使用MsChart画图的方法在网页上。谢谢。
huangsuipeng 2004-02-01
  • 打赏
  • 举报
回复
ding

110,549

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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