博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MS Chart Control 學習手記(二) - 圓餅圖
阅读量:5932 次
发布时间:2019-06-19

本文共 3433 字,大约阅读时间需要 11 分钟。

using System.Web.UI.DataVisualization.Charting;
02 using System.Drawing;
03  
04 namespace Chart.AJAX
05 {
06     public partial class Export_AJAX : System.Web.UI.Page
07     {
08         void CreateChart()
09         {
10             string[] xValues = { "0-20""20-30""30-40""40-50""50-60""> 60""unknow" };
11             int[] yValues = {5, 18, 45, 17, 2, 1, 162 };
12  
13             //ChartAreas,Series,Legends 基本設定-------------------------------------------------
14             Chart Chart1 = new Chart();
15             Chart1.ChartAreas.Add("ChartArea1"); //圖表區域集合
16             Chart1.Legends.Add("Legends1"); //圖例集合說明
17             Chart1.Series.Add("Series1"); //數據序列集合
18  
19             //設定 Chart-------------------------------------------------------------------------
20             Chart1.Width = 770;
21             Chart1.Height = 400;
22             Title title = new Title();
23             title.Text = titleStr;
24             title.Alignment = ContentAlignment.MiddleCenter;
25             title.Font = new System.Drawing.Font("Trebuchet MS", 14F, FontStyle.Bold);
26             Chart1.Titles.Add(title);
27  
28             //設定 ChartArea1--------------------------------------------------------------------
29             Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = is3D;
30             Chart1.ChartAreas[0].AxisX.Interval = 1;
31  
32             //設定 Legends-------------------------------------------------------------------------               
33             //Chart1.Legends["Legends1"].DockedToChartArea = "ChartArea1"; //顯示在圖表內
34             //Chart1.Legends["Legends1"].Docking = Docking.Bottom; //自訂顯示位置
35             //背景色
36             Chart1.Legends["Legends1"].BackColor = Color.FromArgb(235, 235, 235);
37             //斜線背景
38             Chart1.Legends["Legends1"].BackHatchStyle = ChartHatchStyle.DarkDownwardDiagonal;
39             Chart1.Legends["Legends1"].BorderWidth = 1;
40             Chart1.Legends["Legends1"].BorderColor = Color.FromArgb(200, 200, 200);
41  
42             //設定 Series1-----------------------------------------------------------------------
43             Chart1.Series["Series1"].ChartType = SeriesChartType.Pie;
44             //Chart1.Series["Series1"].ChartType = SeriesChartType.Doughnut;
45             Chart1.Series["Series1"].Points.DataBindXY(xValues, yValues);
46             Chart1.Series["Series1"].LegendText = "#VALX:    [ #PERCENT{P1} ]"//X軸 + 百分比
47             Chart1.Series["Series1"].Label = "#VALX\n#PERCENT{P1}"//X軸 + 百分比
48             //Chart1.Series["Series1"].LabelForeColor = Color.FromArgb(0, 90, 255); //字體顏色
49             //字體設定
50             Chart1.Series["Series1"].Font = new System.Drawing.Font("Trebuchet MS", 10, System.Drawing.FontStyle.Bold);
51             Chart1.Series["Series1"].Points.FindMaxByValue().LabelForeColor = Color.Red;
52             //Chart1.Series["Series1"].Points.FindMaxByValue().Color = Color.Red;
53             //Chart1.Series["Series1"].Points.FindMaxByValue()["Exploded"] = "true";
54             Chart1.Series["Series1"].BorderColor = Color.FromArgb(255, 101, 101, 101);
55              
56             //Chart1.Series["Series1"]["DoughnutRadius"] = "80"; // ChartType為Doughnut時,Set Doughnut hole size
57             //Chart1.Series["Series1"]["PieLabelStyle"] = "Inside"; //數值顯示在圓餅內
58             Chart1.Series["Series1"]["PieLabelStyle"] = "Outside"//數值顯示在圓餅外
59             //Chart1.Series["Series1"]["PieLabelStyle"] = "Disabled"; //不顯示數值
60             //設定圓餅效果,除 Default 外其他效果3D不適用
61             Chart1.Series["Series1"]["PieDrawingStyle"] = "Default";
62             //Chart1.Series["Series1"]["PieDrawingStyle"] = "SoftEdge";
63             //Chart1.Series["Series1"]["PieDrawingStyle"] = "Concave";
64  
65             //Random rnd = new Random();  //亂數產生區塊顏色
66             //foreach (DataPoint point in Chart1.Series["Series1"].Points)
67             //{
68             //    //pie 顏色
69             //    point.Color = Color.FromArgb(150, rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255));
70             //}
71             Page.Controls.Add(Chart1); 
72         }
73     }
74 }

 

畫出來的圓餅圖就像這樣

转载地址:http://gnktx.baihongyu.com/

你可能感兴趣的文章
《信息存储与管理(第二版):数字信息的存储、管理和保护》—— 2.8 主机对数据的访问...
查看>>
什么是阿里云数加大数据计算服务MaxCompute?
查看>>
《Docker全攻略》书评
查看>>
SQL 多条件查询去掉影响效率的where 1=1
查看>>
android universal image loader 缓冲原理详解
查看>>
C语言程序设计实践(OJ)-用循环解决问题
查看>>
饿了么Redis Cluster集群化演进
查看>>
第七章 Python异常处理
查看>>
数据结构例程——线索化二叉树(中序)
查看>>
Java安全——密钥那些事
查看>>
[翻译] getauxval() and the auxiliary vector
查看>>
项目特质与设计开发流程的策略选择
查看>>
小程序弹性Web之旅
查看>>
[喵咪Golang(1)]Go语言开篇
查看>>
SQL Server存储过程
查看>>
HTML 控制密码框的可见和隐藏
查看>>
pg_cancel_backend()和pg_terminate_backend()
查看>>
Java Web之网络通讯
查看>>
SVG实例之中国地图
查看>>
css3选择器(一)
查看>>