我找不到控制饼图标签可见性的属性。我需要将标签关闭,因为信息已经在图例中提供。
有人知道我可以在代码后台中使用哪个属性吗?
我尝试将系列标签设置为 string.Empty;
但是标签似乎仍然显示出来。
我找不到控制饼图标签可见性的属性。我需要将标签关闭,因为信息已经在图例中提供。
有人知道我可以在代码后台中使用哪个属性吗?
我尝试将系列标签设置为 string.Empty;
但是标签似乎仍然显示出来。
Chart1.Series[i]["PieLabelStyle"] = "Disabled";
这也可以工作,而且不需要为每个数据点设置。
<asp:Series Name="Series1" ChartType="Pie" CustomProperties="PieLabelStyle=Disabled">
for (var i = 0; i < chart.Series.Count; i++)
for (var j = 0; j < chart.Series[i].Points.Count; j++)
chart.Series[i].Points[j]["PieLabelStyle"] = "Disabled";
...并且Ben的答案是VB.NET格式:
Chart1.Series(0)("PieLabelStyle") = "Disabled"
对于设置整个系列来说,这个功能表现良好。
// Set pie labels to be outside the pie chart
this.Chart2.Series[0]["PieLabelStyle"] = "Outside";
// Set border width so that labels are shown on the outside
this.Chart2.Series[0].BorderWidth = 1;
this.Chart2.Series[0].BorderColor = System.Drawing.Color.FromArgb(26, 59, 105);
// Add a legend to the chart and dock it to the bottom-center
this.Chart2.Legends.Add("Legend1");
this.Chart2.Legends[0].Enabled = true;
this.Chart2.Legends[0].Docking = Docking.Bottom;
this.Chart2.Legends[0].Alignment = System.Drawing.StringAlignment.Center;
// Set the legend to display pie chart values as percentages
// Again, the P2 indicates a precision of 2 decimals
this.Chart2.Series[0].LegendText = "#PERCENT{P2}";
// By sorting the data points, they show up in proper ascending order in the legend
this.Chart2.DataManipulator.Sort(PointSortOrder.Descending, Chart2.Series[0]);
}
还可以访问这个网站,我也是从那个网站上获取了这段代码。那里有一个非常好的教程关于使用mscharts显示百分比。
http://betterdashboards.wordpress.com/2009/02/04/display-percentages-on-a-pie-char对于C#,以下代码适用于系列中的所有点。
chart1.Series[seriesname]["PieLabelStyle"] = "Disabled";
objChart.ChartAreas[0].AxisY.LabelStyle.Enabled = false;