簡體   English   中英

在餅圖中隱藏標簽(MS Chart for.Net)

[英]Hide labels in pie charts (MS Chart for .Net)

丑陋的餅圖

我似乎找不到控制餅圖中標簽可見性的屬性。 我需要關閉標簽,因為圖例中提供了信息。

任何人都知道我可以在代碼后面使用什么屬性?

我嘗試將系列標簽設置為Chart1.Series[i].Label = string.Empty; 但標簽似乎無論如何都會出現。

Chart1.Series[i]["PieLabelStyle"] = "Disabled";

也適用,不需要為每個數據點設置。

在這里找到答案: http//social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/thread/32ccd993-5f43-47a3-bcbc-e772a13a87fe

事實證明,有一個名為PieLabelStyle的模糊DataPointCustomProperty控制餅圖中的標簽可見性。 更糟糕的是,必須在每個數據點上設置屬性。

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";

更改圖表自定義屬性也可以解決問題,無需編碼

<asp:Series Name="Series1" ChartType="Pie" CustomProperties="PieLabelStyle=Disabled">

可能是這個網站解決了你的問題

protected void Page_Load(object sender,EventArgs e){
//插入代碼以創建基本餅圖//查看我的博客文章“ASP.NET中的餅圖”以獲取完整的源代碼

     // 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-piechar

...和Ben的VB.NET格式答案:

Chart1.Series(0)("PieLabelStyle") = "Disabled"

適用於設置整個系列

objChart.ChartAreas[0].AxisY.LabelStyle.Enabled = false;

這也可以在UI中完成

  1. 打開系列編輯器窗口(主屬性面板中的省略號按鈕)
  2. 選擇想要的系列
  3. 擴展CustomProperties屬性
  4. 選擇Disabled

例

對於 C#,以下代碼適用於系列中的所有點。

chart1.Series[seriesname]["PieLabelStyle"] = "Disabled";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM