public void AddPie(Graphics g, ChartStyle cs)
{
SolidBrush aBrush = new SolidBrush(Color.Black);
Pen aPen = new Pen(BorderColor);
int nData = DataList.Count;
float fSum = 0;
for (int i = 0; i < nData; i++)
{
fSum = fSum + (float)DataList[i];
}
float startAngle = 0;
float sweepAngle = 0;
Rectangle rect = cs.SetPieArea();
for (int i = 0; i < nData; i++)
{
Color fillColor = Color.FromArgb(CMap[i, 0], CMap[i, 1],
CMap[i, 2], CMap[i, 3]);
aBrush = new SolidBrush(fillColor);
int explode = (int)ExplodeList[i];
if (fSum < 1)
{
startAngle = startAngle + sweepAngle;
sweepAngle = 360 * (float)DataList[i];
}
else if (fSum >= 1)
{
startAngle = startAngle + sweepAngle;
sweepAngle = 360 * (float)DataList[i] / fSum;
}
int xshift = (int)(explode * Math.Cos((startAngle +
sweepAngle / 2) * Math.PI / 180));
int yshift = (int)(explode * Math.Sin((startAngle +
sweepAngle / 2) * Math.PI / 180));
Rectangle rect1 = new Rectangle(rect.X + xshift, rect.Y + yshift,
rect.Width, rect.Height);
g.FillPie(aBrush, rect1, startAngle, sweepAngle);
g.DrawPie(aPen, rect1, startAngle, sweepAngle);
}
}