📄 splinegraph.cs
字号:
// Disclaimer and Copyright Information
// SplineGraph.cs :
//
// All rights reserved.
//
// Written by Pardesi Services, LLC
// Version 1.01
//
// Distribute freely, except: don't remove our name from the source or
// documentation (don't take credit for my work), mark your changes (don't
// get me blamed for your possible bugs), don't alter or remove this
// notice.
// No warrantee of any kind, express or implied, is included with this
// software; use at your own risk, responsibility for damages (if any) to
// anyone resulting from the use of this software rests entirely with the
// user.
//
// Send bug reports, bug fixes, enhancements, requests, flames, etc. to
// softomatix@CommonComponent.com
///////////////////////////////////////////////////////////////////////////////
//
using System;
using System.Diagnostics;
using System.Collections;
using System.Drawing;
using System.Xml;
namespace CommonComponent.CommonChart
{
/// <summary>
///
/// </summary>
public class SplineGraph : CommonChart.AxialGraph
{
protected float m_fXScale;
protected float m_fYScale;
public SplineGraph()
{
//
// TODO: Add constructor logic here
//
m_fXScale = 1.0F;
m_fYScale = 1.0F;
this.m_GraphType = Type.AreaGraph;
this.m_QuadrantToShow = QuadrantType.Quad1;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected bool CalculateXScale()
{
m_fXScale = (this.m_iXAxisSpan)/(float)(this.MaxXValue - this.MinXValue);
return true;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected bool CalculateYScale()
{
m_fYScale = (this.m_iYAxisSpan)/(float)(this.MaxYValue - this.MinYValue);
return true;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
override protected bool CalculateAxisLocation()
{
// Calculate the origin of axis.
CalculateAxis();
return true;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
override protected bool DrawGraphAxis(bool bDrawGrid)
{
// Calculate the width of x-axis and y-axis lines
CalculateAxisSpan();
CalculateXScale();
CalculateYScale();
// Calculate the axis location.
CalculateAxisLocation();
CalculateAxisLabelLocations();
DrawAxisLines(bDrawGrid);
DrawAxisLabels();
return true;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
override protected bool DrawAxisLines(bool bDrawGrid)
{
Pen obPen = null;
Pen obGridPen = null;
try
{
// Draw the grid lines now.
if (HasGridLines && this.YTickSpacing > 0)
{
SizeF rectText;
string strVal = "";
PointF pt1 = new PointF();
PointF pt2 = new PointF();
obGridPen = new Pen(GridColor);
int iYTickCount = (int)((this.MaxYValue - this.MinYValue)/this.YTickSpacing);
int iXTickCount = (int)((this.MaxXValue - this.MinXValue)/this.XTickSpacing);
// Draw Y Grid Lines
for (int i = 0; i <= iYTickCount; i++)
{
pt1.X = this.m_ChartAxis.X1.X;
pt2.X = pt1.X + this.m_iXAxisSpan;
pt1.Y = this.m_ChartAxis.Y2.Y - (i * this.YTickSpacing) * this.m_fYScale;
pt2.Y = pt1.Y;
this.m_obGraphics.DrawLine(obGridPen, pt1, pt2);
strVal = (MinYValue + (i * YTickSpacing)).ToString();
rectText = this.m_obGraphics.MeasureString(strVal, this.m_YTickFont);
pt1.X = pt1.X - (rectText.Width + 2);
this.m_obGraphics.DrawString(strVal, this.m_YTickFont, new SolidBrush(this.m_TitleColor), pt1);
}
// Draw XGrid Lines
for (int i = 0; i <= iXTickCount; i++)
{
pt1.X = this.m_ChartAxis.Y2.X + (i * this.XTickSpacing) * this.m_fXScale;
pt1.Y = this.m_ChartAxis.Y2.Y;
pt2.X = pt1.X;
pt2.Y = this.m_ChartAxis.Y1.Y;
this.m_obGraphics.DrawLine(obGridPen, pt1, pt2);
strVal = (MinXValue + (i * XTickSpacing)).ToString();
rectText = this.m_obGraphics.MeasureString(strVal, this.m_YTickFont);
pt1.X = pt1.X - (rectText.Width + 2);
this.m_obGraphics.DrawString(strVal, this.m_XTickFont, new SolidBrush(this.m_TitleColor), pt1);
}
}
obPen = new Pen(new SolidBrush(Color.Black));
this.m_obGraphics.DrawLine(obPen, this.m_ChartAxis.X1, this.m_ChartAxis.X2);
this.m_obGraphics.DrawLine(obPen, this.m_ChartAxis.Y2, this.m_ChartAxis.Y1);
}
finally
{
if (obPen != null)
{
obPen.Dispose();
}
}
return true;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
override protected bool DrawData()
{
//TODO: For now we will process only first array of data list. Later
// on implementation needs to take into account that there may
// be more than one list.
Pen obSplinePen = null;
try
{
ArrayList dataList = (ArrayList)this.m_obIslandList[0];
if (null == dataList || dataList.Count == 0)
{
throw new Exception("There is no data list present in the array.");
}
int nCount = dataList.Count;
// Create a polygon for specifying all the data points. We will
// need two extra points for specifying the starting and closing
// point to close the polygon.
PointF [] splinePolygon = new PointF[nCount];
obSplinePen = new Pen(new SolidBrush(Color.DarkBlue));
for (int i = 0; i < nCount; i++)
{
GraphDataObject obData1 = (GraphDataObject)dataList[i];
if (null != obData1)
{
splinePolygon[i].X = this.m_ChartAxis.Origin.X + (float)(obData1.X * this.m_fXScale);
splinePolygon[i].Y = this.m_ChartAxis.Origin.Y - (float)(obData1.Y * this.m_fYScale);
}
}
// Draw the polygon now.
this.m_obGraphics.DrawCurve(obSplinePen, splinePolygon, 1.0F);
}
finally
{
if (null != obSplinePen)
{
obSplinePen.Dispose();
}
}
return true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -