求教,柱状图的代码?

117hn 2003-08-20 04:39:27
本人求教柱状图的代码,请各位大侠不吝赐教,我用c#语言
pmcchn@pmjt.com.cn
...全文
91 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
childish 2003-08-23
  • 打赏
  • 举报
回复
mark
117hn 2003-08-22
  • 打赏
  • 举报
回复
你们所发的都不详细,我没有办法用
sunnyfigo 2003-08-21
  • 打赏
  • 举报
回复
to:aloxy(亦杨)
你的asp代码!
FlyingQQ 2003-08-21
  • 打赏
  • 举报
回复
数据表:

字段名称 类型 说明
ID 自动编号 主键 ,递增
YF 数字 销售月份
SL 数字 销量

数据
ID YF SL
1 1 12
2 2 5
3 3 7
4 4 20
5 5 16
6 6 10
7 7 19
8 8 8
9 9 7
10 10 13
11 11 11
12 12 15
alphawin 2003-08-21
  • 打赏
  • 举报
回复
好东西
FlyingQQ 2003-08-21
  • 打赏
  • 举报
回复
给段代码给你,应该对你有帮助

string sRouter = "c:\\db.mdb" ;
//获得当前Access数据库在服务器端的绝对路径
string strCon = " Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " + sRouter ;
//创建一个数据库连接
OleDbConnection myConn = new OleDbConnection ( strCon ) ;
string strCom = " SELECT YF ,SL FROM Table01 ORDER BY YF" ;
myConn.Open ( ) ;
OleDbCommand myCommand = new OleDbCommand ( strCom , myConn ) ;
OleDbDataReader myOleDbDataReader = myCommand.ExecuteReader ( ) ;
//创建OleDbDataReader实例,并以此实例来获取数据库中各条记录数据
int [ ] iXiaoSH = new int [ 12 ] ;
//定义一个数组,用以存放从数据库中读取的销售数据
string [ ] sMoth = new string [ 12 ] ;
//定义一个数组,用以存放从数据库中读取的销售月份
int iIndex = 0 ;
while ( myOleDbDataReader.Read ( ) )
{
iXiaoSH [ iIndex ] = myOleDbDataReader.GetInt32 ( 1 ) ;
sMoth [ iIndex ] = myOleDbDataReader.GetInt32 ( 0 ) . ToString ( ) + "月" ;
iIndex++ ;
}
//读取Table01数据表中的各条数据,并存放在先前定义的二个数组中
myConn . Close ( ) ;
myOleDbDataReader . Close ( ) ;
//关闭各种资源
Bitmap bm = new Bitmap ( 600 , 250 ) ;
//创建一个长度为600,宽带为250的Bitmap实例
Graphics g ;
g = Graphics.FromImage ( bm ) ;
//由此Bitmap实例创建Graphic实例
g . Clear ( Color . Snow ) ;
//用Snow色彩为背景色填充此绘画图面
g . DrawString ( " ××公司××器件2002年度销售情况一览表" , new Font ( "宋体" , 16 ) , Brushes . Black , new Point ( 5 , 5 ) ) ;
//在绘画图面的指定位置,以指定的字体、指定的颜色绘制指定的字符串。即为图表标题
//以下代码是是实现图01中的右上部
Point myRec = new Point ( 535 , 30 ) ;
Point myDec = new Point ( 560 , 26 ) ;
//以上是在图01中为下面绘制定位
g . DrawString ( "单位:万套" , new Font ( "宋体" , 9 ) , Brushes . Black , new Point ( 525 , 12 ) ) ;
for ( int i = 0 ; i < sMoth.Length ; i++ )
{
g . DrawRectangle ( Pens.Black , myRec . X , myRec . Y , 20 , 10 ) ;
//绘制小方块
g . FillRectangle ( new SolidBrush ( GetColor ( i ) ) , myRec . X , myRec . Y , 20 , 10 ) ;
//填充小方块
g . DrawString ( sMoth [ i ] . ToString ( ) , new Font ( "宋体" , 9 ) , Brushes . Black , myDec ) ;
//绘制小方块右边的文字
myRec . Y += 15 ;
myDec . Y += 15 ;
}
//以下代码是绘制图01中的Bar图,及其销售数量
int iBarWidth = 40 ;
int scale = 10 ;
for ( int i = 0 ; i < iXiaoSH . Length ; i++ )
{
g . DrawRectangle ( Pens.Black , ( i * iBarWidth ) + 15 , 250 - ( iXiaoSH [ i ] * scale ) , 20 , ( iXiaoSH [ i ] * scale ) + 5 ) ;
//绘制Bar图
g . FillRectangle ( new SolidBrush ( GetColor ( i ) ) , ( i * iBarWidth ) + 15 , 250 - ( iXiaoSH [ i ] * scale ) , 20 , ( iXiaoSH [ i ] * scale ) + 5 ) ;
//以指定的色彩填充Bar图
g . DrawString ( iXiaoSH [ i ] . ToString ( ) , new Font ( "宋体" , 9 ) , Brushes . Black , ( i * iBarWidth ) + 20 , 235 - ( iXiaoSH [ i ] * scale ) ) ;
//显示Bar图代表的数据
}
//以下代码是绘制图01中的边框,并形成Jpeg文件,供浏览器显示出来
Pen p = new Pen ( Color.Black , 2 ) ;
g . DrawRectangle ( p , 1 , 1 , 598 , 248 ) ;
bm.Save ( Response . OutputStream , ImageFormat . Jpeg ) ;

  9. WebForm1.aspx.cs文件中的InitializeComponent过程之后,添加下列代码,下列代码的作用是定义一个名称为GetColor函数,此函数的功能根据索引号得到相应的系统颜色:

