private void SetPlotArea(Graphics g)
{
// Set PlotArea:
float xOffset = ChartArea.Width / 30.0f;
float yOffset = ChartArea.Height / 30.0f;
SizeF labelFontSize = g.MeasureString("A", LabelFont);
SizeF titleFontSize = g.MeasureString("A", TitleFont);
if (Title.ToUpper() == "NO TITLE")
{
titleFontSize.Width = 8f;
titleFontSize.Height = 8f;
}
float xSpacing = xOffset / 3.0f;
float ySpacing = yOffset / 3.0f;
SizeF tickFontSize = g.MeasureString("A", TickFont);
float tickSpacing = 2f;
SizeF yTickSize = g.MeasureString(YLimMin.ToString(), TickFont);
for (float yTick = YLimMin; yTick <= YLimMax; yTick += YTick)
{
SizeF tempSize = g.MeasureString(yTick.ToString(), TickFont);
if (yTickSize.Width < tempSize.Width)
{
yTickSize = tempSize;
}
}
float leftMargin = xOffset + labelFontSize.Width +
xSpacing + yTickSize.Width + tickSpacing;
float rightMargin = xOffset;
float topMargin = yOffset + titleFontSize.Height + ySpacing;
float bottomMargin = yOffset + labelFontSize.Height +
ySpacing + tickSpacing + tickFontSize.Height;
if (!IsY2Axis)
{
// Define the plot area with one Y axis:
int plotX = ChartArea.X + (int)leftMargin;
int plotY = ChartArea.Y + (int)topMargin;
int plotWidth = ChartArea.Width - (int)leftMargin - 2 * (int)rightMargin;
int plotHeight = ChartArea.Height - (int)topMargin - (int)bottomMargin;
PlotArea = new Rectangle(plotX, plotY, plotWidth, plotHeight);
}
else
{
// Define the plot area with Y and Y2 axes:
SizeF y2TickSize = g.MeasureString(Y2LimMin.ToString(), TickFont);
for (float y2Tick = Y2LimMin; y2Tick <= Y2LimMax; y2Tick += Y2Tick)
{
SizeF tempSize2 = g.MeasureString(y2Tick.ToString(), TickFont);
if (y2TickSize.Width < tempSize2.Width)
{
y2TickSize = tempSize2;
}
}
rightMargin = xOffset + labelFontSize.Width +
xSpacing + y2TickSize.Width + tickSpacing;
int plotX = ChartArea.X + (int)leftMargin;
int plotY = ChartArea.Y + (int)topMargin;
int plotWidth = ChartArea.Width - (int)leftMargin - (int)rightMargin;
int plotHeight = ChartArea.Height - (int)topMargin - (int)bottomMargin;
PlotArea = new Rectangle(plotX, plotY, plotWidth, plotHeight);
}
}