折线图
http://202.109.105.148:31415/verifycode/buildchart.aspx?charttype=2&XCollection=Mary,Tom,Jacky,Landy&YCollection=45,66,60,80;70,44,70,73;68,90,66,35&mWidth=400&mHeight=300&YMin=0&YMax=100&YColName=Term1,Term2,Term3&chartname=My%20Chart柱状图
http://202.109.105.148:31415/verifycode/buildchart.aspx?charttype=3&XCollection=Mary,Tom,Jacky,Landy&YCollection=45,66,60,80;70,44,70,73;68,90,66,35&mWidth=400&mHeight=300&YMin=0&YMax=100&YColName=Term1,Term2,Term3&chartname=My%20Chart饼图
http://202.109.105.148:31415/verifycode/buildchart.aspx?charttype=1如需要2D效果,则相应增加if3D=false
http://202.109.105.148:31415/verifycode/buildchart.aspx?charttype=2&XCollection=Mary,Tom,Jacky,Landy&YCollection=45,66,60,80;70,44,70,73;68,90,66,35&mWidth=400&mHeight=300&YMin=0&YMax=100&YColName=Term1,Term2,Term3&chartname=My%20Chart柱状图
http://202.109.105.148:31415/verifycode/buildchart.aspx?charttype=3&XCollection=Mary,Tom,Jacky,Landy&YCollection=45,66,60,80;70,44,70,73;68,90,66,35&mWidth=400&mHeight=300&YMin=0&YMax=100&YColName=Term1,Term2,Term3&chartname=My%20Chart饼图
http://202.109.105.148:31415/verifycode/buildchart.aspx?charttype=1如需要2D效果,则相应增加if3D=false
charttype=4
我有个问题:
http://community.csdn.net/Expert/topic/3553/3553456.xml?temp=.376034
psLibBase.ClsBuildChart tmp = new psLibBase.ClsBuildChart();
tmp.ChartNameSize=11;
tmp.fontFamily="宋体";
tmp.chartYBuffer=40;
tmp.XYSize=9;
MemoryStream stmp = tmp.MakePieChart("红色,橙色,黄色,绿色,兰色,紫色,颜色一,颜色二,颜色三,testPie,color4,color5,color6"
,"10,20,15,8,11,15,25,8,8,18,10,5,15"
,"测试"
,450
,320);
Image frmimage = new Bitmap(stmp);
pictureBox1.Width=450;
pictureBox1.Height=320;
pictureBox1.Image = frmimage;
一个图中用两种方法表示,呵呵,为什么不用两个图呢,如上面代码中
建立两个pictureBox和两个Image就可以了啊,这样还可以把位置调整
成自己所要的位置wntpfi(宗)
我的MSN:[email protected]
FORM的左上方是折线图,左下方是柱状图,右边是一个显
示数据用的DataGrid,这样就可以组合成你要的东东了~
<%
Response.ContentType="image/png"
set test = server.createobject("psLibBase.ClsBuildChart")
Dim objStream
set objStream = test.MakeLineChart("红色,橙色,黄色,绿色,兰色,紫色,颜色一,颜色二,颜色三,testPie,color4,color5,color6,color7,color8,color9","100000,200000,150000,80000,110000,150000,250000,80000,80000,180000,100000,50000,150000,60000,170000,80000.5","测试",700,320,"单位(万)",true,"{0:N0}")
Response.BinaryWrite objStream.ToArray()
%>
public MemoryStream MakePieChart(string XCollection,string YCollection,string ChartName,
int mWidth,int mHeight,float XYScale)
{
int btBuffer=3;
float descBuffer=mWidth/4;
float height3D;
string[] splitX,splitY;
splitX = XCollection.Split(',');
splitY = YCollection.Split(',');
try
{
System.Drawing.Bitmap img;
Graphics g;
MemoryStream ms;
img = new Bitmap(mWidth,mHeight);
g = Graphics.FromImage(img); descBuffer=15+2*btBuffer+g.MeasureString(GetMaxLengthString(XCollection),
new Font(fontFamily,ChartNameSize)).Width; System.Drawing.Drawing2D.LinearGradientBrush lineartmp;
lineartmp = new System.Drawing.Drawing2D.LinearGradientBrush(new Point(mWidth,0),
new Point(mWidth,mHeight),
Color.SkyBlue,
Color.LightYellow);
g.FillRectangle(lineartmp,0,0,mWidth,mHeight); g.DrawString(ChartName,new Font(fontFamily,ChartNameSize),new SolidBrush(Color.Red),3,3); System.Drawing.Rectangle pieRect = new Rectangle(
Convert.ToInt16(g.MeasureString(GetMaxLengthString(XCollection),
new Font(fontFamily,ChartNameSize)).Width+2*btBuffer),
Convert.ToInt16(mHeight*0.1875),
Convert.ToInt16(mHeight*0.725),
Convert.ToInt16(mHeight*0.725/XYScale));
float pieAngle=0,lastAngle=0; height3D=pieRect.Width/8;
System.Drawing.Rectangle pieRect2 = new Rectangle(
Convert.ToInt16(g.MeasureString(GetMaxLengthString(XCollection),
new Font(fontFamily,ChartNameSize)).Width+2*btBuffer),
Convert.ToInt16(mHeight*0.1875+height3D),
Convert.ToInt16(mHeight*0.725),
Convert.ToInt16(mHeight*0.725/XYScale)); System.Drawing.Region tmpRegion,tmpRegion2;
System.Drawing.Drawing2D.GraphicsPath tmpPath = new System.Drawing.Drawing2D.GraphicsPath();
tmpPath.AddPie(pieRect2,0,180);
tmpRegion = new Region(tmpPath); tmpPath = new System.Drawing.Drawing2D.GraphicsPath();
tmpPath.AddPie(pieRect,0,180);
tmpRegion2 = new Region(tmpPath); if(XYScale>1)
g.DrawPie(new Pen(Color.Black,2),pieRect2,0,180); float descX=mWidth-descBuffer-10;
float descY=10; Single totalVal=0;
for(int i=0;i<splitY.Length;i++)
{
totalVal += Convert.ToSingle(splitY[i]);
}
if(totalVal==0)
totalVal=1; Font strFont = new Font(fontFamily,XYSize);
System.Drawing.Pen piePen = new Pen(Color.Black);
g.FillRectangle(new SolidBrush(Color.LightYellow),descX,descY,descBuffer,
Convert.ToInt16(splitX.Length*(g.MeasureString(splitX[0],strFont).Height+1))+2*btBuffer);
g.DrawRectangle(piePen,descX,descY,descBuffer,
Convert.ToInt16(splitX.Length*(g.MeasureString(splitX[0],strFont).Height+1))+2*btBuffer); float rectX = pieRect.Left+pieRect.Width;
float rectW = 0F;
for(int i=0;i<splitY.Length;i++)
{ pieAngle = Convert.ToSingle(Convert.ToSingle(splitY[i])*360/totalVal); System.Drawing.SolidBrush pieBrush;
if(colorName.Length>=i+1)
pieBrush = new SolidBrush(Color.FromName(colorName[i]));
else
{
pieBrush = new SolidBrush(Color.FromArgb(0,0,0));
switch(i%3)
{
case 0:
pieBrush = new SolidBrush
(Color.FromArgb((i-colorName.Length+1)*255/(splitY.Length-colorName.Length),
255,255));
break;
case 1:
pieBrush = new SolidBrush
(Color.FromArgb(255,
(i-colorName.Length+1)*255/(splitY.Length-colorName.Length),255));
break;
case 2:
pieBrush = new SolidBrush
(Color.FromArgb(255,255,
(i-colorName.Length+1)*255/(splitY.Length-colorName.Length)));
break;
}
} if((lastAngle+pieAngle)>180)
{
rectW = rectX - pieRect.Left;
rectX = pieRect.Left;
}
else
{
rectW = rectX -
Convert.ToSingle(pieRect.Left+pieRect.Width/2+
GetXFromRoundL(pieRect.Width/2,pieRect.Height/2,pieAngle,lastAngle));
rectX = Convert.ToSingle(pieRect.Left+pieRect.Width/2+
GetXFromRoundL(pieRect.Width/2,pieRect.Height/2,pieAngle,lastAngle));
}
System.Drawing.RectangleF tmpRect = new RectangleF(rectX,pieRect.Top+pieRect.Height/2,rectW-0.5F,mHeight);
System.Drawing.RectangleF tmpRectSmall = new RectangleF(rectX,pieRect.Top+pieRect.Height/2,rectW-0.5F,height3D+1);
System.Drawing.Region recRegion = new Region(tmpRect);
{
recRegion.Intersect(tmpRegion); recRegion.Exclude(tmpRegion2);
g.FillRegion(pieBrush,recRegion);
recRegion = new Region(tmpRectSmall);
recRegion.Exclude(tmpRegion2);
g.FillRegion(pieBrush,recRegion);
float lineFromX,lineFromY,lineToX,lineToY;
lineFromX = rectX;
lineFromY = pieRect.Top+pieRect.Height/2+
GetYFromRoundL(rectX-pieRect.Left-pieRect.Width/2,pieAngle,lastAngle);
lineToX = lineFromX;
lineToY = lineFromY+height3D; if(i==0)
{
g.DrawLine(new Pen(Color.Black),
pieRect.Left+pieRect.Width,
pieRect.Top+pieRect.Height/2,
pieRect.Left+pieRect.Width,
pieRect.Top+pieRect.Height/2+height3D);
}
if(lastAngle+pieAngle<=180)
g.DrawLine(new Pen(Color.Black),lineFromX,lineFromY,lineToX,lineToY);
}
if(XYScale>1&&i==splitX.Length-1)
{
g.DrawLine(new Pen(Color.Black),
pieRect.Left,
pieRect.Top+pieRect.Height/2,
pieRect.Left,
pieRect.Top+pieRect.Height/2+height3D);
} g.FillPie(pieBrush,pieRect,lastAngle,pieAngle);
g.DrawPie(new Pen(Color.Black),pieRect,lastAngle,pieAngle);
piePen = new Pen(Color.White);
System.Drawing.Point fromPoint;
System.Drawing.Point toPoint; float fromPX0 = GetXFromRound(pieRect.Width/2,pieRect.Height/2,pieAngle,lastAngle);
int fromPX = Convert.ToInt16(pieRect.X+pieRect.Width/2+fromPX0);
int fromPY = Convert.ToInt16(pieRect.Y+pieRect.Height/2+
GetYFromRound(fromPX0,pieAngle,lastAngle));
if(XYScale>1&&(lastAngle+pieAngle/2)<=180)
fromPY+=Convert.ToInt16(height3D); float toPX0 = GetXFromRound(pieRect.Width/2+5,(pieRect.Width/2+5)/XYScale,pieAngle,lastAngle);
int toPX = Convert.ToInt16(pieRect.X+pieRect.Width/2+toPX0);
int toPY = Convert.ToInt16(pieRect.Y+pieRect.Height/2+
GetYFromRound(toPX0,pieAngle,lastAngle));
if(XYScale>1&&(lastAngle+pieAngle/2)<=180)
toPY+=Convert.ToInt16(height3D); fromPoint = new Point(fromPX,fromPY);
toPoint = new Point(toPX,toPY);
g.DrawLine(piePen,fromPoint,toPoint); piePen = new Pen(Color.Black);
float distance=0;
distance = Convert.ToInt16(g.MeasureString(splitX[i],strFont).Width);
float brX,brY,brW,brH;
if((lastAngle+pieAngle/2)<=90)
{
brX = toPX;
brY = toPY;
}
else if((lastAngle+pieAngle/2)>90&&(lastAngle+pieAngle/2)<=180)
{
brX = toPX-distance;
brY = toPY;
}
else if((lastAngle+pieAngle/2)>180&&(lastAngle+pieAngle/2)<=270)
{
brX = toPX-distance;
brY = toPY-g.MeasureString(splitX[i],strFont).Height;
}
else
{
brX = toPX;
brY = toPY-g.MeasureString(splitX[i],strFont).Height;
} brW = distance+1;
brH = g.MeasureString(splitX[0],strFont).Height; g.FillRectangle(new SolidBrush(Color.LightYellow),brX,brY,brW,brH);
g.DrawRectangle(piePen,brX,brY,brW,brH);
g.DrawString(splitX[i],strFont,new SolidBrush(Color.Black),
brX+1,brY+2); g.FillRectangle(pieBrush,descX+btBuffer,descY+btBuffer,15,brH-1);
g.DrawRectangle(new Pen(Color.Black),descX+btBuffer,descY+btBuffer,15,brH-1); g.DrawString(splitX[i],strFont,new SolidBrush(Color.Black),
descX+20+2*btBuffer,
descY+btBuffer);
descY += brH+1;
lastAngle += pieAngle;
piePen.Dispose();
}
strFont.Dispose();
ms = new MemoryStream();
img.Save(ms,ImageFormat.Png);
g.Dispose();
img.Dispose();
return ms;
}
catch
{
return MakeNullChart("您输入的数据有误!");
}
}