private Color GetColor ( int itemIndex )
{
 Color MyColor ;
 int i = itemIndex ;
 switch ( i )
 {
  case 0 :
   MyColor = Color . Cornsilk ;
   return MyColor ;
  case 1 :
   MyColor = Color . Red ;
   return MyColor ;
  case 2 :
   MyColor = Color . Yellow ;
   return MyColor ;
  case 3 :
   MyColor = Color . Peru ;
   return MyColor ;
  case 4 :
   MyColor = Color . Orange ;
   return MyColor ;
  case 5 :
   MyColor = Color . Coral ;
   return MyColor ;
  case 6:
   MyColor = Color . Gray ;
   return MyColor ;
  case 7:
   MyColor = Color . Maroon ;
   return MyColor ;
  case 8:
   MyColor = Color . Azure ;
   return MyColor ;
  case 9:
   MyColor = Color.AliceBlue ;
   return MyColor ;
  case 10:
   MyColor = Color . Bisque ;
   return MyColor ;
  case 11:
   MyColor = Color . BurlyWood ;
   return MyColor ;
  case 12:
   MyColor = Color . Chartreuse ;
   return MyColor ;
  default:
   MyColor = Color . Green ;
   return MyColor ;
 }
}
aloxy 2003-08-20
  • 打赏
  • 举报
回复

for i=1 to total_no
temp_space=table_x+left_width+table_space/2+table_space*(i-1)+table_width*(i-1)
response.write "<v:rect id='_x0000_s1025' alt='' style='position:absolute;left:"
response.write temp_space
response.write "px;top:"
response.write table_y+all_height*(1-(total(i,1)/temp3))
response.write "px;width:"&table_width&"px;height:"&all_height*(total(i,1)/temp3)&"px;z-index:1' fillcolor='"&tb_color(i,2)&"'>"
response.write "<v:fill color2='"&tb_color(i,1)&"' rotate='t' type='gradient'/>"
response.write "<o:extrusion v:ext='view' backdepth='"&thickness&"pt' color='"&tb_color(i,2)&"' on='t'/>"
response.write "</v:rect>"
response.write "<v:shape id='_x0000_s1025' type='#_x0000_t202' alt='' style='position:absolute;left:"&temp_space&"px;top:"&table_y+all_height*(1-(total(i,1)/temp3))-table_width&"px;width:"&table_space+15&"px;height:18px;z-index:1'>"
response.write "<v:textbox inset='0px,0px,0px,0px'><table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td align='center'>"&total(i,1)&"</td></tr></table></v:textbox></v:shape>"

