效果 图:
添加一个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 =