问题描述
我在wpf中用chart画了个饼图当其中数据源中只有一个值得时候饼图不能显示出来求指教
解决方案
解决方案二:
没有大神吗难道
解决方案三:
求图,求代码,这个好像很简单的,我刚做,dotnetcharting做得
解决方案四:
web项目里面运用的
解决方案五:
利用饼图分析人力资源情况示例privatevoidCreateImage(){//连数据库SqlConnectionCon=newSqlConnection(ConfigurationManager.AppSettings["ConSql"]);Con.Open();stringstr1="select*fromtb_manpower";SqlCommandCom=newSqlCommand(str1,Con);DataSetds=newDataSet();SqlDataAdapterDa=newSqlDataAdapter(Com);Da.Fill(ds);Con.Close();//计算员工总和stringstr2="SELECTSUM(Employee+SellMan+Director+Manager)ASNumberFROMtb_manpower";SqlDataAdapterDa2=newSqlDataAdapter(str2,Con);DataSetds2=newDataSet();Da2.Fill(ds2);intSum=Convert.ToInt32(ds2.Tables[0].Rows[0][0].ToString());//获取普通员工数目intemployee=Convert.ToInt32(ds.Tables[0].Rows[0][1].ToString());//获取销售员工数目intsellman=Convert.ToInt32(ds.Tables[0].Rows[0][2].ToString());//获取主任数目intdirector=Convert.ToInt32(ds.Tables[0].Rows[0][3].ToString());//获取经理数目intmanager=Convert.ToInt32(ds.Tables[0].Rows[0][4].ToString());//创建画图对象intwidth=400,height=450;Bitmapbitmap=newBitmap(width,height);Graphicsg=Graphics.FromImage(bitmap);try{//清空背景色g.Clear(Color.White);Penpen1=newPen(Color.Red);Brushbrush1=newSolidBrush(Color.YellowGreen);Brushbrush2=newSolidBrush(Color.Blue);Brushbrush3=newSolidBrush(Color.Brown);Fontfont1=newFont("CourierNew",16,FontStyle.Bold);Fontfont2=newFont("CourierNew",8);g.FillRectangle(brush1,0,0,width,height);//绘制背景图g.DrawString("公司人力资源饼形图",font1,brush2,newPoint(80,20));//书写标题//普通员工在饼形图中分配的角度floatangle1=Convert.ToSingle((360/Convert.ToSingle(Sum))*Convert.ToSingle(employee));//销售员工在饼形图中分配的角度floatangle2=Convert.ToSingle((360/Convert.ToSingle(Sum))*Convert.ToSingle(sellman));//主任在饼形图中分配的角度floatangle3=Convert.ToSingle((360/Convert.ToSingle(Sum))*Convert.ToSingle(director));//经理在饼形图中分配的角度floatangle4=Convert.ToSingle((360/Convert.ToSingle(Sum))*Convert.ToSingle(manager));g.FillPie(Brushes.Beige,50,100,100,100,0,360);g.FillPie(brush2,50,100,100,100,0,angle1);//绘制普通员工所占比例g.FillRectangle(brush2,50,220,20,10);//绘制小矩形g.DrawString("普通员工"+Convert.ToSingle(employee)*100/Convert.ToSingle(Sum)+"%",font2,brush2,80,220);g.FillPie(Brushes.Beige,200,100,100,100,0,360);g.FillPie(brush3,200,100,100,100,0,angle2);//绘制销售员工所占比例g.FillRectangle(brush3,200,220,20,10);//绘制小矩形g.DrawString("销售员工"+Convert.ToSingle(sellman)*100/Convert.ToSingle(Sum)+"%",font2,brush3,230,220);g.FillPie(Brushes.Beige,50,260,100,100,0,360);g.FillPie(Brushes.BlueViolet,50,260,100,100,0,angle3);//绘制普通员工所占比例g.FillRectangle(Brushes.BlueViolet,50,380,20,10);//绘制小矩形g.DrawString("主任"+Convert.ToSingle(director)*100/Convert.ToSingle(Sum)+"%",font2,Brushes.BlueViolet,80,380);g.FillPie(Brushes.Beige,200,260,100,100,0,360);g.FillPie(Brushes.Black,200,260,100,100,0,angle4);//绘制销售员工所占比例g.FillRectangle(Brushes.Black,200,380,20,10);//绘制小矩形g.DrawString("经理"+Convert.ToSingle(manager)*100/Convert.ToSingle(Sum)+"%",font2,Brushes.Black,230,380);}//codego.net/tags/1/1/catch(Exceptionmd){Response.Write(md.Message);}System.IO.MemoryStreamms=newSystem.IO.MemoryStream();bitmap.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);Response.ClearContent();Response.ContentType="image/Gif";Response.BinaryWrite(ms.ToArray());}