using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing.Imaging;
using System.Drawing;
/// <summary>
/// DrawingCurve 的摘要說明
/// </summary>
public class DrawingCurve
{
public int intXLong = 800; //圖片大小 長
public int intYLong = 600; //圖片大小 高
public int intXMultiple = 1; //零刻度的值 X
public int intYMultiple = 0; //零刻度的值 Y
public int intXMax = 12; //最大刻度(點數) X
public int intYMax = 30; //最大刻度(點數) Y
public int intLeft = 50; //左邊距
public int intRight = 120; //右邊距
public int intTop = 30; //上邊距
public int intEnd = 50; //下邊距
public string strXText = "時間(單位:月)"; //單位 X
public string strYText = "數量(單位:個)"; //單位 Y
public string strTitle = "趨勢線圖"; //標題
public DataTable tbData; //要統計的數據
public DrawingCurve() intXScale = (intXLong - intLeft - intRight) / (intXMax + 1);//一刻度長度 X //intX = intXLong - intLeft; //0點 X坐標 public Bitmap DrawingImg() Bitmap img = new Bitmap(intXLong, intYLong); //圖片大小 //繪制縱坐標 //繪制橫坐標
private int intXScale = 30; //一刻度長度 X
private int intYScale = 30; //一刻度高度 Y
//private int intX = 0; //0點 X坐標
//private int intY = 0; //0點 Y坐標
public int intData = 0; //記錄數
{
intYScale = (intYLong - intTop - intEnd) / (intYMax + 1);//一刻度高度 Y
//intY = intYLong - intEnd; //0點 Y坐標
}
{
Graphics g = Graphics.FromImage(img);
g.Clear(Color.Snow);
g.DrawString(strTitle, new Font("宋體", 14), Brushes.Black, new Point(5, 5));
g.DrawLine(new Pen(Color.Black, 2), intLeft, intYLong - intEnd, intXLong - intRight, intYLong - intEnd); //繪制橫向
g.DrawLine(new Pen(Color.Black, 2), intLeft, intTop, intLeft, intYLong - intEnd); //繪制縱向
g.DrawString(strYText, new Font("宋體", 12), Brushes.Black, new Point(intLeft, intTop));//Y 單位
Point p1 = new Point(intLeft - 10, intYLong - intEnd);
for (int j = 0; j <= intYMax; j++)
{
p1.Y = intYLong - intEnd - j * intYScale;
Point pt = new Point(p1.X + 10, p1.Y);
//繪制縱坐標的刻度和直線
g.DrawLine(Pens.Black, pt, new Point(p1.X + 15, p1.Y));
//繪制縱坐標的文字說明
g.DrawString(Convert.ToString(j + intYMultiple), new Font("宋體", 12), Brushes.Black, new Point(p1.X - 25, p1.Y - 8));
}
g.DrawString(strXText, new Font("宋體", 12), Brushes.Black, new Point(intXLong - intRight, intYLong - intEnd));//X 單位
Point p = new Point(intLeft, intYLong - intEnd);
for (int i = 0; i < intXMax; i++)
{
p.X = intLeft + i * intXScale;
//繪制橫坐標刻度和直線
g.DrawLine(Pens.Black, p, new Point(p.X, p.Y - 5));
//繪制橫坐標的文字說明
g.DrawString(Convert.ToString(i + intXMultiple), new Font("宋體", 12), Brushes.Black, p);
}
intData = tbData.Rows.Count;
if (intData > 0)
{
//趨勢線圖
for (int i = 0; i < intData - 1; i++)
{
DataRow Row1 = tbData.Rows[i];
DataRow Row2 = tbData.Rows[i + 1];
//定義起點
Point rec = new Point(Convert.ToInt32(intLeft + ((TurnNumber(Row1[0].ToString()) - intXMultiple) * intXScale)), Convert.ToInt32(intYLong - intEnd - (TurnNumber(Row1[1].ToString()) - intYMultiple) * intYScale));
//定義終點
Point dec = new Point(Convert.ToInt32(intLeft + ((TurnNumber(Row2[0].ToString()) - intXMultiple) * intXScale)), Convert.ToInt32(intYLong - intEnd - (TurnNumber(Row2[1].ToString()) - intYMultiple) * intYScale));
//繪制趨勢折線
g.DrawLine(new Pen(Color.Red), rec, dec);
&