ASP.NET画图系列之实现Curve图(曲线图),今天要实现的是Curve图,先看下效果:

页面部分,还是和Pie一样
<form id="form1" runat="server">
<div>
<asp:Image ID="Image1" runat="server" />
</div>
</form>
cs代码:
using System.Drawing; //Bitmap
using System.Drawing.Imaging; //ImageFormat
using SkyNet.Chart;
using SkyNet.OA.OAWebUtility;
public partial class SkyNetChart_MyCurve : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
InitChart();
}
}
private void InitChart()
{
Curve curveImg = new Curve(); //定义一个画图类实例
curveImg.Title = "2008年销售情况统计表";
curveImg.Width = 900;
curveImg.Height = 500;
curveImg.TextColor = Color.Red;
string imgPath = "../ChartImages/" + "MyCurve.jpg";
string savePath = Server.MapPath(imgPath);
ChartHelper.CreateChartByCurve(curveImg, imgPath, ImageFormat.Jpeg);
this.Image1.ImageUrl = imgPath;
}
}
上面有不明白的地方,请参照ASP.NET画图系列之实现Pie图(圆饼图)
接下来是Curve类
Code
#region 私有字段
private Graphics objGraphics; //Graphics 类提供将对象绘制到显示设备的方法
private Bitmap objBitmap; //位图对象
private int m_Width = 900; //图像宽度
private int m_Height = 500; //图像高度
private float m_XSlice = 50; //X轴刻度宽度
private float m_YSlice = 50; //Y轴刻度宽度
private float m_YSliceValue = 20; //Y轴刻度的数值宽度
private float m_YSliceBegin = 0; //Y轴刻度开始值
private float m_Tension = 0.5f;
private string m_Title = "××公司销售情况曲线图"; //Title
private string m_Unit = "万元"; //单位
private string m_XAxisText = "月份"; //X轴说明文字
private string m_YAxisText = "万元"; //Y轴说明文字
private string[] m_Keys = new string[] { "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月" }; //键
private float[] m_Values = new float[] { 20.0f, 30.0f, 50.0f, 55.4f, 21.6f, 12.8f, 99.5f, 36.4f, 78.2f, 56.4f, 45.8f, 66.5f }; //值
private Color m_BgColor = Color.Snow; //背景
private Color m_TextColor = Color.Black; //文字颜色
private Color m_BorderColor = Color.Black; //整体边框颜色
private Color m_AxisColor = Color.Black; //轴线颜色
private Color m_AxisTextColor = Color.Black; //轴说明文字颜色
private Color m_SliceTextColor = Color.Black; //刻度文字颜色
private Color m_SliceColor = Color.Black; //刻度颜色
private Color m_CurveColor = Color.Red; //曲线颜色
private DataSet m_ds;
#endregion
#region 属性
public DataSet DS
{
get { return m_ds; }
set { m_ds = value; }
}
public int Width
{
set
{
if (value < 300)
{
m_Width = 300;
}
else
{
m_Width = value;
}
}
get
{
return m_Width;
}
}
public int Height
{
set
{
if (value < 300)
{
m_Height = 300;
}
else
{
m_Height = value;
}
}
get
{
return m_Height;
}
}
public float XSlice
{
set
{
m_XSlice = value;
}
get
{
return m_XSlice;
}
}
public float YSlice
{
set
{
m_YSlice = value;
}
get
{
return m_YSlice;
}
}
public float YSliceValue
{
set
{
m_YSliceValue = value;
}
get
{
return m_YSliceValue;
}
}
public float YSliceBegin
{
set
{
m_YSliceBegin = value;
}
get
{
return m_YSliceBegin;
}
}
public float Tension
{
set
{
if (value < 0.0f && value > 1.0f)
{
m_Tension = 0.5f;
}
else
{
m_Tension = value;
}
}
get
{
return m_Tension;
}
}
public string Title
{
set
{
m_Title = value;
}
get
{
return m_Title;
}
}
public string Unit
{
set
{
m_Unit = value;
}
get
{
return m_Unit;
}
}
public string[] Keys
{
set
{
m_Keys = value;
}
get
{
return m_Keys;
}
}
public float[] Values
{
set
{
m_Values = value;
}
get
{
return m_Values;
}
}
public Color BgColor
{
set
{
m_BgColor = value;
}
get
{
return m_BgColor;
}
}
public Color TextColor
{
set
{
m_TextColor = value;
}
get
{
return m_TextColor;
}
}
public Color BorderColor
{
set
{
m_BorderColor = value;
}
get
{
return m_BorderColor;
}
}
public Color AxisColor
{
set
{
m_AxisColor = value;
}
get
{
return m_AxisColor;
}
}
public string XAxisText
{
set
{
m_XAxisText = value;
}
get
{
return m_XAxisText;
}
}
public string YAxisText
{
set
{
m_YAxisText = value;
}
get
{
return m_YAxisText;
}
}
public Color AxisTextColor
{
set
{
m_AxisTextColor = value;
}
get
{
return m_AxisTextColor;
}
}
public Color SliceTextColor
{
set
{
m_SliceTextColor = value;
}
get
{
return m_SliceTextColor;
}
}
public Color SliceColor
{
set
{
m_SliceColor = value;
}
get
{
return m_SliceColor;
}
}
public Color CurveColor
{
set
{
m_CurveColor = value;
}
get
{
return m_CurveColor;
}
}
#endregion

