• 2021/10/11

1  private void LineChart()
 2         {//定义绘图用到的类
 3             int height = 480, width = 700;
 4             Bitmap image = new Bitmap(width, height);
 5             Graphics g = Graphics.FromImage(image);
 6             try
 7             {
 8                 g.Clear(Color.White);                //清空图片背景***r>  9                 Font font = new Font("Arial", 9, FontStyle.Regular);
10                 Font font1 = new Font("宋体", 20, FontStyle.Regular);
11                 Font font2 = new Font("Arial", 8, FontStyle.Regular);
12                 LinearGradientBrush brush = new LinearGradientBrush(
13                 new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.Blue, 1.2f, true);
14                 g.FillRectangle(Brushes.AliceBlue, 0, 0, width, height);
15                 Brush brush1 = new SolidBrush(Color.Blue);
16                 Brush brush2 = new SolidBrush(Color.SaddleBrown);
17 
18                 g.DrawString("挂点数统计折线图", font1, brush1, new PointF(85, 30));
19                 //画图片的边框线
20                 g.DrawRectangle(new Pen(Color.Blue), 0, 0, image.Width - 1, image.Height - 1);
21 
22                 Pen mypen = new Pen(brush, 1);
23                 //绘制线条
24                 //绘制纵向线条
25                 int x = 60;
26                 for (int i = 0; i < dtResult.Rows.Count; i++)
27                 {
28                     g.DrawLine(mypen, x, 80, x, 340);
29                     x = x + 80;
30                 }
31                 Pen mypen1 = new Pen(Color.Blue, 3);
32                 x = 60;
33                 g.DrawLine(mypen1, x, 82, x, 340);
34 
35                 //绘制横向线条
36                 int y = 106;
37                 for (int i = 0; i < 10; i++)
38                 {
39                     g.DrawLine(mypen, 60, y, 620, y);
40                     y = y + 26;
41                 }
42                 // y = 106;
43                 g.DrawLine(mypen1, 60, y - 26, 620, y - 26);
44 
45                 //x轴
46                 string[] n = { "A", "B", "C", "D", "E", "F", "G" };
47                 x = 45;
48                 for (int i = 0; i < 7; i++)
49                 {
50                     g.DrawString(n[i].ToString(), font, Brushes.Red, x, 348); //设置文字内容及输出位置
51                     x = x + 77;
52                 }
53 
54                 //y轴
55                 String[] m = { "220", " 200", " 175", "150", " 125", " 100", " 75", " 50", " 25人" };
56                 y = 100;
57                 for (int i = 0; i < 9; i++)
58                 {
59                     g.DrawString(m[i].ToString(), font, Brushes.Red, 10, y); //设置文字内容及输出位置
60                     y = y + 26;
61                 }
62 
63                 int[] Count = new int[dtResult.Rows.Count];
64                 //挂点数
65                 for (int i = 0; i < dtResult.Rows.Count; i++)
66                 {
67                     Count[i] = Convert.ToInt32(dtResult.Rows[i]["Point"].ToString());
68                 }
69 
70                 //显示折线效果
71                 Font font3 = new System.Drawing.Font("Arial", 10, FontStyle.Bold);
72                 SolidBrush mybrush = new SolidBrush(Color.Red);
73                 Point[] points1 = new Point[7];
74                 points1[0].X = 60; points1[0].Y = 340 - Count[0]; //从106纵坐标开始, 到(0, 0)坐标时
75                 points1[1].X = 140; points1[1].Y = 340 - Count[1];
76                 points1[2].X = 220; points1[2].Y = 340 - Count[2];
77                 points1[3].X = 300; points1[3].Y = 340 - Count[3];
78                 g.DrawLines(mypen, points1); //绘制折线
79 
80                 Pen mypen3 = new Pen(Color.Green, 2);
81                 MemoryStream ms = new System.IO.MemoryStream();
82                 image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
83                 Response.ClearContent();
84                 Response.BinaryWrite(ms.ToArray());
85             }
86             finally
87             {
88                 g.Dispose();
89                 image.Dispose();
90             }
91         }

private void LineChart(

  • 2021/10/12
  1. 在图表中显示数据,其中ASP.NET网页 (Razor) | Microsoft Docs
  • 2021/10/1
  • 2021/10/1
  • 2021/10/1
  • 2021/10/1
  • 2021/10/1
  • 2021/10/1
  • 2021/10/1
  • 2021/10/1
  • 2021/10/1
  • 2021/10/1