您的位置:首页 > 编程语言

谢谢各位关系这个的朋友门,这里是三维立体图的部分草稿源代码,随后将会有不断的扩展,敬请关注,

2007-05-13 22:35 513 查看
已经封装为控件 myowc.dll

http://blog.csdn.net/sunjay117/archive/2007/06/04/1638016.aspx








由于一些其他的原因,没有来得及的更新,以下是显示的代码,随后将会有不断的扩展,敬请关注

使用方法:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Reflection;
public partial class Default8 : System.Web.UI.Page
{
private int _pWidth = 640;//画布宽
private int _pHeight = 350;//画布宽
int oX = 80;//圆心
int oY = 250;//圆心
int oXX = 420;
int oYY = 190;
int oZZ = 70;
int Thickness = 10;//厚度
int total = 0;
int offset =500;
Hashtable list = new Hashtable();
Color c = Color.FromArgb(128, 128, 128);//字体颜色
Bitmap bmp;
Graphics g;
int alpha = 140;
float rotateA = 30;
Random rnd;
struct 月份
{

private int m1;
private int m2;
private int m3;
private int m4;
private int m5;
private int m6;
private int m7;
private int m8;
private int m9;
private int m10;
private int m11;
private int m12;
public int Month1
{
get { return this.m1; }
set { this.m1 = value; }
}

public int Month2
{
get { return this.m2; }
set { this.m2 = value; }
}
public int Month3
{
get { return this.m3; }
set { this.m3 = value; }
}
public int Month4
{
get { return this.m4; }
set { this.m4 = value; }
}
public int Month5
{
get { return this.m5; }
set { this.m5 = value; }
}
public int Month6
{
get { return this.m6; }
set { this.m6 = value; }
}
public int Month7
{
get { return this.m7; }
set { this.m7 = value; }
}
public int Month8
{
get { return this.m8; }
set { this.m8 = value; }
}
public int Month9
{
get { return this.m9; }
set { this.m9 = value; }
}
public int Month10
{
get { return this.m10; }
set { this.m10 = value; }
}
public int Month11
{
get { return this.m11; }
set { this.m11 = value; }
}
public int Month12
{
get { return this.m12; }
set { this.m12 = value; }
}
}
protected void Page_Load(object sender, EventArgs e)
{
initPanel();
DrawHeader("调查统计结果一览图");
rnd=new Random();
AddItem("软件销售", 46, 56, rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000));
AddItem("硬件销售", 80, rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000));
//AddItem("blog.csdn.net/sunjay", rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000));
//AddItem("贞观长歌", rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000), rnd.Next(100, 1000));

Draw();

ShowPanel();
}

