private void DrawLegend(Graphics g, float xCenter, float yCenter,
float hWidth, float hHeight, DataCollection dc, ChartStyle cs)
{
float spacing = 8.0f;
float textHeight = 8.0f;
float htextHeight = textHeight / 2.0f;
float lineLength = 30.0f;
float hlineLength = lineLength / 2.0f;
Rectangle legendRectangle;
Pen aPen = new Pen(LegendBorderColor, 1f);
SolidBrush aBrush = new SolidBrush(LegendBackColor);
if (isLegendVisible)
{
legendRectangle = new Rectangle((int)xCenter - (int)hWidth,
(int)yCenter - (int)hHeight,
(int)(2.0f * hWidth), (int)(2.0f * hHeight));
g.FillRectangle(aBrush, legendRectangle);
if (IsBorderVisible)
{
g.DrawRectangle(aPen, legendRectangle);
}
int n = 1;
foreach (DataSeries ds in dc.DataSeriesList)
{
// Draw lines and symbols:
float xSymbol = legendRectangle.X + spacing + hlineLength;
float xText = legendRectangle.X + 2 * spacing + lineLength;
float yText = legendRectangle.Y + n * spacing + (2 * n - 1) * htextHeight;
aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness);
aPen.DashStyle = ds.LineStyle.Pattern;
PointF ptStart = new PointF(legendRectangle.X + spacing, yText);
PointF ptEnd = new PointF(legendRectangle.X + spacing + lineLength, yText);
g.DrawLine(aPen, ptStart, ptEnd);
//ds.SymbolStyle.DrawSymbol(g, new PointF(xSymbol, yText));
// Draw text:
StringFormat sFormat = new StringFormat();
sFormat.Alignment = StringAlignment.Near;
g.DrawString(ds.SeriesName, LegendFont, new SolidBrush(textColor),
new PointF(xText, yText - 8), sFormat);
n++;
}
}
aPen.Dispose();
aBrush.Dispose();
}