public void AddChartStyle(Graphics g)
{
// Draw TotalChartArea, ChartArea, and PlotArea:
SetPlotArea(g);
Pen aPen = new Pen(ChartBorderColor, 1f);
SolidBrush aBrush = new SolidBrush(ChartBackColor);
g.FillRectangle(aBrush, ChartArea);
g.DrawRectangle(aPen, ChartArea);
aPen = new Pen(PlotBorderColor, 1f);
aBrush = new SolidBrush(PlotBackColor);
g.FillRectangle(aBrush, PlotArea);
g.DrawRectangle(aPen, PlotArea);
SizeF tickFontSize = g.MeasureString("A", TickFont);
// Create vertical gridlines:
float fX, fY;
if (IsYGrid == true)
{
aPen = new Pen(GridColor, 1f);
aPen.DashStyle = GridPattern;
for (fX = XLimMin + XTick; fX < XLimMax; fX += XTick)
{
g.DrawLine(aPen, Point2D(new PointF(fX, YLimMin)),
Point2D(new PointF(fX, YLimMax)));
}
}
// Create horizontal gridlines:
if (IsXGrid == true)
{
aPen = new Pen(GridColor, 1f);
aPen.DashStyle = GridPattern;
for (fY = YLimMin + YTick; fY < YLimMax; fY += YTick)
{
g.DrawLine(aPen, Point2D(new PointF(XLimMin, fY)),
Point2D(new PointF(XLimMax, fY)));
}
}
// Create the x-axis tick marks:
aBrush = new SolidBrush(TickFontColor);
for (fX = XLimMin; fX <= XLimMax; fX += XTick)
{
PointF yAxisPoint = Point2D(new PointF(fX, YLimMin));
g.DrawLine(Pens.Black, yAxisPoint, new PointF(yAxisPoint.X,
yAxisPoint.Y - 5f));
StringFormat sFormat = new StringFormat();
sFormat.Alignment = StringAlignment.Far;
SizeF sizeXTick = g.MeasureString(fX.ToString(), TickFont);
g.DrawString(fX.ToString(), TickFont, aBrush,
new PointF(yAxisPoint.X + sizeXTick.Width / 2,
yAxisPoint.Y + 4f), sFormat);
}
// Create the y-axis tick marks:
for (fY = YLimMin; fY <= YLimMax; fY += YTick)
{
PointF xAxisPoint = Point2D(new PointF(XLimMin, fY));
g.DrawLine(Pens.Black, xAxisPoint,
new PointF(xAxisPoint.X + 5f, xAxisPoint.Y));
StringFormat sFormat = new StringFormat();
sFormat.Alignment = StringAlignment.Far;
g.DrawString(fY.ToString(), TickFont, aBrush,
new PointF(xAxisPoint.X - 3f,
xAxisPoint.Y - tickFontSize.Height / 2), sFormat);
}
// Create the y2-axis tick marks:
if (IsY2Axis)
{
for (fY = Y2LimMin; fY <= Y2LimMax; fY += Y2Tick)
{
PointF x2AxisPoint = Point2DY2(new PointF(XLimMax, fY));
g.DrawLine(Pens.Black, x2AxisPoint,
new PointF(x2AxisPoint.X - 5f, x2AxisPoint.Y));
StringFormat sFormat = new StringFormat();
sFormat.Alignment = StringAlignment.Near;
g.DrawString(fY.ToString(), TickFont, aBrush,
new PointF(x2AxisPoint.X + 3f,
x2AxisPoint.Y - tickFontSize.Height / 2), sFormat);
}
}
aPen.Dispose();
aBrush.Dispose();
AddLabels(g);
}