C#窗体绘制条形图

本文展示了如何在C#窗体中利用PictureBox控件绘制条形图,包括具体步骤和代码实现。文章提供的代码示例是静态数据,可用于初步测试,实际应用时可动态调整数据以获得更精确的图表。
摘要由CSDN通过智能技术生成

效果 图:

添加一个PictureBox控件代码:

 // 绘制柱状统计图的完整代码
        private void CreateExaminationBarChart()
        {
            int height = 500, width = 700;
            Bitmap bitmap = new Bitmap(width, height);
            //创建Graphics类对象 
            Graphics g = Graphics.FromImage(bitmap);


          
            try
            {
                //清空图片背景色 
                g.Clear(Color.White);

                Font font = new Font("Arial", 10, FontStyle.Regular);
                Font font1 = new Font("宋体", 20, FontStyle.Bold);

                LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                Color.Blue, Color.BlueViolet, 1.2f, true);
                g.FillRectangle(Brushes.WhiteSmoke, 0, 0, width, height);
                // Brush brush1 = new SolidBrush(Color.Blue);

                g.DrawString("2020年考试" +
                " 成绩统计柱状图", font1, brush, new PointF(70, 30));
                //画图片的边框线 
                g.DrawRectangle(new Pen(Color.Blue), 0, 0, bitmap.Width - 1, bitmap.Height - 1);

                Pen mypen = new Pen(brush, 1);
                //绘制线条 
                //绘制横向线条 
                int x = 100;
                for (int i = 0; i < 14; i++)
                {
                    g.DrawLine(mypen, x, 80, x, 340);
                    x = x + 40;
                }
                Pen mypen1 = 
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

试行

祝您生活愉快!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值