ZedGraph的曲线的LineItem对象的Tag属性存储信息进而在鼠标悬浮时进行显示
生活随笔
收集整理的這篇文章主要介紹了
ZedGraph的曲线的LineItem对象的Tag属性存储信息进而在鼠标悬浮时进行显示
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
場(chǎng)景
Winform中設(shè)置ZedGraph鼠標(biāo)懸浮顯示距離最近曲線上的點(diǎn)的坐標(biāo)值和X軸與Y軸的標(biāo)題:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103140781
上面博客能實(shí)現(xiàn)鼠標(biāo)懸浮顯示最近的曲線上點(diǎn)的坐標(biāo)值與X軸和Y軸的標(biāo)題,
如果想要再顯示其他信息,比如曲線所對(duì)應(yīng)的文件名等。
那么就要在生成曲線時(shí)將自定義要保存的信息與曲線進(jìn)行綁定存儲(chǔ)。
注:
博客主頁(yè):
https://blog.csdn.net/badao_liumang_qizhi
關(guān)注公眾號(hào)
霸道的程序猿
獲取編程相關(guān)電子書、教程推送與免費(fèi)下載。
實(shí)現(xiàn)
ZedGraph的曲線對(duì)象是LineItem,其有一屬性Tag可以用它來存儲(chǔ)額外信息。
在生成曲線時(shí)
LineItem myCurve = myPane.AddCurve(yList[i].Title, list, System.Drawing.ColorTranslator.FromHtml(yList[i].Color), symbolType); //使用曲線TAG存儲(chǔ)數(shù)據(jù)庫(kù)名 文件名 //文件完整路徑 string filePath = compTestDataList[k].ThisDataFile; //文件名string fileName = System.IO.Path.GetFileNameWithoutExtension(filePath); //數(shù)據(jù)庫(kù)名 string dBName = System.IO.Directory.GetParent(filePath).ToString(); dBName = dBName.Substring(dBName.LastIndexOf('\\') + 1); dBName = "DB_" + dBName; //短文件名 string[] titles = fileName.Split('_'); string shortFileName = "柜" + titles[titles.Length - 2] + "通道" + titles[titles.Length - 1]; myCurve.Tag = dBName + shortFileName; myCurve.YAxisIndex = i;生成曲線時(shí)使用曲線對(duì)象的Tag屬性存儲(chǔ)了自定義的一些信息。
那么在鼠標(biāo)的懸浮事件中
tag = nearstCurve.Tag.ToString();完整示例代碼
private static string zgc_CursorValueEvent(ZedGraphControl sender, GraphPane pane, Point mousePt){ZedGraphControl zgc = sender as ZedGraphControl;if (zgc != null){CurveItem nearstCurve;int i;Double x = 0.0;Double y = 0.0;string xTitle = String.Empty;string yTtile = String.Empty;string tag = String.Empty;string xVlaue = String.Empty;string z = String.Empty;try{zgc.GraphPane.FindNearestPoint(mousePt, out nearstCurve, out i);if (nearstCurve != null && nearstCurve.Points.Count > i && nearstCurve.Points[i] != null){z = nearstCurve.Points[i].Tag.ToString();y = nearstCurve.Points[i].Y;xTitle = zgc.GraphPane.XAxis.Title.Text;//獲取當(dāng)前pane面板的YAxis的標(biāo)題的文本內(nèi)容,通過nearstCurve.YAxisIndex獲取當(dāng)前距離最近的曲線所對(duì)應(yīng)的Y軸的IndexyTtile = zgc.GraphPane.YAxisList[nearstCurve.YAxisIndex].Title.Text;tag = nearstCurve.Tag.ToString();}}catch (Exception ex){}return tag+ " X-" + xTitle + ": " + z + "? Y-" + yTtile + ": " + y.ToString();}else{return String.Empty;}}效果
?
與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的ZedGraph的曲线的LineItem对象的Tag属性存储信息进而在鼠标悬浮时进行显示的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DevExpress的LookUpEdi
- 下一篇: DevExpress的GridContr