📄 piegraph.cs
字号:
if (this.DrawYTickerText)
{
ptDesc.X -= descSize.Width;
ptDesc.Y -= descSize.Height;
ptData.X = (float)(ptDesc.X + (descSize.Width/2.0 - dataSize.Width/2.0));
// using 3 pixel buffer between desc and data string display
ptData.Y = ptDesc.Y + (descSize.Height);
}
}
ob.SmoothingMode = SmoothingMode.HighQuality;
// Draw the lines.
ob.DrawLine(obPen, pt1, ptAnchor);
ob.DrawLine(obPen, ptAnchor, pt2);
// Draw the strings now.
if (this.DrawYTickerText)
{
ob.DrawString(strTickerDesc, this.m_TickerDescFont, obBrush, ptDesc);
}
ob.DrawString(strData, this.m_TickerDataFont, obBrush, ptData);
}
finally
{
ob.SmoothingMode = sMode;
}
return true;
}
/// <summary>
///
/// </summary>
protected void CalculateDrawingMeasurements()
{
float fRectWidth = 0.0F;
float fRectHeight = 0.0F;
fRectWidth = (this.m_ChartRectangle.Width - ((m_iNumberOfDataIslands - 1)*IslandSpacing))/m_iNumberOfDataIslands;
fRectHeight = this.m_ChartRectangle.Height;
BoundingSquareSize = Math.Min(fRectWidth, fRectHeight);
// Calculate left over height and width;
LeftOverHeight = (float)Math.Round(this.m_ChartRectangle.Height - (BoundingSquareSize));
LeftOverWidth = (float)Math.Round(this.m_ChartRectangle.Width - (m_iNumberOfDataIslands * BoundingSquareSize + (m_iNumberOfDataIslands - 1)*IslandSpacing));
}
/// <summary>
/// Function is used to calculate the span of x and y axis.
/// </summary>
/// <returns></returns>
override protected bool CalculateAxisSpan()
{
//this.m_iXAxisSpan = (int)(this.Width - LeftSpacing - RightSpacing);
//this.m_iYAxisSpan = (int)(this.Height - BottomSpacing - TopSpacing);
m_iXAxisSpan = (int)this.m_ChartRectangle.Width;
m_iYAxisSpan = (int)this.m_ChartRectangle.Height;
return true;
}
/// <summary>
/// The method calculates
/// </summary>
override protected void CalculateLegendsRectangle_V(short nLegendCount)
{
float fHeight = 0.0F;
// If marker height is greater than the max text string height then
// use that to caluclate the rectangle height otherwise use
// maximum text string height.
// Also adjust the legend widths and heights accrodingly.
if (this.m_fMaxLegendTextHeight > m_sLegendHeight)
{
m_sLegendHeight = (short)m_fMaxLegendTextHeight;
m_sLegendWidth = m_sLegendHeight;
}
fHeight += nLegendCount * m_sLegendHeight;
fHeight += nLegendCount * this.m_sVertcalLegendSpacing;
fHeight += 2;
// Width = Buffer + LegendWidth + TextSpacing + MaxTextWidth + Buffer
float fWidth = this.m_sLegendWidth;
fWidth += this.m_sLegendTextSpacing;
fWidth += this.m_fMaxLegendTextWidth;
// TODO: Add bufering attribute to class.
fWidth += 2;
fWidth += 2;
m_LegendRectangle.X = (int)((Width - fWidth)/2.0F);
m_LegendRectangle.Y = (int)(Height - BottomSpacing);
m_LegendRectangle.Width = (int)fWidth;
m_LegendRectangle.Height = (int)fHeight;
}
/// <summary>
///
/// </summary>
override protected void CalculateLegendsRectangle_H(short nLegendCount)
{
float fHeight = 0.0F;
// If marker height is greater than the max text string height then
// use that to caluclate the rectangle height otherwise use
// maximum text string height.
// Also adjust the legend widths and heights accrodingly.
if (this.m_fMaxLegendTextHeight > m_sLegendHeight)
{
m_sLegendHeight = (short)m_fMaxLegendTextHeight;
m_sLegendWidth = m_sLegendHeight;
}
// Width = Buffer + LegendWidth + TextSpacing + MaxTextWidth + Buffer
float fWidth = this.m_sLegendWidth;
fWidth += this.m_sLegendTextSpacing;
fWidth += this.m_fAvgLegendTextWidth;
// TODO: Add bufering attribute to class.
fWidth += 2;
fWidth += 2;
fWidth *= nLegendCount;
// If the total width is more than axis span, switch to
// vertical legend mode.
if (fWidth > this.m_iXAxisSpan)
{
this.LegendAlignment = LegendAlignmentType.Vertical;
CalculateLegendsRectangle_V(nLegendCount);
return;
}
fHeight += m_sLegendHeight;
// TODO: Add attributes for buffers
fHeight += 2;
fHeight += 2;
m_LegendRectangle.X = (int)((Width - fWidth)/2.0F);
m_LegendRectangle.Y = (int)(Height - BottomSpacing);
m_LegendRectangle.Width = (int)fWidth;
m_LegendRectangle.Height = (int)fHeight;
}
/// <summary>
///
/// </summary>
///
/*
override protected bool DrawVerticalLegends()
{
Pen obBorderPen = null;
SolidBrush obBgBrush = null;
SolidBrush obTextBrush = null;
try
{
obBgBrush = new SolidBrush(this.BackgroundColor);
obBorderPen = new Pen(new SolidBrush(Color.Black));
obTextBrush = new SolidBrush(this.m_LegendColor);
//this.m_obGraphics.DrawRectangle(obBorderPen, this.m_LegendRectangle);
DrawingUtil.DrawRectangle(m_obGraphics, obBorderPen, m_LegendRectangle);
this.m_obGraphics.FillRectangle(obBgBrush, this.m_LegendRectangle);
// Now draw the legends.
PointF textPt = new PointF();
int x = (int)m_LegendRectangle.X + 2;
textPt.X = x + this.m_sLegendWidth + this.m_sLegendTextSpacing;
int yStart = (int)m_LegendRectangle.Y + 2;
int y = 0;
for (short i = 0; i < this.m_sLegendCount; i++)
{
y = yStart + i * (this.m_sLegendHeight + this.m_sVertcalLegendSpacing);
textPt.Y = yStart + i * (this.m_sLegendHeight + this.m_sVertcalLegendSpacing);
this.DrawBar(this.m_obGraphics, x, y, this.m_sLegendWidth, this.m_sLegendHeight, 0.0, (Color)this.m_arrColors[i]);
this.m_obGraphics.DrawString(this.m_LegendsList[i], this.m_LegendFont, obTextBrush, textPt);
}
}
catch (Exception ex)
{
Trace.WriteLine(ex.Message);
return false;
}
finally
{
if (null != obBorderPen)
{
obBorderPen.Dispose();
}
if (null != obBgBrush)
{
obBgBrush.Dispose();
}
if (null != obTextBrush)
{
obTextBrush.Dispose();
}
}
return true;
}
*/
/// <summary>
///
/// </summary>
///
/*
override protected bool DrawHorizontalLegends()
{
Pen obBorderPen = null;
SolidBrush obBgBrush = null;
SolidBrush obTextBrush = null;
try
{
obBgBrush = new SolidBrush(this.BackgroundColor);
obBorderPen = new Pen(new SolidBrush(Color.Black));
obTextBrush = new SolidBrush(this.m_LegendColor);
//this.m_obGraphics.DrawRectangle(obBorderPen, this.m_LegendRectangle);
DrawingUtil.DrawRectangle(m_obGraphics, obBorderPen, m_LegendRectangle);
this.m_obGraphics.FillRectangle(obBgBrush, this.m_LegendRectangle);
// Now draw the legends.
PointF textPt = new PointF();
int xStart = (int)m_LegendRectangle.X;
textPt.X = this.m_LegendRectangle.X;
int yStart = (int)m_LegendRectangle.Y + 2;
int iSum = 0;
for (short i = 0; i < this.m_sLegendCount; i++)
{
xStart = (int)m_LegendRectangle.X;
if (i > 0)
{
iSum += ((int)(float)this.m_arrLegendTextWidth[i-1] + m_sLegendTextSpacing);
}
xStart += iSum;
xStart += i * (this.m_sLegendWidth + m_sLegendTextSpacing);
textPt.Y = yStart;
textPt.X = xStart;
this.DrawBar(this.m_obGraphics, xStart, yStart, this.m_sLegendWidth, this.m_sLegendHeight, 0.0, (Color)this.m_arrColors[i]);
textPt.X += (m_sLegendTextSpacing + this.m_sLegendWidth);
this.m_obGraphics.DrawString(this.m_LegendsList[i], this.m_LegendFont, obTextBrush, textPt);
}
}
catch (Exception ex)
{
Trace.WriteLine(ex.Message);
return false;
}
finally
{
if (null != obBorderPen)
{
obBorderPen.Dispose();
}
if (null != obBgBrush)
{
obBgBrush.Dispose();
}
if (null != obTextBrush)
{
obTextBrush.Dispose();
}
}
return true;
}
*/
/// <summary>
///
/// </summary>
/// <param name="strLegend"></param>
/// <param name="obGraphics"></param>
/// <param name="textFont"></param>
/// <param name="txtPt"></param>
/// <param name="dWidth"></param>
/// <param name="color"></param>
/// <returns></returns>
protected bool DrawIslandLegendText(string strLegend,
Graphics obGraphics,
Font textFont,
PointF pt,
float fWidth,
Color color)
{
SolidBrush obTextBrush = null;
PointF textPt = new PointF();
SizeF textSize;
try
{
// Calculate size of text string.
textSize = obGraphics.MeasureString(strLegend, textFont);
obTextBrush = new SolidBrush(color);
textPt.X = pt.X + (fWidth - textSize.Width)/2.0F;
// Draw the legend text 10 pixels above the bounding rectangle of circle.
textPt.Y = (float)(pt.Y - 10 - m_fRadialTickerBuffer);
textPt.Y -= (2*this.m_fMaxLegendTextHeight);
obGraphics.DrawString(strLegend, textFont, obTextBrush, textPt);
}
finally
{
if (null != obTextBrush)
{
obTextBrush.Dispose();
}
}
return true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -