# 问个GDI+的问题

0

实际的过程当中已经控制图片大小为1100*400

Model:

```    public partial class ST_Histogram
{
/// <summary>
/// 时间
/// </summary>
public DateTime X { get; set; }

/// <summary>
/// 降雨量
/// </summary>
public float Y { get; set; }
}```

list:

```List<ST_Histogram> list =

``` //获取数据量,X轴上的数据量,从数据库获取数据已经控制为24条数据
int count = list.Count();```

Random rand = new Random(Guid.NewGuid().GetHashCode());
Pen pen;
float xDistance = 1000 / count;

``` for (int i = 0; i < count; i++)
{
//画刻度线
g.DrawLine(blackPen, 50f + xDistance * i, 350f, 50f + xDistance * i, 355f);
//画虚线
if (i != 0)
g.DrawLine(sliverPen, 50f + xDistance * i, 350f, 50f + xDistance * i, 100f);
//画标签
g.DrawString(list[i].X.Hour.ToString() + "时", normalFont, blackBrush, 40f + xDistance * i, 357f);
//画柱状图
pen = new Pen(Color.FromArgb(rand.Next(255), rand.Next(255), rand.Next(255)), xDistance);
if (list[i].Y != 0)
{
float x1 = 50f + ((TimeSpan)(list[i].X - list[0].X)).Hours * xDistance + xDistance / 2;
float y1 = 350f;
float x2 = x1;
float y2 = y1 - list[i].Y * yDistance;
g.DrawLine(pen, x1, y1, x2, y2);
}
}```

FreeSaber | 初学一级 | 园豆：85

您需要登录以后才能回答，未注册用户请先注册