|
//画颜色方块
g.FillRectangle(new SolidBrush(item.Color) , intRectSize * 2 ,
intRectSize * (i * 2 + 1) + m_intHeight / 3 * 2
,intRectSize , intRectSize) ;
//写文字
g.DrawString(intPercent.ToInt32().ToString() + "% " + item.Text ,
new Font("宋体" , intRectSize) ,
new SolidBrush(item.Color) , intRectSize * 4 ,
intRectSize * ( i * 2 + 1) + m_intHeight / 3 * 2) ;
}
}
//清控对象
g.Dispose() ;
//保存为jpg格式
try
{
myBmp.Save(a_strFileName , System.Drawing.Imaging.ImageFormat.JPEG) ;
}
catch(Exception e)
{
throw(new Exception("保存图片失败:" + e.ToString())) ;
}
myBmp.Dispose() ;
}
/// <summary>
/// 画折线图
/// </summary>
/// <param name="a_strFileName"> </param>
protected void DrawCurve(string a_strFileName)
{
//绘图准备,新建一个image对象,一个graphics对象
System.Drawing.Image myBmp = new Bitmap(m_intWidth , m_intHeight ) ;
System.Drawing.Graphics g = Graphics.FromImage(myBmp) ;
//填充背景
g.FillRectangle(new System.Drawing.SolidBrush(m_objBackColor) , 0 , 0 , m_intWidth , m_intHeight) ;
//如果没有任何回答,则显示没有结果
if (this.m_intTotalCount == 0)
{
g.DrawString("没有统计数字!" , new Font("宋体" , m_intWidth / 14) ,
new SolidBrush(Color.Red) , (m_intWidth - m_intWidth / 8 * 6) / 2 ,
m_intHeight / 2 - m_intWidth / 8) ;
}
else
{
//定义一个一个像素宽的黑色的笔
System.Drawing.Pen pen = new System.Drawing.Pen(new System.Drawing.SolidBrush(Color.Black) , 1) ;
//画标志线
g.DrawLine(pen , 0 , 10 , 0 , m_intHeight / 3 * 2 + 10) ;
g.DrawLine(pen , 0 , m_intHeight / 3 * 2 + 10 , m_intWidth , m_intHeight / 3 * 2 + 10) ;
for (int i = 0 ; i < 10 ; i++)
{
g.DrawLine( pen , 0 , m_intHeight / 3 * 2 / 10 * i + 10 , 5 , m_intHeight / 3 * 2 / 10 * i + 10) ;
}
//写单位
g.DrawString("单位:" + m_strUnit , new System.Drawing.Font("宋体" , m_intWidth/40) ,
new SolidBrush(Color.Black) , 10 , 10) ; |
|