📄 chartbox.cs
字号:
{
switch (childNodes[i].Name)
{
case "title":
try
{
this.mTitle = Helpers.SafeXMLToText(childNodes[i].InnerText);
}
catch (Exception){}
break;
case "xLabel":
try
{
this.mXLabel = Helpers.SafeXMLToText(childNodes[i].InnerText);
}
catch (Exception){}
break;
case "labelFont":
try
{
this.mLabelFont = Helpers.ResolveFont( childNodes[i] );
}
catch (Exception){}
break;
case "titleFont":
try
{
this.mTitleFont = Helpers.ResolveFont( childNodes[i] );
}
catch (Exception){}
break;
case "mapAreaColor":
try
{
this.mMapAreaColor = Color.FromName(childNodes[i].InnerText) ;
}
catch (Exception){}
break;
case "showLegend":
try
{
this.mShowLegend = Convert.ToBoolean(childNodes[i].InnerText) ;
}
catch (Exception){}
break;
case "border":
try
{
this.mBorderColor = Color.FromName( childNodes[i].Attributes["color"].Value );
this.mBorderWidth = childNodes[i].Attributes["width"]==null ? 0 : Convert.ToInt32( childNodes[i].Attributes["width"].Value );
}
catch (Exception){}
break;
}
}
}
/// <summary>
/// Gets the region of the current ChartBox
/// </summary>
/// <returns>System.Drawing.Rectangle</returns>
public override Rectangle GetRegion()
{
return mRegion;
}
/// <summary>
/// Gets or sets the height of the ChartBox
/// </summary>
[Description("The height of the element.")]
public override int Height
{
get {return mRegion.Height;}
set
{
if (this.VerticalAlignment == ICustomPaint.VerticalAlignmentTypes.None || this.VerticalAlignment == ICustomPaint.VerticalAlignmentTypes.Top)
mRegion.Height = value;
else if (this.VerticalAlignment == ICustomPaint.VerticalAlignmentTypes.Bottom)
{
mRegion.Y = mRegion.Y - value + mRegion.Height;
mRegion.Height = value;
}
else if (this.VerticalAlignment == ICustomPaint.VerticalAlignmentTypes.Middle)
{
mRegion.Y = mRegion.Y - value/2 + mRegion.Height/2;
mRegion.Height = value;
}
}
}
/// <summary>
/// Gets or sets the ChartBox's repeatability over multiple pages
/// </summary>
/// <remarks>
/// The ChartBox's repeatability setting governs how whether it is repeated
/// over multiple pages, only on the first page, or only on the last page.
/// </remarks>
[Description("This controls repeatability of the ChartBox over multiple pages.")]
public override ICustomPaint.ObjectRepeatabilityTypes ObjectRepeatability
{
get
{
return this.objectRepeatability;
}
set
{
this.objectRepeatability = value;
}
}
/// <summary>
/// Paints the ChartBox
/// </summary>
/// <param name="g">The Graphics object to draw</param>
/// <remarks>Causes the ChartBox to be painted to the screen.</remarks>
public override void Paint(Graphics g)
{
if ( mChartType == ChartType.Bar)
drawBarsDiagram(g);
else if ( mChartType == ChartType.Pie)
drawPieDiagram(g);
if ( mBorderWidth > 0 )
g.DrawRectangle( new Pen(mBorderColor,mBorderWidth),mRegion);
}
/// <summary>
/// Gets/Sets whether the ChartBox is selectable in the design pane of the DaReport Designer
/// </summary>
/// <remarks>If set to true, then the ChartBox is not selectable in the DaReport Designer application
/// design pane. It is still selectable in the tree view listing of objects.
/// </remarks>
[Description("Sets whether the object can be selected in the design pane.")]
public override bool Selectable
{
get { return this.mSelectable; }
set { this.mSelectable=value; }
}
/// <summary>
/// Gets or sets the vertical alignment of the ChartBox
/// </summary>
[Description("Vertical alignment in the page, relative to margins. This property overrides element coordinates.")]
public override ICustomPaint.VerticalAlignmentTypes VerticalAlignment
{
get {return this.verticalAlignment;}
set
{
this.verticalAlignment = value;
switch (this.verticalAlignment)
{
case ICustomPaint.VerticalAlignmentTypes.Middle:
mRegion.Y = (document.DefaultPageSettings.Bounds.Height-document.Margins.Bottom+document.Margins.Top)/2 - Height/2;
break;
case ICustomPaint.VerticalAlignmentTypes.Bottom:
mRegion.Y = document.DefaultPageSettings.Bounds.Bottom - document.Margins.Bottom - Height;
break;
case ICustomPaint.VerticalAlignmentTypes.Top:
mRegion.Y = document.Margins.Top;
break;
}
}
}
/// <summary>
/// Gets or sets the width of the ChartBox.
/// </summary>
[Description("The width of the element.")]
public override int Width
{
get {return mRegion.Width;}
set
{
if (this.HorizontalAlignment == ICustomPaint.HorizontalAlignmentTypes.None || this.HorizontalAlignment == ICustomPaint.HorizontalAlignmentTypes.Left)
mRegion.Width = value;
else if (this.HorizontalAlignment == ICustomPaint.HorizontalAlignmentTypes.Right)
{
mRegion.X = mRegion.X - value + mRegion.Width;
mRegion.Width = value;
}
else if (this.HorizontalAlignment == ICustomPaint.HorizontalAlignmentTypes.Center)
{
mRegion.X = mRegion.X - value/2 + mRegion.Width/2;
mRegion.Width = value;
}
}
}
/// <summary>
/// The X coordinate of the left-upper corner of the element
/// </summary>
[Description("The X coordinate of the left-upper corner of the element.")]
public override int X
{
get {return mRegion.X;}
set
{
if (this.HorizontalAlignment == ICustomPaint.HorizontalAlignmentTypes.None)
mRegion.X = value;
else if (this.HorizontalAlignment == ICustomPaint.HorizontalAlignmentTypes.Right)
{
mRegion.Width = mRegion.Width + mRegion.X - value;
mRegion.X = value;
}
else if (this.HorizontalAlignment == ICustomPaint.HorizontalAlignmentTypes.Center)
{
mRegion.Width = mRegion.Width + 2*(mRegion.X - value);
mRegion.X = value;
}
}
}
/// <summary>
/// The Y coordinate of the left-upper corner of the element
/// </summary>
[Description("The Y coordinate of the left-upper corner of the element.")]
public override int Y
{
get {return mRegion.Y;}
set
{
if (this.VerticalAlignment == ICustomPaint.VerticalAlignmentTypes.None)
mRegion.Y = value;
else if (this.VerticalAlignment == ICustomPaint.VerticalAlignmentTypes.Bottom)
{
mRegion.Height = mRegion.Height + mRegion.Y - value;
mRegion.Y = value;
}
else if (this.VerticalAlignment == ICustomPaint.VerticalAlignmentTypes.Middle)
{
mRegion.Height = mRegion.Height + 2*(mRegion.Y - value);
mRegion.Y = value;
}
}
}
#endregion
#region Public Functions
/// <summary>
/// A serie is used to populate the ChartBox.
/// </summary>
/// <param name="serieName">Name of the serie. Displayed in the Legend</param>
/// <param name="values">A array of Double values</param>
/// <param name="serieColor">Color of the bar/pie</param>
/// <remarks>
/// You can add multiple serie to a chart. This would be useful for comparing values over certain years.
/// Please see the "Chart Report" example, especially the City Population chart
/// C# Sample
/// <code language="c#">
/// daPrintDocument.AddChartSerie("chart0","Year 1975.",new double[3]{15.9,11.4,11.2},Color.DarkGreen);
/// </code>
/// VB.Net Sample
/// <code language="Visual Basic">
/// daPrintDocument.AddChartSerie("chart0", "Year 1975.", New Double() {15.9, 11.4, 11.2}, Color.DarkGreen)
/// </code>
/// </remarks>
public void AddSerie(string serieName,double[] values,Color serieColor)
{
mYSeries.Add(values);
Color[] tmp = new Color[mSeriesColors.Length+1];
Array.Copy(mSeriesColors,0,tmp,0,mSeriesColors.Length);
tmp[mSeriesColors.Length] = serieColor;
mSeriesColors = tmp;
string[] tmp1 = new string[mSeriesColors.Length+1];
Array.Copy(mSeriesNames,0,tmp1,0,mSeriesNames.Length);
tmp1[mSeriesNames.Length] = serieName;
mSeriesNames = tmp1;
}
#endregion
#region Private Functions
private void calculateBarsMapArea(Graphics g)
{
SizeF sf = g.MeasureString(mTitle,mTitleFont);
SizeF sfLabel = g.MeasureString(mXLabel,mLabelFont);
if (mShowLegend)
{
int originX = (int) (mRegion.X+mRegion.Width*0.08);
int originY = (int) (mRegion.Y+sf.Height+10);
int width = (int) (mRegion.Width*0.68);
int height = (int) (mRegion.Height-sf.Height-10-2*sfLabel.Height-9);
mMapArea = new Rectangle(originX,originY,width,height);
originX = (int) (mRegion.X+mRegion.Width*0.78);
originY = (int) (mRegion.Y+sf.Height+10);
width = (int) (mRegion.Width*0.20);
height = (int) (mRegion.Height-sf.Height-10-2*sfLabel.Height-9);
mLegendArea = new Rectangle(originX,originY,width,height);
}
else
{
int originX = (int) (mRegion.X+mRegion.Width*0.1);
int originY = (int) (mRegion.Y+sf.Height+10);
int width = (int) (mRegion.Width*0.8);
int height = (int) (mRegion.Height-sf.Height-10-2*sfLabel.Height-9);
mMapArea = new Rectangle(originX,originY,width,height);
}
}
private void calculatePieMapArea(Graphics g)
{
SizeF sf = g.MeasureString(mTitle,mTitleFont);
SizeF sfLabel = g.MeasureString(mXLabel,mLabelFont);
if (mShowLegend)
{
int originX = (int) (mRegion.X+mRegion.Width*0.02);
int originY = (int) (mRegion.Y+sf.Height+12);
int width = (int) (mRegion.Width*0.72);
int height = (int) (mRegion.Height-sf.Height-20);
mMapArea = new Rectangle(originX,originY,width,height);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -