|
{
//写题目
//g.DrawString(m_strTitle , new System.Drawing.Font("黑体" , m_intWidth / 30) ,
// new System.Drawing.SolidBrush(Color.Black) , (m_intWidth - m_strTitle.Length * (m_intWidth / 30))/2 , 10 ,
// System.Drawing.StringFormat.GenericDefault) ;
//画统计图项目的矩形
//计算每个矩形的宽度
int intWidth = m_intWidth / (m_arrItems.Count * 2 - 1) ;
//定义一个一个像素宽的黑色的笔
System.Drawing.Pen pen = new System.Drawing.Pen(new System.Drawing.SolidBrush(Color.Black) , 1) ;
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 - 10) ;
//计算矩形坐标
int ix = intWidth * i * 3 / 2 + intWidth ;
int iy = m_intHeight / 3 * 2 - intHeight ;
//画矩形
g.FillRectangle(new System.Drawing.SolidBrush(item.Color) ,
ix , iy , intWidth , intHeight + 10) ;
//写字
//计算字体大小
int intFontSize = intWidth / this.TotalCount.ToString().Length ;
//限制一下,字体大小不能超过12
intFontSize = intFontSize > 12 ? 12 : intFontSize ;
g.DrawString(item.Count.ToString() + m_strUnit ,
new System.Drawing.Font("宋体" , intFontSize) ,
new System.Drawing.SolidBrush(item.Color) ,
ix , iy - intFontSize * 2) ;
//画图例
//计算字体大小
intFontSize = m_intHeight / 3 / m_arrItems.Count / 2 - 1 ;
intFontSize = intFontSize > 12 ? 12 : intFontSize ;
g.FillRectangle(new System.Drawing.SolidBrush(item.Color) , 20 ,
m_intHeight / 3 * 2 + intFontSize * (i * 2 + 1) + 5 ,
intFontSize , intFontSize) ;
g.DrawString( intPercent.ToInt32().ToString() + "%" ,
new System.Drawing.Font("宋体" , intFontSize) ,
new System.Drawing.SolidBrush(item.Color) ,
20 + intFontSize ,
m_intHeight / 3 * 2 + intFontSize * (i * 2 + 1) + 5) ;
g.DrawString(item.Text ,
new System.Drawing.Font("宋体" , intFontSize) ,
new System.Drawing.SolidBrush(item.Color) , 80 ,
m_intHeight / 3 * 2 + intFontSize * (i * 2 + 1) + 5) ;
} |
|