制作報表的時候結果出現畫紅線處的信息太散,
如果沒必要全部顯示出來,我們可以使用這種效果:
注意和前面的區分,這個功能叫做Collect Pie Slices(收集分區)
要實現此功能,應先了解相關信息
1.收集的閥值(Collected Threshold)
比如這張圖我們設置當百分比小于多少5%時集中。
2.集合區要顯示的文本(Collected Label)
比如我們這里集合區域(餅狀圖綠色部分)內顯示的Other
3.圖例文本(標簽)(CollectedLegendText)
即我們餅狀圖的圖例(右上角),顯示的文本
4.合并區域顯示的顏色(CollectedColor)
效果
5.合并后的區域是否突出(CollectedSliceExploded)
效果:
6.效果:
實現紅線處上面為數量,下面為所占百分比:
var servers = Chart1.Series[0];servers.Label = "#VAL/r/n#PERCENT{P1}";
實例:
html:
<asp:Chart ID="Chart1" runat="server" Palette="BrightPastel" BackColor="#D3DFF0" BorderDashStyle="Solid" BackSecondaryColor="White" BackGradientStyle="TopBottom" BorderWidth="2" BorderColor="26, 59, 105" ImageLocation="~/TempImages/ChartPic_#SEQ(300,3)" ImageType="Png"> <Titles> <asp:Title ShadowColor="32, 0, 0, 0" Font="Trebuchet MS, 14.25pt, style=Bold" ShadowOffset="3" Text="Pie Chart" Name="Title1" ForeColor="26, 59, 105"></asp:Title> </Titles> <Legends> <asp:Legend Name="Default" BackColor="Transparent" Font="Trebuchet MS, 8.25pt, style=Bold" Enabled="True" ></asp:Legend> </Legends> <BorderSkin SkinStyle="Emboss"></BorderSkin> <Series> <asp:Series Name="Default" ChartType="Pie" XValueType="Double" BorderColor="180, 26, 59, 105" ShadowOffset="5" Font="Trebuchet MS, 8.25pt, style=Bold" YValueType="Double" ></asp:Series> </Series> <ChartAreas> <asp:ChartArea Name="ChartArea1" BorderColor="64, 64, 64, 64" BackSecondaryColor="White" BackColor="Transparent" ShadowColor="" BorderWidth="0"> <Area3DStyle Rotation="10" Perspective="10" Inclination="15" IsRightAngleAxes="False" WallWidth="0" IsClustered="False"></Area3DStyle> <AxisY LineColor="64, 64, 64, 64"> <LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" /> <MajorGrid LineColor="64, 64, 64, 64" /> </AxisY> <AxisX LineColor="64, 64, 64, 64"> <LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" /> <MajorGrid LineColor="64, 64, 64, 64" /> </AxisX> </asp:ChartArea> </ChartAreas> </asp:Chart>
后臺代碼:
PRotected void Page_Load(object sender, EventArgs e) { // Create pie chart helper class, pieHelper = new PieCollectedDataHelper(Chart1); pieHelper.CollectedLabel = String.Empty; // Set chart type ,設置圖標類型,餅狀圖Pie 環裝圖:Doughnut //Chart1.Series["Default"].ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), ChartTypeList.SelectedItem.Text, true); Chart1.Series["Default"].ChartType = SeriesChartType.Pie; // Set chart type and title //需要配合Titles Chart1.Titles[0].Text = "后整產量" + " Chart"; //ShowLegend顯示標簽,Disabled隱藏 Inside內部顯示,Outside外部顯示 Chart1.Series["Default"]["PieLabelStyle"] = "Outside"; // Set Doughnut hole size,甜甜圈寬度,,只有當 Chart1.Series["Default"].ChartType=="Doughnut"才生效 Chart1.Series["Default"]["DoughnutRadius"] = "60"; //Docking //需要配合Legends //調整Legends位置 Chart1.Legends[0].Docking = Docking.Bottom; //Alignment="Center" Docking="Bottom" IsTextAutoFit="False" LegendStyle="Row" //LegendStyle // Enable 3D Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false; //甜甜圈圖樣式Default SoftEdge Concave,,當啟動3D模式時設置不生效 Chart1.Series[0]["PieDrawingStyle"] = "SoftEdge"; //// Pie drawing style //if (this.CheckboxShow3D.Checked) // this.Dropdownlist1.Enabled = false; //else // this.Dropdownlist1.Enabled = true; // Populate series data double[] yValues = { 9042, 558, 2160, 4051, 2151, 1761 }; string[] xValues = { "A64", "A65", "A66", "A67", "A68", "A69"}; DataTable dt = CreateData(); var v = ToList<HZProducte>(dt); //double[] yValues = { 65.62, 2.1, 85.73, 11.42, 34.45, 75.54, 5.7, 4.1 }; //string[] xValues = { "France", "Japan", "USA", "Italy", "Germany", "Canada", "Russia", "Spain" }; //具有綁定規則的其他數據點屬性,格式為:PointProperty=Field[{Format}] [,PointProperty=Field[{Format}]]。例如:“Tooltip=Price{C1},Url=WebSiteName”。 //Chart1.Series["Default"].Points.DataBindXY(xValues, yValues);<!--Label="#PERCENT{P1}-->" /* MSChart的Label的值的轉義符,如下: #VALX 顯示當前圖例的X軸的對應文本(或數據) #VAL, #VALY, 顯示當前圖例的Y軸的對應文本(或數據) #VALY2, #VALY3, 顯示當前圖例的輔助Y軸的對應文本(或數據) #SER: 顯示當前圖例的名稱 #LABEL 顯示當前圖例的標簽文本 #INDEX 顯示當前圖例的索引 #PERCENT 顯示當前圖例的所占的百分比 #TOTAL 總數量 #LEGENDTEXT 圖例文本 當LegendText為#AXISLABEL時,如果Label為#PERCENT,并且綁定的ValueMember為數值時,LegendText顯示的和Label一樣,存在Bug。 */ var servers = Chart1.Series[0]; servers.Label = "#VAL/r/n#PERCENT{P1}"; //Chart1.DataSource = dt; //servers.XValueMember = "CenterName"; //servers.YValueMembers = "Qty"; //servers.LegendText = "#VALX"; //Chart1.DataBind(); //servers.LabelBackColor = Color.Red; //servers.LabelUrl = "http://www.baidu.com"; servers.Points.DataBind(v, "CenterName", "Qty
新聞熱點
疑難解答