using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using ZedGraph; namespace TestZedGraphControl { /// <summary> /// 畫圖控件操作類(VS顯示控件:工具-->添加項-->選擇項-->ZedGraph.dll) /// </summary> public class CtlZedGraphOperate { private ZedGraphControl m_zedGraphControl = null; /// <summary> /// 關聯ZedGraph畫圖控件 /// </summary> public ZedGraphControl refZedGraphControl { set { m_zedGraphControl = value; } get { return m_zedGraphControl; } } /// <summary> /// 構造函數 /// </summary> public CtlZedGraphOperate() { } private static volatile CtlZedGraphOperate zgOpera = null; /// <summary> /// 獲取畫圖控件操作類單一實例 /// </summary> /// <returns></returns> public static CtlZedGraphOperate GetInstance() { if(null == zgOpera) { zgOpera = new CtlZedGraphOperate(); } return zgOpera; } /// <summary> /// 設置標題 /// </summary> /// <param name="title">圖標題</param> /// <param name="x_title">X軸標題</param> /// <param name="y_title">Y軸標題</param> /// <param name="x_type">X軸類型</param> /// <param name="y_type">Y軸類型</param> public void SetTitles(string title, string x_title, string y_title) { m_zedGraphControl.GraphPane.Title.Text = title; m_zedGraphControl.GraphPane.XAxis.Title.Text = x_title; m_zedGraphControl.GraphPane.YAxis.Title.Text = y_title; } /// <summary> /// 設置標題(Linear:線性,Exponent:指數,Log:對數,Date:時間,Text:文本,Ordinal:序數,LinearOrdinal:線性序數,DateOrdinal:時間序數) /// </summary> /// <param name="title">圖標題</param> /// <param name="x_title">X軸標題</param> /// <param name="y_title">Y軸標題</param> /// <param name="x_type">X軸類型</param> /// <param name="y_type">Y軸類型</param> public void SetTitles(string title, string x_title, string y_title, AxisType x_type, AxisType y_type) { m_zedGraphControl.GraphPane.Title.Text = title; m_zedGraphControl.GraphPane.XAxis.Title.Text = x_title; m_zedGraphControl.GraphPane.YAxis.Title.Text = y_title; m_zedGraphControl.GraphPane.XAxis.Type = x_type; m_zedGraphControl.GraphPane.YAxis.Type = y_type; } /// <summary> /// 依據點集畫線 /// </summary> /// <param name="pointList">點集</param> public LineItem DrawLines(string label, PointPairList pointList, System.Drawing.Color color, SymbolType symbolType) { return m_zedGraphControl.GraphPane.AddCurve(label, pointList, color, symbolType); } /// <summary> /// 刷新 /// </summary> public void ReFresh() { m_zedGraphControl.AxisChange(); m_zedGraphControl.Refresh(); } } }