void Draw()
{
DrawTable(c);
DrawMonth(Month.一月份);
DrawMonth(Month.二月份);
DrawMonth(Month.三月份);
DrawMonth(Month.四月份);
DrawMonth(Month.五月份);
DrawMonth(Month.六月份);
DrawMonth(Month.七月份);
DrawMonth(Month.八月份);
DrawMonth(Month.九月份);
DrawMonth(Month.十月份);
DrawMonth(Month.十一月份);
DrawMonth(Month.十二月份);

}
void AddItem(string name,int m1,int m2,int m3,int m4,int m5,int m6,int m7,int m8,int m9,int m10,int m11,int m12)
{
rnd = new Random();
月份 m=new 月份();
m.Month1 = m1;
m.Month2 = m2;
m.Month3 = m3;
m.Month4 = m4;
m.Month5 = m5;
m.Month6 = m6;
m.Month7 = m7;
m.Month8 = m8;
m.Month9 = m9;
m.Month10 = m10;
m.Month11 =m11;
m.Month12 = m12;
AddItem(name,m);
}
void AddItem(string name,月份 m)
{
this.total += m.Month1;
list.Add(name, m);
}
void DrawHeader(string header)
{
g.DrawString(header, new Font("宋体", 17), new SolidBrush(c), 30, 10);
}//初始化标题
void initPanel()//初始化画布
{
bmp = new Bitmap(this._pWidth, this._pHeight);
Color c = Color.FromArgb(alpha, 128, 128, 128);
Pen p = new Pen(c);
g = Graphics.FromImage(bmp);

g.Clear(Color.WhiteSmoke);
GraphicsPath path = new GraphicsPath();
path.AddLine(Point(0, 0), Point(oXX, 0));
path.AddLine(Point(oXX, 0), Point(oXX, oYY));
path.AddLine(Point(oXX, oYY), Point(0, oYY));
path.AddLine(Point(0, oYY), Point(0, 0));

g.DrawPath(new Pen(c), path);
g.FillPath(new SolidBrush(c), path);
path = new GraphicsPath();
path.AddLine(Point(0, 0), Point(0, oYY));
path.AddLine(Point(0, oYY), Point(0 - getCut(), oYY - getCut()));
path.AddLine(Point(0 - oZZ / Math.Sqrt(2), oYY - getCut()), Point(0 - getCut(), 0 - getCut()));
path.AddLine(Point(0 - getCut(), 0 - getCut()), Point(0, 0));
g.DrawPath(new Pen(c), path);
g.FillPath(new SolidBrush(c), path);
path = new GraphicsPath();
path.AddLine(Point(0, 0), Point(oXX, 0));
path.AddLine(Point(oXX, 0), Point(oXX - getCut(), 0 - getCut()));
path.AddLine(Point(oXX - getCut(), 0 - getCut()), Point(0 - getCut(), 0 - getCut()));
path.AddLine(Point(0 - getCut(), 0 - getCut()), Point(0, 0));
g.DrawPath(new Pen(c), path);
g.FillPath(new SolidBrush(c), path);

}
void ShowPanel()//显示图象
{
DrawTuBiao();
g.DrawRectangle(new Pen(c), 1, 1, bmp.Width - 2, bmp.Height - 2);
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
void DrawMonth(Month m)
{
int k = 0;
offset = Convert.ToInt32(oXX/(12.0));
total = 1000;
int px = offset * (int)m;
foreach (string str in list.Keys)
{
月份 obj = (月份)list[str];
Type objType = obj.GetType();
PropertyInfo[] objPropertiesArray = objType.GetProperties();
foreach (PropertyInfo objProperty in objPropertiesArray)
{
if (objProperty.Name == string.Format("Month{0}", (int)m))
{
int count =(int) objProperty.GetValue(obj, null);

g.DrawLine(new Pen(c), Point(px, 0), Point(px, oYY));
int x = Convert.ToInt32(count / Convert.ToDecimal(total) * oYY);
DrawRect(getColor(k), px + Thickness * k - Convert.ToInt32(list.Count / 2 * Thickness), x);
k++;
break;
}
}
}
g.TranslateTransform(getX(px-getCut()-10),getY(-getCut()));
g.RotateTransform(rotateA);
g.DrawString(m.ToString(), new Font("宋体", 9), new SolidBrush(c), 0,0);
g.ResetTransform();

}
void DrawTuBiao()
{
int k = 0;
offset = 30;

foreach (string str in list.Keys)
{
int x = Convert.ToInt32(((月份)list[str]).Month1 / Convert.ToDecimal(total) * oYY);
//DrawRect(getColor(k), offset+Thickness*k, x);
int top = 20;
int left = bmp.Width - 100;
g.DrawString(str, new Font("宋体", 9), new SolidBrush(c), left + 35, top + k * 20);
g.FillRectangle(new SolidBrush(getColor(k)), left, top + k * 20, 30, 12);

k++;
}
}
int getCut()
{
return Convert.ToInt32(oZZ / Math.Sqrt(2));
}//获取修剪数据
Point Point(object x, object y)
{
return new Point(getX(x), getY(y));
}//转化为坐标点
int getX(object x)//获取X坐标
{
return Convert.ToInt32(x) + oX;
}
int getY(object y)//获取Y坐标
{

return -Convert.ToInt32(y) + oY;

}
void DrawTable(Color c)
{
int tX = Convert.ToInt32(oYY / 10);
//int tY = Convert.ToInt32(oXX / list.Count);
for (int i = 1; i <= 10; i++)
{
string str = (i * Convert.ToInt32(total / 10)).ToString();
g.DrawLine(new Pen(c), Point(0, tX * i), Point(oXX, tX * i));//画x
g.DrawLine(new Pen(c), Point(0, tX * i), Point(0 - getCut(), tX * i - getCut()));
g.DrawString(str, new Font("宋体", 9), new SolidBrush(Color.FromArgb(128, 128, 128)), Point(-getCut() - 4 - System.Text.Encoding.Default.GetBytes(str).Length * 6, tX * i - getCut()));
}
g.DrawLine(new Pen(Color.Black), Point(0 - getCut(), 0 - getCut()), Point(0 - getCut(), oYY - getCut()));
g.DrawLine(new Pen(Color.Black), Point(0 - getCut(), 0 - getCut()), Point(oXX - getCut(), -getCut()));
}//初始化表格

void DrawRect(Color c, int tX, int H)
{

int rechH = H;

Color rechC = c;
GraphicsPath path = new GraphicsPath();
Point p1 = Point(tX - Thickness - getCut(), -getCut());
Point p2 = Point(tX - getCut(), -getCut());
Point p3 = Point(tX, 0);
Point p4 = Point(tX - Thickness, 0);
Point p5 = Point(tX - Thickness - getCut(), -getCut() + rechH);
Point p6 = Point(tX - getCut(), -getCut() + rechH);
Point p7 = Point(tX, rechH);
Point p8 = Point(tX - Thickness, rechH);
path.AddLines(new Point[] { p1, p4, p8, p5 ,p1});
fillPath(rechC, path);

path = new GraphicsPath();
path.AddLines(new Point[] { p1, p2, p3, p4,p1 });
fillPath(rechC, path);

path = new GraphicsPath();
path.AddLines(new Point[] { p4, p3, p7, p8,p4 });
fillPath(rechC, path);

path = new GraphicsPath();
path.AddLines(new Point[] { p1, p2, p6, p5 ,p1});
fillPath(rechC, path);

path = new GraphicsPath();
path.AddLines(new Point[] { p2, p3, p7, p6,p2 });
fillPath(rechC, path);

path = new GraphicsPath();
path.AddLines(new Point[] { p5, p6, p7, p8,p5 });
fillPath(rechC, path);
}//画表体
void fillPath(Color c, GraphicsPath path)
{
g.FillPath(new SolidBrush(Color.FromArgb(alpha,c)), path);
g.DrawPath(new Pen(Color.FromArgb(200,128,128,128)), path);
}//填充颜色
public Color getColor(int i)
{
switch (i)
{
case 0: return Color.YellowGreen;
case 2: return Color.Olive;
case 3: return Color.FromArgb(56,147,232);
case 1: return Color.Green;
case 4: return Color.Pink;
case 5: return Color.Plum;
case 6: return Color.Gray;
case 7: return Color.Salmon;
case 8: return Color.RosyBrown;
case 9: return Color.Teal;
case 10: return Color.Orange;
case 11: return Color.Thistle;
case 12: return Color.Maroon;
default: return Color.WhiteSmoke;
}
}
enum Month
{
一月份 = 1,
二月份,
三月份,
四月份,
五月份,
六月份,
七月份,
八月份,
九月份,
十月份,
十一月份,
十二月份
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