急!!dundas 饼图问题 将数据绑定到dundas上,生成饼图,希望在图形上显示百分比,图例显示条目名称。如何实现,谢谢!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 charthttp://topic.csdn.net/u/20090925/11/38e21f0a-ab85-4fe7-8b9a-bce36b519e8b.html 我用的是dundas,现在一绑定后,要么都是百分数,要么都是条目名称,如何能让图形上显示百分数,图例上是名称? public static void CreatePieChart(Chart chart, List<OrderReportInfo> theList, string title,int height, int width) { chart.Title = title; chart.Width = width; chart.Height = height; Font font = new Font("宋体", 20F, FontStyle.Bold); chart.TitleFont = font; chart.Palette = ChartColorPalette.Tanzanite; chart.BackGradientEndColor = Color.Cornsilk; chart.BorderLineColor = Color.LightSlateGray; chart.BorderLineStyle = ChartDashStyle.Solid; chart.BackGradientType = GradientType.DiagonalRight; ColorConverter color = new ColorConverter(); chart.BackColor = (Color)color.ConvertFromString("#C8D7C8"); chart.ChartAreas.Add("ChartArea1"); Series series = new Series(); series.Type = SeriesChartType.Pie; series.BackGradientEndColor = Color.White; series.BackGradientType = GradientType.TopBottom; series.BorderColor = Color.FromArgb(64, 64, 64); series.Points.DataBindXY(theList, "name", theList, "ordercount"); series.Label = "#VALY笔"; series["PieLabelStyle"] = "Outside"; chart.Series.Add(series); chart.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true; int i = 0; foreach (OrderReportInfo reportInfo in theList) { series.Points[i].LegendText = reportInfo.Name; series.Points[i].ToolTip = "订单状态:" + reportInfo.Name + "\n比例:#PERCENT{P2}"; i++; } } 你这个虽然能显示,但我查询时,不起作用。而且就是LegendText 不断的增加条目 /// <summary> /// 用于绘制日地域分析或月地域分析的饼型图 /// </summary> /// <param name="Total">整型变量,该变量表示总访问人数</param> /// <param name="count">整型变量,该变量表示日地域分析视图或月地域分析视图的IP总数</param> /// <param name="ds">DataSet对象,用于存储日第一分析视图或月地域分析视图的所有信息</param> /// <param name="title">字符串变量,该变量表示标题</param> /// <param name="ipCount">整型变量,该变量表示日或月的IP总数</param> private void createImage(int Total, int count, DataSet ds, string title, int ipCount) { //创建一个整型变量,该变量用于设置颜色提示的换行 int iloop; //设置字体,fonttitle为主标题的字体 Font fontlegend = new Font("verdana", 9), fonttitle = new Font("verdana", 10, FontStyle.Bold); //背景宽 int width = 600; int bufferspace = 15; //颜色提示文字的高度 int legendheight = fontlegend.Height * (count + 1) + bufferspace; // int titleheight = fonttitle.Height + bufferspace; //白色背景高 int height = width + legendheight + titleheight + bufferspace; int pieheight = 300; Rectangle pierect = new Rectangle(0, titleheight, width - 300, pieheight); //加上各种随机色 ArrayList colors = new ArrayList(); Random rnd = new Random(); for (iloop = 0; iloop < ds.Tables[0].Rows.Count; iloop++) colors.Add(new SolidBrush(Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255)))); Bitmap objbitmap = new Bitmap(width, 350); Graphics objgraphics = Graphics.FromImage(objbitmap); //画背景颜色 objgraphics.FillRectangle(new SolidBrush(Color.White), 0, 0, width, height); objgraphics.FillRectangle(new SolidBrush(Color.LightYellow), pierect); SolidBrush blackbrush = new SolidBrush(Color.Black); //以下为画饼图(有几行row画几个) float currentdegree = 0.0f; for (iloop = 0; iloop < ds.Tables[0].Rows.Count; iloop++) { //设置饼型的弧度 float pi = Convert.ToSingle(ds.Tables[0].Rows[iloop]["sumNum"]) / Total * 360; //绘制一个饼型 objgraphics.FillPie((SolidBrush)colors[iloop], pierect, currentdegree, Convert.ToSingle(pi)); //设置饼型的起始位置 currentdegree += Convert.ToSingle(ds.Tables[0].Rows[iloop]["sumNum"]) / Total * 360; } //以下为生成标题给出颜色地域的提示 StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; objgraphics.DrawString(title, fonttitle, blackbrush, new Rectangle(0, 0, width - 300, titleheight), stringFormat); //列出各字段与数目 objgraphics.DrawRectangle(new Pen(Color.Black, 2), 300, 0, width - 300, legendheight); for (iloop = 0; iloop < count; iloop++) { //判断是否以显示两个标题提示 if (iloop % 2 == 0) { //绘制一个矩形 objgraphics.FillRectangle((SolidBrush)colors[iloop], 310, fontlegend.Height * iloop + 7 + fonttitle.Height, 10, 10); //获取地域的名称 string st = ds.Tables[0].Rows[iloop]["placeName"].ToString(); //获取某个IP的访问量 double sd = Convert.ToDouble(ds.Tables[0].Rows[iloop]["sumNum"]); //计算百分比 float ss = Convert.ToSingle(Math.Round(sd * 100 / Total, 2)); //绘制文字该问题用于提示颜色表示的地域名称及该颜色所占的百分比 objgraphics.DrawString(st + " — " + ss + "%", fontlegend, blackbrush,330, fontlegend.Height * iloop + 5 + fonttitle.Height); } else { //绘制一个矩形 objgraphics.FillRectangle((SolidBrush)colors[iloop], 455, fontlegend.Height * (iloop - 1) + 7 + fonttitle.Height, 10, 10); string st = ds.Tables[0].Rows[iloop]["placeName"].ToString(); double sd = Convert.ToDouble(ds.Tables[0].Rows[iloop]["sumNum"]); float ss = Convert.ToSingle(Math.Round(sd * 100 / Total, 2)); //绘制文字该问题用于提示颜色表示的地域名称及该颜色所占的百分比 objgraphics.DrawString(st + " — " + ss + "%", fontlegend, blackbrush, 475, fontlegend.Height * (iloop - 1) + 5 + fonttitle.Height); } } //图像总的高度-一行字体的高度,即是最底行的一行字体高度(height - fontlegend.Height ) objgraphics.DrawString("总IP数为:" + ipCount + "人", fonttitle, blackbrush, 380, 2); objbitmap.Save(Server.MapPath("Images") + "\\r.jpeg"); Image1.ImageUrl = "Images\\r.jpeg?id=" + rnd.Next(9999); objgraphics.Dispose(); objbitmap.Dispose(); } 请教,ASP.NET MVC项目中表单提交避免弹出新窗口的问题 各位大侠快来帮帮我,跪求~急。。。100分赐上~POST数据接收问题 简单的数据截取问题 在线等 VS2003如何进行FTP的操作? 请问datagrid怎么将表头放在左边, 表格内容放在右面? 我的这段代码为什么不执行呢,`???? 帮忙看下哪里错了 版本升级导致无法加载项目? 求助asp CheckBox 传值问题 今次无聊,在线等待别人提问题,提的好的问题给分! aspx页面的<% Register %> ,在CS后台文件,怎样才可动态生成? 按钮复制问题,还是不明白
http://topic.csdn.net/u/20090925/11/38e21f0a-ab85-4fe7-8b9a-bce36b519e8b.html
public static void CreatePieChart(Chart chart, List<OrderReportInfo> theList, string title,int height, int width)
{
chart.Title = title;
chart.Width = width;
chart.Height = height;
Font font = new Font("宋体", 20F, FontStyle.Bold);
chart.TitleFont = font;
chart.Palette = ChartColorPalette.Tanzanite;
chart.BackGradientEndColor = Color.Cornsilk;
chart.BorderLineColor = Color.LightSlateGray;
chart.BorderLineStyle = ChartDashStyle.Solid;
chart.BackGradientType = GradientType.DiagonalRight;
ColorConverter color = new ColorConverter();
chart.BackColor = (Color)color.ConvertFromString("#C8D7C8");
chart.ChartAreas.Add("ChartArea1"); Series series = new Series();
series.Type = SeriesChartType.Pie;
series.BackGradientEndColor = Color.White;
series.BackGradientType = GradientType.TopBottom;
series.BorderColor = Color.FromArgb(64, 64, 64);
series.Points.DataBindXY(theList, "name", theList, "ordercount");
series.Label = "#VALY笔";
series["PieLabelStyle"] = "Outside";
chart.Series.Add(series);
chart.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
int i = 0;
foreach (OrderReportInfo reportInfo in theList)
{
series.Points[i].LegendText = reportInfo.Name;
series.Points[i].ToolTip = "订单状态:" + reportInfo.Name + "\n比例:#PERCENT{P2}";
i++;
}
}
而且就是LegendText 不断的增加条目
/// 用于绘制日地域分析或月地域分析的饼型图
/// </summary>
/// <param name="Total">整型变量,该变量表示总访问人数</param>
/// <param name="count">整型变量,该变量表示日地域分析视图或月地域分析视图的IP总数</param>
/// <param name="ds">DataSet对象,用于存储日第一分析视图或月地域分析视图的所有信息</param>
/// <param name="title">字符串变量,该变量表示标题</param>
/// <param name="ipCount">整型变量,该变量表示日或月的IP总数</param>
private void createImage(int Total, int count, DataSet ds, string title, int ipCount)
{
//创建一个整型变量,该变量用于设置颜色提示的换行
int iloop;
//设置字体,fonttitle为主标题的字体
Font fontlegend = new Font("verdana", 9), fonttitle = new Font("verdana", 10, FontStyle.Bold); //背景宽
int width = 600;
int bufferspace = 15;
//颜色提示文字的高度
int legendheight = fontlegend.Height * (count + 1) + bufferspace;
//
int titleheight = fonttitle.Height + bufferspace;
//白色背景高
int height = width + legendheight + titleheight + bufferspace; int pieheight = 300;
Rectangle pierect = new Rectangle(0, titleheight, width - 300, pieheight); //加上各种随机色
ArrayList colors = new ArrayList();
Random rnd = new Random();
for (iloop = 0; iloop < ds.Tables[0].Rows.Count; iloop++)
colors.Add(new SolidBrush(Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255))));
Bitmap objbitmap = new Bitmap(width, 350);
Graphics objgraphics = Graphics.FromImage(objbitmap); //画背景颜色
objgraphics.FillRectangle(new SolidBrush(Color.White), 0, 0, width, height);
objgraphics.FillRectangle(new SolidBrush(Color.LightYellow), pierect); SolidBrush blackbrush = new SolidBrush(Color.Black);
//以下为画饼图(有几行row画几个)
float currentdegree = 0.0f;
for (iloop = 0; iloop < ds.Tables[0].Rows.Count; iloop++)
{
//设置饼型的弧度
float pi = Convert.ToSingle(ds.Tables[0].Rows[iloop]["sumNum"]) / Total * 360;
//绘制一个饼型
objgraphics.FillPie((SolidBrush)colors[iloop], pierect, currentdegree, Convert.ToSingle(pi));
//设置饼型的起始位置
currentdegree += Convert.ToSingle(ds.Tables[0].Rows[iloop]["sumNum"]) / Total * 360; }
//以下为生成标题给出颜色地域的提示
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
objgraphics.DrawString(title, fonttitle, blackbrush,
new Rectangle(0, 0, width - 300, titleheight), stringFormat);
//列出各字段与数目
objgraphics.DrawRectangle(new Pen(Color.Black, 2), 300, 0, width - 300, legendheight); for (iloop = 0; iloop < count; iloop++)
{
//判断是否以显示两个标题提示
if (iloop % 2 == 0)
{
//绘制一个矩形
objgraphics.FillRectangle((SolidBrush)colors[iloop], 310, fontlegend.Height * iloop + 7 + fonttitle.Height, 10, 10);
//获取地域的名称
string st = ds.Tables[0].Rows[iloop]["placeName"].ToString();
//获取某个IP的访问量
double sd = Convert.ToDouble(ds.Tables[0].Rows[iloop]["sumNum"]);
//计算百分比
float ss = Convert.ToSingle(Math.Round(sd * 100 / Total, 2));
//绘制文字该问题用于提示颜色表示的地域名称及该颜色所占的百分比
objgraphics.DrawString(st + " — " + ss + "%", fontlegend, blackbrush,330, fontlegend.Height * iloop + 5 + fonttitle.Height);
}
else
{
//绘制一个矩形
objgraphics.FillRectangle((SolidBrush)colors[iloop], 455, fontlegend.Height * (iloop - 1) + 7 + fonttitle.Height, 10, 10);
string st = ds.Tables[0].Rows[iloop]["placeName"].ToString();
double sd = Convert.ToDouble(ds.Tables[0].Rows[iloop]["sumNum"]);
float ss = Convert.ToSingle(Math.Round(sd * 100 / Total, 2));
//绘制文字该问题用于提示颜色表示的地域名称及该颜色所占的百分比
objgraphics.DrawString(st + " — " + ss + "%", fontlegend, blackbrush, 475, fontlegend.Height * (iloop - 1) + 5 + fonttitle.Height);
} }
//图像总的高度-一行字体的高度,即是最底行的一行字体高度(height - fontlegend.Height ) objgraphics.DrawString("总IP数为:" + ipCount + "人", fonttitle, blackbrush, 380, 2); objbitmap.Save(Server.MapPath("Images") + "\\r.jpeg");
Image1.ImageUrl = "Images\\r.jpeg?id=" + rnd.Next(9999); objgraphics.Dispose();
objbitmap.Dispose();
}