【ttyp】ASP.NET圖形化的曲線圖類
chart.cs
using System;
using System.Drawing;
namespace Report
{
///
/// Chart 的摘要說明。
/// ==================================================================================================
///
/// ClassName :Report.Chart
/// Intro :
/// Example :
/// Ver :0.2
///
/// Author :ttyp
/// Email :ttyp@21cn.com
/// Date :2007-7-30
/// ==================================================================================================
///
public class Chart
{
public Chart(){}
private string _data = "";
private int _width = 100;
private int _height = 100;
private int _padding= 8;
private Color _grid_color = Color.FromArgb(0x93,0xbe,0xe2);
private Color _border_color = Color.FromArgb(0x93,0xbe,0xe2);
private Font _font = new Font("Arial",8);
public Font Font
{
get { return _font;}
set { _font = value;}
}
public Color BorderColor
{
get { return _border_color;}
set { _border_color = value;}
}
public Color GridColor
{
get { return _grid_color;}
set { _grid_color = value;}
}
public int Padding
{
get { return _padding;}
set { _padding = Math.Max(0,value);}
}
public int Width
{
get { return _width;}
set { _width = Math.Max(0,value);}
}
public int Height
{
get { return _height;}
set { _height = Math.Max(0,value);}
}
public string Data
{
get { return _data;}
set { _data = value;}
}
public void Render()
{
int width = this.Width;
int height = this.Height;
int padding = this.Padding;
System.Drawing.Bitmap image = new System.Drawing.Bitmap(width,height);
Graphics g = Graphics.FromImage(image);
//清空圖片背景色
g.Clear(Color.White);
//虛線畫筆
Pen dot = new Pen(this.GridColor);
dot.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
//實線畫筆
Pen solid = new Pen(this.BorderColor);
//文字字型
Font font = this.Font;
try
{
//冗餘,去除最後的資料分割標記,防止空資料
if(this.Data.EndsWith(";"))
{
this.Data = this.Data.Substring(0,this.Data.Length-1);
}
string[] info = this.Data.Split(';'); //資料資訊
if(info.Length>=2)
{
string[] lines = info[0].Split(','); //圖例
string[] units = info[1].Split(','); //單位和標題格式,a,b,c,d a 縱座標單位 b 縱座標格式 N 數字 D 時間 後面是具體格式,c 橫座標單位 d 橫座標格式(同b)
//曲線顏色表
Color[] color = new Color[]{Color.Blue,Color.Green,Color.Red,Color.Gray,Color.Black,Color.Magenta,Color.Cyan,Color.Yellow,Color.DeepPink,Color.BurlyWood,Color.DarkRed,Color.Gold};
//圖例文字的大小
SizeF sFont = GetMaxSize(lines,g,font);
//獲得刻度文字高度
int textHeight = (int)(sFont.Height*3/2);
//曲線點的個數
int points = info.Length-2;
//得到曲線點陣列集合
string[,] curve = new string[info.Length-2,lines.Length+1];
for(int i=0;i<points;i++)
{
string[] l = info[i+2].Split(',');
int len = l.Length;
for(int j=0;j<=lines.Length;j++)
{
if(j<len)
{
curve[i,j] = l[j];
}
else
{
curve[i,j] = "N"; //非資料,不畫線
}
}
}
//獲得最大,最小值
double maxY,minY,maxX,minX;
GetMaxMin(curve,out maxY,out minY,out maxX,out minX);
//冗餘最大最小值
if(maxY==minY)
{
if(maxY==0)
{
maxY = 10;
minY = -10;
}
else
{
if(maxY>0)
{
maxY = maxY*2;
minY = 0;
}
else
{
maxY = 0;
minY = maxY*2;
}
}
}
if(maxX==minX)
{
if(maxX==0)
{
maxX = 10;
minX = -10;
}
else
{
if(maxX>0)
{
maxX = maxX*2;
minY = 0;
}
else
{
maxX = 0;
minX = maxX*2;
}
}
}
//獲取座標框的上下左右
float left = (padding*2+sFont.Height+2 + sFont.Width + padding+GetMaxSize(units[1],g,font).Width+padding);
float bottom = height-padding-textHeight;
float top = padding;
float right = width -padding;
//獲取曲線框的寬度和高度(比座標框略小)
float yWidth = bottom-top-GetMaxSize(units[0],g,font).Height*3/2-padding;
float xWidth = right-left-GetMaxSize(units[3],g,font).Width/2 - sFont.Width -padding;
//---------------------------------------------------------------------------------
//獲取最大行
int maxrow = (int)(yWidth/(sFont.Height/2*3));
maxrow = Math.Max(maxrow,1);
//獲取Y步進值
float stepYv = (float)((maxY-minY)/(maxrow));
if(units[1].Length>1)
{
//整數分割,調整最大行和最大最小值
if(units[1].Substring(0,1).ToLower()=="d")
{
maxY = Math.Ceiling(maxY);
minY = Math.Floor(minY);
stepYv = (float)Math.Ceiling((maxY-minY)/maxrow);
maxrow = (int)((maxY-minY)/stepYv);
}
}
float stepy = (float)((yWidth/(maxY-minY))*stepYv);
//---------------------------------------------------------------------------------
//得到最大的網格列(最多10列)
int maxcol = points;
maxcol = Math.Min(points,maxcol);
maxcol = Math.Max(maxcol,1);
//獲取X步進值
float stepXv = (float)((maxX-minX)/(maxcol));
if(units[3].Length>1)
{
//整數分割,調整最大和最小值,以及步進
if(units[3].Substring(0,1).ToLower()=="d")
{
maxX = Math.Ceiling(maxX);
minX = Math.Floor(minX);
stepXv = (float)Math.Ceiling((maxX-minX)/maxcol);
maxcol = (int)((maxX-minX)/stepXv);
}
}
//獲得最大顯示列數
int dispcol = (int)((xWidth)/(GetMaxSize(units[3].Substring(1),g,font).Width+padding));
dispcol = Math.Max(dispcol,1);
//如果最大顯示列小於最大列,則應該縮減
if(dispcol<maxcol)
{
stepXv = (float)Math.Ceiling((maxX-minX)/dispcol);
maxcol = (int)((maxX-minX)/stepXv);
}
float stepx = (float)((xWidth/(maxX-minX))*stepXv);
//獲得最大的曲線數目
int maxline = color.Length; &nbs
using System.Drawing;
namespace Report
{
///
/// Chart 的摘要說明。
/// ==================================================================================================
///
/// ClassName :Report.Chart
/// Intro :
/// Example :
/// Ver :0.2
///
/// Author :ttyp
/// Email :ttyp@21cn.com
/// Date :2007-7-30
/// ==================================================================================================
///
public class Chart
{
public Chart(){}
private string _data = "";
private int _width = 100;
private int _height = 100;
private int _padding= 8;
private Color _grid_color = Color.FromArgb(0x93,0xbe,0xe2);
private Color _border_color = Color.FromArgb(0x93,0xbe,0xe2);
private Font _font = new Font("Arial",8);
public Font Font
{
get { return _font;}
set { _font = value;}
}
public Color BorderColor
{
get { return _border_color;}
set { _border_color = value;}
}
public Color GridColor
{
get { return _grid_color;}
set { _grid_color = value;}
}
public int Padding
{
get { return _padding;}
set { _padding = Math.Max(0,value);}
}
public int Width
{
get { return _width;}
set { _width = Math.Max(0,value);}
}
public int Height
{
get { return _height;}
set { _height = Math.Max(0,value);}
}
public string Data
{
get { return _data;}
set { _data = value;}
}
public void Render()
{
int width = this.Width;
int height = this.Height;
int padding = this.Padding;
System.Drawing.Bitmap image = new System.Drawing.Bitmap(width,height);
Graphics g = Graphics.FromImage(image);
//清空圖片背景色
g.Clear(Color.White);
//虛線畫筆
Pen dot = new Pen(this.GridColor);
dot.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
//實線畫筆
Pen solid = new Pen(this.BorderColor);
//文字字型
Font font = this.Font;
try
{
//冗餘,去除最後的資料分割標記,防止空資料
if(this.Data.EndsWith(";"))
{
this.Data = this.Data.Substring(0,this.Data.Length-1);
}
string[] info = this.Data.Split(';'); //資料資訊
if(info.Length>=2)
{
string[] lines = info[0].Split(','); //圖例
string[] units = info[1].Split(','); //單位和標題格式,a,b,c,d a 縱座標單位 b 縱座標格式 N 數字 D 時間 後面是具體格式,c 橫座標單位 d 橫座標格式(同b)
//曲線顏色表
Color[] color = new Color[]{Color.Blue,Color.Green,Color.Red,Color.Gray,Color.Black,Color.Magenta,Color.Cyan,Color.Yellow,Color.DeepPink,Color.BurlyWood,Color.DarkRed,Color.Gold};
//圖例文字的大小
SizeF sFont = GetMaxSize(lines,g,font);
//獲得刻度文字高度
int textHeight = (int)(sFont.Height*3/2);
//曲線點的個數
int points = info.Length-2;
//得到曲線點陣列集合
string[,] curve = new string[info.Length-2,lines.Length+1];
for(int i=0;i<points;i++)
{
string[] l = info[i+2].Split(',');
int len = l.Length;
for(int j=0;j<=lines.Length;j++)
{
if(j<len)
{
curve[i,j] = l[j];
}
else
{
curve[i,j] = "N"; //非資料,不畫線
}
}
}
//獲得最大,最小值
double maxY,minY,maxX,minX;
GetMaxMin(curve,out maxY,out minY,out maxX,out minX);
//冗餘最大最小值
if(maxY==minY)
{
if(maxY==0)
{
maxY = 10;
minY = -10;
}
else
{
if(maxY>0)
{
maxY = maxY*2;
minY = 0;
}
else
{
maxY = 0;
minY = maxY*2;
}
}
}
if(maxX==minX)
{
if(maxX==0)
{
maxX = 10;
minX = -10;
}
else
{
if(maxX>0)
{
maxX = maxX*2;
minY = 0;
}
else
{
maxX = 0;
minX = maxX*2;
}
}
}
//獲取座標框的上下左右
float left = (padding*2+sFont.Height+2 + sFont.Width + padding+GetMaxSize(units[1],g,font).Width+padding);
float bottom = height-padding-textHeight;
float top = padding;
float right = width -padding;
//獲取曲線框的寬度和高度(比座標框略小)
float yWidth = bottom-top-GetMaxSize(units[0],g,font).Height*3/2-padding;
float xWidth = right-left-GetMaxSize(units[3],g,font).Width/2 - sFont.Width -padding;
//---------------------------------------------------------------------------------
//獲取最大行
int maxrow = (int)(yWidth/(sFont.Height/2*3));
maxrow = Math.Max(maxrow,1);
//獲取Y步進值
float stepYv = (float)((maxY-minY)/(maxrow));
if(units[1].Length>1)
{
//整數分割,調整最大行和最大最小值
if(units[1].Substring(0,1).ToLower()=="d")
{
maxY = Math.Ceiling(maxY);
minY = Math.Floor(minY);
stepYv = (float)Math.Ceiling((maxY-minY)/maxrow);
maxrow = (int)((maxY-minY)/stepYv);
}
}
float stepy = (float)((yWidth/(maxY-minY))*stepYv);
//---------------------------------------------------------------------------------
//得到最大的網格列(最多10列)
int maxcol = points;
maxcol = Math.Min(points,maxcol);
maxcol = Math.Max(maxcol,1);
//獲取X步進值
float stepXv = (float)((maxX-minX)/(maxcol));
if(units[3].Length>1)
{
//整數分割,調整最大和最小值,以及步進
if(units[3].Substring(0,1).ToLower()=="d")
{
maxX = Math.Ceiling(maxX);
minX = Math.Floor(minX);
stepXv = (float)Math.Ceiling((maxX-minX)/maxcol);
maxcol = (int)((maxX-minX)/stepXv);
}
}
//獲得最大顯示列數
int dispcol = (int)((xWidth)/(GetMaxSize(units[3].Substring(1),g,font).Width+padding));
dispcol = Math.Max(dispcol,1);
//如果最大顯示列小於最大列,則應該縮減
if(dispcol<maxcol)
{
stepXv = (float)Math.Ceiling((maxX-minX)/dispcol);
maxcol = (int)((maxX-minX)/stepXv);
}
float stepx = (float)((xWidth/(maxX-minX))*stepXv);
//獲得最大的曲線數目
int maxline = color.Length; &nbs
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-407087/,如需轉載,請註明出處,否則將追究法律責任。
![【ttyp】ASP.NET圖形化的曲線圖類](https://i.iter01.com/images/c7e43ea87787ea70648b3b17b12023983513dbf879af95b70b0cff7860d557a9.png)
請登入後發表評論
登入
全部評論
相關文章
- 4次Bezier曲線--計算機圖形學 opengl計算機
- delphi 畫圖表,曲線圖
- Qt QPolarChart極座標圖(阿基米德線、四葉曲線、六葉花瓣、三葉花瓣、心形曲線)QT
- canva畫曲線圖效果
- Flutter 實現平滑曲線折線圖Flutter
- MPAndroidChart繪製曲線圖、柱狀圖總結Android
- SerenityOS:類似Unix的圖形化桌面作業系統作業系統
- sk-learn 學習曲線圖
- R語言之視覺化①③散點圖+擬合曲線R語言視覺化
- python-資料分析-Matplotlib-1-基礎圖形(曲線圖-散點-柱狀-堆疊柱狀-餅狀圖-直方圖)Python直方圖
- 線上編輯Word——插入圖片、圖形
- Java圖形化:Swing表格的使用Java
- iOS 圖形效能優化iOS優化
- 圖形化安裝OracleOracle
- Java圖形化:JComponent元件Java元件
- Unity Dotween Ease曲線 圖表 效果展示Unity
- 解析csv資料繪製曲線圖
- Tableau——資料前處理、折線圖、餅圖(環形圖)
- 【Notes_8】現代圖形學入門——幾何(基本表示方法、曲線與曲面)
- Java圖形化:佈局方式Java
- iOS 圖形效能最佳化iOS
- flutter 自定義view 繪製曲線統計圖FlutterView
- python-科研繪圖系列(6)-深度模型準確率,誤差收斂曲線圖;雙座標繪圖;雙座標圖例放置在一個框中;帶95%置信區間的曲線圖Python繪圖模型
- 圖形演算法視覺化演算法視覺化
- XManager:xshell顯示圖形化介面
- 圖形學之Unity渲染管線流程Unity
- 畫影圖形: SVG & Canvas 圖形對比SVGCanvas
- 箱形圖(python畫圖)Python
- Java的圖形列印Java
- 圖形的認識
- java的圖形化介面 文字區JTextArea的程式例子Java
- Linux效能分析工具與圖形化方法Linux
- 圖形化配置和Kconfig基本語法
- 安裝Nmap圖形化前端工具Zenmap前端
- Kindd:一個圖形化 dd 命令前端前端
- 阿里雲centos安裝圖形化介面阿里CentOS
- oracle安裝呼叫圖形化失敗Oracle
- oracle linux 7 安裝圖形化介面OracleLinux
- 計算機圖形學-線性過濾計算機