Winforn中設置ZedGraph曲線圖的屬性、座標軸屬性、刻度屬性:node
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100112573編程
在對ZedGraph進行添加曲線時,須要對X軸的刻度進行賦值,須要一個string的數組。數組
而且在生成曲線時還要給曲線一個個座標點的list。spa
如何在生成完曲線後直接從曲線中取得曲線的橫座標做爲X軸的賦值。.net
注:code
博客主頁:
https://blog.csdn.net/badao_liumang_qizhi
關注公衆號
霸道的程序猿
獲取編程相關電子書、教程推送與免費下載。blog
循環添加曲線教程
PointPairList list = null; for (int i = 0; i < yList.Count; i++) { //循環添加曲線 foreach(DataTreeNode node in Global.Instance.PrepareCompareDataInOne) { IEnumerable<Entity.Record> record = Global.Instance.VirtualData.RecordDataList.Where(p => p.CycleIndex == int.Parse(node.Id)); list = SetCurveTextInOne(yList[i].TitleKey,record); LineItem myCurve = myPane.AddCurve(yList[i].Title, list, System.Drawing.ColorTranslator.FromHtml(yList[i].Color), SymbolType.None); myCurve.YAxisIndex = i; //很關鍵,對應使用那個座標值 } }
給曲線賦值索引
public static PointPairList SetCurveTextInOne(string yAxis,IEnumerable<Entity.Record> record) { PointPairList list = new PointPairList(); #region 數據驗證 if (record == null) { return list; } #endregion else { //曲線賦值 int maxCtn = 0; //最大點數 double y = 0.0; int x =1; List<Entity.Record> recordList = new List<Entity.Record>(); foreach (Entity.Record re in record) { maxCtn++; recordList.Add(re); } Func<Entity.Record, object> getYValue = BaseHelper.EmitGetter<Entity.Record>(yAxis); for (int k = 0; k < recordList.Count; k++) { if (BaseHelper.IsExistsProperty<Entity.Record>(yAxis)) { object objY = getYValue(recordList[k]); if (objY != null) { double.TryParse(objY.ToString(), out y); } } list.Add(x, y, k+1); //添加一組數據(k:x數據點的索引,y:y的值,xTag:x的實際值) x++; } return list; } }
X軸的刻度值在曲線中獲取get
myPane.XAxis.Scale.TextLabels = list.Select<PointPair, string>(p => p.X.ToString()).ToArray<string>(); //X軸文本取值