Chart 图表 饼图

15 篇文章 0 订阅

以下是一些关于饼图的显示代码:

MyChart.Series.Clear();
                    //饼状图
                    MyChart.DataSource = list;
                    string[] xValues = new string[list.Count];//X轴数据,即显示文字
                    decimal[] yValues = new decimal[list.Count];//Y轴数据,即金额
                    for (int i = 0; i < list.Count; i++)
                    {
                        xValues[i] = list[i].ProductName;
                        yValues[i] = list[i].productMoney;
                    }
                    var series = new Series();
                    series.ChartType = SeriesChartType.Pie;
                    series.CustomProperties = "PieDrawingStyle=SoftEdge,PieLabelStyle=Enabled,DoughnutRadius=60";
                    series["PieLabelStyle"] = "Outside"; //设置文字显示在外
                    series["PieLineColor"] = "Black";

                    series.Points.DataBindXY(xValues, yValues);


                    series.Label = "#VALX:[#PERCENT{p1}]"; //设置图例显示
                    series.LegendText = "#VALX:#VAL";

                    MyChart.Series.Add(series);


                    //标题
                    var title = new Title();
                    title.Text = "销售概况";
                    title.Alignment = ContentAlignment.MiddleCenter;
                    title.Font = new System.Drawing.Font("Trebuchet MS", 14F, FontStyle.Bold);
                    MyChart.Titles.Add(title);

                    //ChartArea1
                    MyChart.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//3D模式
                    MyChart.ChartAreas[0].AxisX.Interval = 1;

                    //背景色
                    MyChart.Legends["Legends1"].BackColor = Color.FromArgb(235, 235, 235);


                    //斜線背景
                    MyChart.Legends["Legends1"].BackHatchStyle = ChartHatchStyle.DarkDownwardDiagonal;
                    MyChart.Legends["Legends1"].BorderWidth = 1;
                    MyChart.Legends["Legends1"].BorderColor = Color.FromArgb(200, 200, 200);

                    //字體設定
                    //MyChart.Series["Series1"].Font = new Font("Trebuchet MS",10,System.Drawing.FontStyle.Bold);
                    MyChart.Series["Series1"].Points.FindMaxByValue().LabelForeColor = Color.Red;
                    MyChart.Series["Series1"].BorderColor = Color.FromArgb(255, 101, 101, 101);
                    //MyChart.Series["Series1"]["PieDrawingStyle"] = "Default";


                    //初始化柱子颜色 
                    Color[] colorValues = new Color[] {Color.IndianRed, Color.DarkTurquoise, Color.Red, Color.SlateGray, Color.Gold, Color.Green, Color.Indigo, Color.MediumOrchid};

                    for (int i = 0; i < MyChart.Series[0].Points.Count; i++)
                    {
                        MyChart.Series[0].Points[i].Color = colorValues[i];
                    }

效果图:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值