动态图形和表格的生成

GraphsAndCharts是一款无需编程即可生成动态2D图表和表格的工具。仅需通过<IMG>标签配置参数即可实现图表的实时更新。支持多种图表类型包括饼图、条形图等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

代码下载



介绍:
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 +
                 (intSpace + intBarWidth) * ii,
                 aoRect.Top - intTopOffset +
                 aintHeight - sngY[ii], intBarWidth, sngY[ii]);}


   //绘制图例
   writeLegend(aoRect, oGraphic, astrCaption,
               astrTitles, aintV, aintWidth, flTotal);

   return aoBmp;
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值