response.write "<v:shape id='_x0000_s1025' type='#_x0000_t202' alt='' style='position:absolute;left:"&temp_space-table_space/2&"px;top:"&table_y+all_height+1&"px;width:"&table_space+table_width&"px;height:18px;z-index:1'>"
response.write "<v:textbox inset='0px,0px,0px,0px'><table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td align='center'>"&total(i,2)&"</td></tr></table></v:textbox></v:shape>"
next
Case "B"
table_space=(all_height-table_width*total_no)/total_no
temp4=temp3/5
response.write "<!--[if gte vml 1]><v:line id='_x0000_s1027' alt='' style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"&table_x+left_width+length&"px,"&table_y+all_height-length&"px' to='"&table_x+left_width+all_width&"px,"&table_y+all_height-length&"px' strokecolor='"&line_color&"'/><![endif]-->"
for i=0 to all_width-1 step all_width/5
response.write "<!--[if gte vml 1]><v:line id='_x0000_s1027' alt='' style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"&table_x+left_width+i&"px,"&table_y+all_height-length&"px' to='"&table_x+left_width+length+i&"px,"&table_y+all_height&"px' strokecolor='"&line_color&"'/><![endif]-->"
response.write "<!--[if gte vml 1]><v:line id='_x0000_s1027' alt='' style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"&table_x+left_width+length+i&"px,"&table_y+all_height-length&"px' to='"&table_x+left_width+length+i&"px,"&table_y&"px' strokecolor='"&line_color&"'/><![endif]-->"
response.write "<!--[if gte vml 1]><v:line id='_x0000_s1027' alt='' style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"&table_x+left_width+i+all_width/5&"px,"&table_y+all_height&"px' to='"&table_x+left_width+i+all_width/5&"px,"&table_y+all_height+15&"px'/><![endif]-->"
response.write "<!--[if gte vml 1]>"
response.write "<v:shape id='_x0000_s1025' type='#_x0000_t202' alt='' style='position:absolute;left:"&table_x+left_width+i+all_width/5-left_width&"px;top:"&table_y+all_height&"px;width:"&left_width&"px;height:18px;z-index:1'>"
response.write "<v:textbox inset='0px,0px,0px,0px'><table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td align='right'>"&temp4&"</td></tr></table></v:textbox></v:shape><![endif]-->"
temp4=temp4+temp3/5
next

for i=1 to total_no
temp_space=table_space/2+table_space*(i-1)+table_width*(i-1)
response.write "<v:rect id='_x0000_s1025' alt='' style='position:absolute;left:"
response.write table_x+left_width
response.write "px;top:"
response.write table_y+temp_space
response.write "px;width:"&all_width*(total(i,1)/temp3)&"px;height:"&table_width&"px;z-index:1' fillcolor='"&tb_color(i,2)&"'>"
response.write "<v:fill color2='"&tb_color(i,1)&"' rotate='t' angle='-90' focus='100%' type='gradient'/>"
response.write "<o:extrusion v:ext='view' backdepth='"&thickness&"pt' color='"&tb_color(i,2)&"' on='t'/>"
response.write "</v:rect>"
response.write "<v:shape id='_x0000_s1025' type='#_x0000_t202' alt='' style='position:absolute;left:"&table_x+left_width+all_width*(total(i,1)/temp3)+thickness/2&"px;top:"&table_y+temp_space&"px;width:"&table_space+15&"px;height:18px;z-index:1'>"
response.write "<v:textbox inset='0px,0px,0px,0px'><table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td align='center'>"&total(i,1)&"</td></tr></table></v:textbox></v:shape>"

response.write "<v:shape id='_x0000_s1025' type='#_x0000_t202' alt='' style='position:absolute;left:"&table_x&"px;top:"&table_y+temp_space&"px;width:"&left_width&"px;height:18px;z-index:1'>"
response.write "<v:textbox inset='0px,0px,0px,0px'><table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td align='right'>"&total(i,2)&"</td></tr></table></v:textbox></v:shape>"
next
case else
end select

end function
%>
说明:不是我写的~~
aloxy 2003-08-20
  • 打赏
  • 举报
