动态创建mschart饼图不显示图块区域,请各位大虾帮忙!!

zhengxy22 2010-01-12 11:07:20

Chart chart = new Chart();
// Add series to the chart
Series series = chart.Series.Add("My series");


// Set series visual attributes
series.ChartType = SeriesChartType.Pie;
series.ShadowOffset = 4;
series.Font = new Font("Times New Format", 7f);
series.BorderColor = Color.DarkGray;

//series.CustomAttributes = "LabelStyle=Outside";

series.ToolTip = "#LEGENDTEXT: #VAL{C} million";
series.LegendToolTip = "#PERCENT";
series.PostBackValue = "#INDEX";
series.LegendPostBackValue = "#INDEX";
chart.Titles.Add("test");
chart.Titles[0].Text = "早餐前(空腹)";

// Populate series data
double[] yValues = { 7, 2, 5, 11};
string[] xValues = { "理想", "较好", "差(高血糖)", "差(低血糖)"};
series.Points.DataBindY(yValues);

for (int pointIndex = 0; pointIndex < series.Points.Count; pointIndex++)
{
series.Points[pointIndex].LegendText = xValues[pointIndex];
}

if (!this.IsPostBack)
{
series.Points[0].CustomProperties += "Exploded=true";
}
Controls.Add(chart);

问题出在哪?
...全文
433 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ljlne 2010-06-30
  • 打赏
  • 举报
回复
大哥 怎么动态创建 Chart 能把你改好的代码贴出来不?我创建之后是空白的,也不报错
zhengxy22 2010-01-12
  • 打赏
  • 举报
回复
那我要在旁边显示每个颜色表示什么,那要添加什么?
zhengxy22 2010-01-12
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wo6522317 的回复:]
你添加的顺序有问题;
系列(Series)-> 区域(Area)-> 图表控件(Chart)->UI
改正的代码:
C# code
Chart chart=new Chart();// Add chartArea to the chartChartArea chartArea=new ChartArea("myChartArea");// Add series to the chartSeries series=new Series("My series");//..........//.........chart.ChartAreas.Add(chartArea);
chart.Series.Add(series);
Controls.Add(chart);
[/Quote]
谢谢高手,解决了,给分了
jshi123 2010-01-12
  • 打赏
  • 举报
回复
没有区域,在最后加上
chart.ChartAreas.Add("My area");
koukoujiayi 2010-01-12
  • 打赏
  • 举报
回复
是不是Legends的不显示?若是,以下代码可显示:
Chart1.Legends.Add("Series1");
wo6522317 2010-01-12
  • 打赏
  • 举报
回复
你添加的顺序有问题;
系列(Series)-> 区域(Area)-> 图表控件(Chart)->UI
改正的代码:

Chart chart = new Chart();
// Add chartArea to the chart
ChartArea chartArea = new ChartArea("myChartArea");
// Add series to the chart
Series series = new Series("My series");
//..........
//.........
chart.ChartAreas.Add(chartArea);
chart.Series.Add(series);
Controls.Add(chart);
zhengxy22 2010-01-12
  • 打赏
  • 举报
回复
竟然没有人知道吗
zhengxy22 2010-01-12
  • 打赏
  • 举报
回复
没有人知道吗
wo6522317 2010-01-12
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 zhengxy22 的回复:]
那我要在旁边显示每个颜色表示什么,那要添加什么?
[/Quote]
加入代码:
Legend legend = new Legend("my Legend");            
chart.Legends.Add(legend);

可以默认生成 与图片相对应的 图列标签;
自定义的话使用
图例中的一个(LegendItem)小图例中3个表示(LegendCell)
1,图片 2,颜色表示 3, 显示文本;

62,046

社区成员

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

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

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

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