Chart 图表 柱图

15 篇文章 0 订阅

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

MyChart.Series.Clear();
                    //Chart
                    var series = new Series();

                    series.Label = "#VAL";
                    series.LegendText = "金额(单位:元)";
                    series.Color = Color.Green;
                    series.YValueMembers = "ProductMoney";
                    series.XValueMember = "ProductName";

                    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"].BorderColor = Color.Black;
                    MyChart.ChartAreas["ChartArea1"].BorderWidth = 1;
                    MyChart.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false;
                    MyChart.ChartAreas[0].AxisX.Interval = 1;
                    MyChart.ChartAreas[0].AxisX.IntervalOffset = 1;

                    MyChart.ChartAreas[0].AxisX.LabelStyle.IsStaggered = true;
                    MyChart.ChartAreas[0].AxisX.LabelStyle.Angle = 89;
                    MyChart.ChartAreas[0].AxisX.LabelStyle.Font = new System.Drawing.Font("微软雅黑", 9F);
                    //MyChart.ChartAreas[0].AxisX.LabelStyle.

                    //背景色
                    //MyChart.Legends["Legends1"]. = "金额";
                    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.ChartAreas["ChartArea1"].AxisY.TitleFont = new Font("微软雅黑", float.Parse("8"), FontStyle.Regular);
                    MyChart.ChartAreas["ChartArea1"].AxisY.TitleForeColor = Color.FromName("Black");
                    MyChart.ChartAreas["ChartArea1"].AxisY.Title = "销售额";
                    MyChart.ChartAreas["ChartArea1"].AxisX.TitleFont = new Font("微软雅黑", float.Parse("8"), FontStyle.Regular);
                    MyChart.ChartAreas["ChartArea1"].AxisX.TitleForeColor = Color.FromName("Black");
                    MyChart.ChartAreas["ChartArea1"].AxisX.Title = "产品名称";



                    MyChart.DataSource = list;
                    MyChart.DataBind();

                    //初始化柱子颜色 
                    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];
                    }

效果图:




                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值