当前位置: 代码迷 >> Web Service >> 动态图形和表格的生成,该怎么解决
  详细解决方案

动态图形和表格的生成,该怎么解决

热度:297   发布时间:2012-03-03 15:33:04.0
动态图形和表格的生成
代码下载


介绍:
GraphsAndCharts 是一个完全动态的图形和表格生成器。图表的生成不需要任何代码,只需要在一个<IMG>的SRC属性。图表可以在空闲时被刷新并不需要上传网页。只需要添加代码到程序中,图表就可以生成。不需要自己写任何代码。
注意:这是开源代码,可以为图表对象增加更多的功能。
该代码可以被用来建立:
各种风格的图表
表格:饼型,条形等
图形物体如线,椭圆,矩形,圆等。


GraphsAndCharts的功能:
GraphsAndCharts的目的是迅速建立2D表格和图形而不使用代码。
使用GraphsAndCharts:
数据的可视话
描述静态数据
描述精确数据
报告
使用代码:
解压后用ASP.NET 2.0打开代码,是一个网页程序。运行 default.htm。

怎样工作:
一个<IMG>语句的秘密是它可以定位非图片。
在.NET中,一个用.ashx做扩展名的页面用来建立图片(这里,是DrawIt.ashx)。
在.ashx 页面中,生成图片的信息被翻译。
.ashx调用DrawAll类来建立位图。
内存中的位图作为一个二进制流输出到<IMG>。
例如用<IMG>建立一个饼型表:
<IMG SRC=ashx/DrawIt.ashx?width=250&height=250&xaxis=pushes
  &yaxis=pulls&background=powderblue&piechart=20,30,10,10,5;
  &titles=kings,queens,rooks,pawns,knights,castles;&>
该例子展示了DrawIt.ashx用到的参数:
width=250
height=250
xaxis=pushes
yaxis=pulls
background=powderblue
piechart=20,30,10,10,5;
titles=kings,queens,rooks,pawns,knights,castles;


解释:
<IMG>调用DrawIt.ashx。
DrawIt.ashx读取相关参数并翻译。
通过这些参数,DrawIt.ashx调用DrawAll类来建立图形对象。
DrawAll.cs中的函数建立相关的图形对象并在内存中返回位图。
DrawIt.ashx输出二进制流到<IMG>
代码片段:
以下是DrawAll类中的drawBarChart函数:
 Collapsepublic Bitmap drawBarChart (Bitmap aoBmp, Rectangle aoRect, int aintWidth, 
  int aintHeight, string astrBackground, string astrCaption, 
  string astrXaxis, string astrYaxis, int[] aintV, string[] astrTitles)
{
  Single[] sngY = new Single[aintV.Length];
  float flTotal;
  Single sngMax;
  int ii, intUpb, intBarWidth, intLegendHeight, 
  intSpace, intTopOffset, intTop;
  Graphics oGraphic;
  Font oFont;

  oGraphic = Graphics.FromImage(aoBmp);
  oFont = new Font("Small Fonts", 7);
  intTopOffset = (astrCaption == "") ? 4 : 20;

  oGraphic.FillRectangle(brushGet(astrBackground), 0, 0, aoRect.Left + 
  aintWidth + aoRect.Width, aoRect.Top + 
  aintHeight + aoRect.Bottom);


  //画轴
  //注意:Y轴开始于顶部
  oGraphic.DrawLine(penGet("black", 1), new Point(aoRect.Left, 
  aoRect.Top + aintHeight - aoRect.Height), 
  new Point(aoRect.Left + aintWidth, 
  aoRect.Top + aintHeight - aoRect.Height));
  oGraphic.DrawLine(penGet("black", 1), new Point(aoRect.Left, 
  aoRect.Top + aintHeight - aoRect.Height), 
  new Point(aoRect.Left, aoRect.Top + 0));


  //写头
  writeHeaders(aoRect, oGraphic, astrXaxis, 
  astrYaxis, astrCaption, aintWidth, aintHeight);

  intUpb = aintV.Length;
  intSpace = 10;
  intBarWidth = (int) ((aintWidth/intUpb) - intSpace);
  intLegendHeight = (int) ((aintHeight/intUpb) - 5);

  // Set Upper Y value
  //实质上部Y值
  sngMax = 1;
  flTotal = 0;
  for (ii=0;ii<intUpb;ii++)
  {
  sngMax = (aintV[ii] > sngMax) ? aintV[ii] : sngMax;
  flTotal += aintV[ii];
  }
  for (ii=0;ii<intUpb;ii++)
  {sngY[ii] = (aintV[ii] / sngMax) * (aintHeight - 10);}

  //设置Y值比例

  //绘条
  for (ii=0;ii<intUpb;ii++)
  {oGraphic.FillRectangle(brushGet(colorName(ii + 7)), 
  aoRect.Left + intSpace + 
  相关解决方案