回复
<%
dim total(7,2)
total(1,1)=200
total(2,1)=800
total(3,1)=1000
total(4,1)=600
total(5,1)=1222
total(6,1)=3213
total(7,1)=8

total(1,2)="中国经营报"
total(2,2)="招聘网"
total(3,2)="51Job"
total(4,2)="新民晚报"
total(5,2)="新闻晚报"
total(6,2)="南方周末"
total(7,2)="羊城晚报"

total_no=7
%>
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<!--[if !mso]>
<style>
v\:* { behavior: url(#default#VML) }
o\:* { behavior: url(#default#VML) }
.shape { behavior: url(#default#VML) }
</style>
<![endif]-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<style>
TD { FONT-SIZE: 9pt}
</style></head>
<body topmargin=5 leftmargin=0 scroll=AUTO>
<%call table1(total,200,20,20,30,400,200,"A")%>
<%call table1(total,200,320,20,20,400,250,"B")%>
</body>
</html>


<%
function table1(total,table_x,table_y,thickness,table_width,all_width,all_height,table_type)
'参数含义(传递的数组,横坐标,纵坐标,柱子的厚度,柱子的宽度,图表的宽度,图表的高度,图表的类型)
'纯ASP代码生成图表函数1——柱状图
'作者:龚鸣(Passwordgm) QQ:25968152 MSN:passwordgm@sina.com Email:passwordgm@sina.com
'本人非常愿意和ASP,VML,FLASH的爱好者在HTTP://topclouds.126.com进行交流和探讨
'版本2.0 最后修改日期 2003-7-22
'非常感谢您使用这个函数,请您使用和转载时保留版权信息,这是对作者工作的最好的尊重。
dim tb_color(7,2)
tb_color(1,1)="#d1ffd1"
tb_color(2,1)="#ffbbbb"
tb_color(3,1)="#ffe3bb"
tb_color(4,1)="#cff4f3"
tb_color(5,1)="#d9d9e5"
tb_color(6,1)="#ffc7ab"
tb_color(7,1)="#ecffb7"

tb_color(1,2)="#00ff00"
tb_color(2,2)="#ff0000"
tb_color(3,2)="#ff9900"
tb_color(4,2)="#33cccc"
tb_color(5,2)="#666699"
tb_color(6,2)="#993300"
tb_color(7,2)="#99cc00"

line_color="#69f"
left_width=70
length=thickness/2
total_no=ubound(total,1)

temp1=0
for i=1 to total_no
if temp1<total(i,1) then temp1=total(i,1)
next
temp1=int(temp1)
if temp1>9 then
temp2=mid(cstr(temp1),2,1)
if temp2>4 then
temp3=(int(temp1/(10^(len(cstr(temp1))-1)))+1)*10^(len(cstr(temp1))-1)
else
temp3=(int(temp1/(10^(len(cstr(temp1))-1)))+0.5)*10^(len(cstr(temp1))-1)
end if
else
if temp1>4 then temp3=10 else temp3=5
end if
temp4=temp3
response.write "<!--[if gte vml 1]><v:rect id='_x0000_s1027' alt='' style='position:absolute;left:"&table_x+left_width&"px;top:"&table_y&"px;width:"&all_width&"px;height:"&all_height&"px;z-index:-1' fillcolor='#9cf' stroked='f'><v:fill rotate='t' angle='-45' focus='100%' type='gradient'/></v:rect><![endif]-->"
response.write "<!--[if gte vml 1]><v:line id='_x0000_s1027' alt='' style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"&table_x+left_width&"px,"&table_y+all_height&"px' to='"&table_x+all_width+left_width&"px,"&table_y+all_height&"px'/><![endif]-->"
response.write "<!--[if gte vml 1]><v:line id='_x0000_s1027' alt='' style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"&table_x+left_width&"px,"&table_y&"px' to='"&table_x+left_width&"px,"&table_y+all_height&"px'/><![endif]-->"

select case table_type
case "A"
table_space=(all_width-table_width*total_no)/total_no
response.write "<!--[if gte vml 1]><v:line id='_x0000_s1027' alt='' style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"&table_x+left_width+length&"px,"&table_y&"px' to='"&table_x+left_width+length&"px,"&table_y+all_height-length&"px' strokecolor='"&line_color&"'/><![endif]-->"
for i=0 to all_height-1 step all_height/5
response.write "<!--[if gte vml 1]><v:line id='_x0000_s1027' alt='' style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"&table_x+left_width&"px,"&table_y+all_height-length-i&"px' to='"&table_x+left_width+length&"px,"&table_y+all_height-i&"px' strokecolor='"&line_color&"'/><![endif]-->"
response.write "<!--[if gte vml 1]><v:line id='_x0000_s1027' alt='' style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"&table_x+left_width+length&"px,"&table_y+all_height-length-i&"px' to='"&table_x+all_width+left_width&"px,"&table_y+all_height-length-i&"px' strokecolor='"&line_color&"'/><![endif]-->"
response.write "<!--[if gte vml 1]><v:line id='_x0000_s1027' alt='' style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"&table_x+(left_width-15)&"px,"&table_y+i&"px' to='"&table_x+left_width&"px,"&table_y+i&"px'/><![endif]-->"
response.write "<!--[if gte vml 1]>"
response.write "<v:shape id='_x0000_s1025' type='#_x0000_t202' alt='' style='position:absolute;left:"&table_x&"px;top:"&table_y+i&"px;width:"&left_width&"px;height:18px;z-index:1'>"
response.write "<v:textbox inset='0px,0px,0px,0px'><table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td align='right'>"&temp4&"</td></tr></table></v:textbox></v:shape><![endif]-->"
temp4=temp4-temp3/5
next
JensiaTsang 2003-08-20
  • 打赏
  • 举报
回复
收起来
csharplove 2003-08-20
  • 打赏
  • 举报
回复
我写的显示投票结果的柱状图代码:

private Label displayRectangle(Poll p)
{
System.Drawing.Bitmap b=new Bitmap(400,240);
Graphics g=Graphics.FromImage(b);

SolidBrush lbrush;
g.Clear(Color.White);
Pen p1=new Pen(Color.Black);
p1.EndCap=LineCap.ArrowAnchor;
g.DrawLine(p1,20,200,20,10);
g.DrawLine(p1,20,200,230,200);

pollxml px=new pollxml(p.Pollfile);
string[] items;
string[] votes;

px.getvotes(out items,out votes);

int num=items.Length;
float[] votenum=new float[num];


float maxvote=0;

for(int i=0;i<num;i++)
{
votenum[i]=float.Parse(votes[i]);
if(maxvote<votenum[i])
maxvote=votenum[i];
}

Color c=Color.FromArgb(0,180,0);
int offset=70;
int gap=180/(2*num+1);
for(int i=0;i<num;i++)
{
if(c.R+offset<=255)
{

c=Color.FromArgb(c.R+offset,180,255);

}
else
{

c=Color.FromArgb(c.R+offset-255,180,255);


}
lbrush=new SolidBrush(c);
g.FillRectangle(lbrush,20+(2*i+1)*gap,200-170*(votenum[i]/maxvote),gap,170*(votenum[i]/maxvote));
g.DrawString(votes[i]+"票",new Font("宋体",7),lbrush,new Point((20+(2*i+1)*gap),205));
g.FillRectangle(lbrush,230,20*2*i+20,30,10);
g.DrawString(items[i],new Font("宋体",10),lbrush,new Point(230,(2*i+1)*20+20));
}
b.Save(p.path+@"\rec.jpg",ImageFormat.Jpeg);
b.Dispose();
g.Dispose();
}
孟子E章 2003-08-20
  • 打赏
  • 举报
回复
http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=ADB6D011-A4AD-43A0-A8BF-3CED872A7A95

http://www.erp800.com/net_lover/ShowDetail.asp?id=221BC601-1A1B-4E1F-883D-04B043659703
meetweb 2003-08-20
  • 打赏
  • 举报
回复
到电脑报网站看看,我记得以前有该代码,我原来写了个通用类,可惜不知道放到那里去:-(
cyp503 2003-08-20
  • 打赏
  • 举报
回复
http://xml.sz.luohuedu.net/ShowDetail.asp?id=221BC601-1A1B-4E1F-883D-04B043659703

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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