16,472
社区成员
发帖
与我相关
我的任务
分享
//draw small parts
int xCenter = m_rcArea.X + m_rcArea.Width / 2;
int yCenter = m_rcArea.Y + m_rcArea.Height / 2;
int B = m_rcArea.Height / 2;
int A = m_rcArea.Width / 2;
PointF lastPt((REAL)A,0);
REAL lastAngel = 0; //上次累加的角度
REAL angel = 0; //本次角度
REAL totalPer = 0; //累加百分比
REAL totalRadians = 0; //累加弧度
//m_vecUNIT只有一个值和颜色信息
for (unsigned int i = 0 ; i < m_vecUNIT.size() ; ++i)
{
//m_dTotal是整个饼图的值
angel = m_vecUNIT[i]->dPercent * 360 / m_dTotal;
totalPer += m_vecUNIT[i]->dPercent;
if (totalPer >= m_dTotal)
{
return ;
}
totalRadians = totalPer * 2 * PIE / m_dTotal ;
path1.Reset();
path1.AddLine((REAL)xCenter,(REAL)yCenter,(REAL)lastPt.X + (REAL)xCenter,(REAL)lastPt.Y + (REAL)yCenter);
path1.AddArc(m_rcArea,lastAngel, angel);
float endX = (REAL)A * cos(totalRadians) + (REAL)xCenter;
float endY = (REAL)B * sin(totalRadians) + (REAL)yCenter;
path1.AddLine((REAL)A * cos(totalRadians) + (REAL)xCenter,(REAL)B * sin(totalRadians) + (REAL)yCenter,(REAL)xCenter,(REAL)yCenter);
path1.CloseAllFigures();
g.DrawPath(&Pen(m_vecUNIT[i]->crContent),&path1);
BYTE crR = m_vecUNIT[i]->crContent.GetR();
BYTE crG = m_vecUNIT[i]->crContent.GetG();
BYTE crB = m_vecUNIT[i]->crContent.GetB();
// g.FillPath(&LinearGradientBrush(m_rcArea,Color(128,crR,crG ,crB ),Color(255,crR ,crG ,crB ),270,LinearGradientModeBackwardDiagonal),&path1);
lastPt.X = A * cos(totalRadians) ;
lastPt.Y = B * sin(totalRadians) ;
lastAngel = totalPer * 360 / m_dTotal;
}