WinForm"立體餅狀圖實現(附原始碼示例)" 之配餐系統的開發
阿新 • • 發佈:2020-10-21
本文所要將的是在“配餐系統”開發中 立體餅狀圖效果的實現,直接貼出程式碼和附上示例,相信需要的朋友可以很容易使用!專案中的效果圖,如下:
實現 應用的是 System.Drawing.PieChart.PieChartControl 控制元件, PieChartHelper類如下:
程式碼 using System;using System.Collections;
using System.Drawing;
using System.Text;
///<summary>
/// 立體餅狀圖操作類
///</summary>
publicclass PieChartHelper
{
///<summary>
/// 餅狀圖初始化設定
///</summary>
///<param name="pieChart"></param>
publicstaticvoid Init_PieChart(System.Drawing.PieChart.PieChartControl pieChart)
{
pieChart.EdgeColorType = System.Drawing.PieChart.EdgeColorType.Contrast;
pieChart.EdgeLineWidth =1;//設定餅塊的邊框線的寬度
//餅狀圖(上下左右)距離邊框(PieChart控制元件的邊框)都為5
pieChart.LeftMargin = 5f;
pieChart.RightMargin = 5f;
pieChart.TopMargin = 5f;
pieChart.BottomMargin = 5f;
pieChart.FitChart =true;
pieChart.SliceRelativeHeight =0.15f;//設定餅塊的厚(高)度
pieChart.InitialAngle =30;
pieChart.ShadowStyle = System.Drawing.PieChart.ShadowStyle.GradualShadow;
pieChart.BackColor = System.Drawing.Color.Transparent;
///<summary>
/// 設定餅狀圖各項對應的值
///</summary>
///<param name="pieChart"></param>
///<param name="valArray"></param>
publicstaticvoid SetPieChartControl_Values(System.Drawing.PieChart.PieChartControl pieChart, decimal[] valArray)
{
pieChart.Values = valArray;
}
///<summary>
/// 設定餅狀圖各項對應的顏色
///</summary>
///<param name="pieChart"></param>
///<param name="colArray"></param>
publicstaticvoid SetPieChartControl_Colors(System.Drawing.PieChart.PieChartControl pieChart, Color[] colArray)
{
ArrayList colors =new ArrayList();
foreach (Color col in colArray)
{
colors.Add(Color.FromArgb(125, col));
}
pieChart.Colors = (Color[])colors.ToArray(typeof(Color)); ;
}
///<summary>
/// 設定餅狀圖各項對應的文字
///</summary>
///<param name="pieChart"></param>
///<param name="textArray"></param>
publicstaticvoid SetPieChartControl_Texts(System.Drawing.PieChart.PieChartControl pieChart, string[] textArray)
{
pieChart.Texts = textArray;
}
///<summary>
/// 設定餅狀圖各項對應的文字提示
///</summary>
///<param name="pieChart"></param>
///<param name="tipArray"></param>
publicstaticvoid SetPieChartControl_ToolTips(System.Drawing.PieChart.PieChartControl pieChart, string[] tipArray)
{
pieChart.ToolTips = tipArray;
}
}
原始碼示例下載
轉載於:https://blog.51cto.com/springsmile/1362780