|
/// <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) ;
//画折线
//计算宽度
int intWidth = m_intWidth / (m_arrItems.Count * 2) ;
//定义两个变量,记住上一个点的x , y
int ix = 0 ;
int iy = 0 ;
for ( int i = 0 ; i < m_arrItems.Count ; i ++)
{
ChartItem item = (ChartItem)m_arrItems ;
//计算所占百分比
float intPercent = (float)Decimal.Divide(item.Count * 100 , m_intTotalCount) ;
//计算点高度
int intHeight = (int)(m_intHeight / 3 * 2 * intPercent / 100) ;
//画点
g.FillEllipse(new SolidBrush(item.Color) , intWidth * (i * 2 + 1) ,
m_intHeight / 3 * 2 - intHeight , 10 , 10) |
|