一、用鼠標懸停事件處理ide
private void Form1_Load(object sender, EventArgs e) { //connStr = connPath1 + conn2; fileName = connPath1 + conn2; connStr = "Provider= Microsoft.Ace.OLEDB.12.0;Data Source =" + connPath1 + conn2; ; chart1.MouseHover += new EventHandler(chart1_MouseHover); } //直接用鼠標懸停事件處理 void chart1_MouseHover(object sender, EventArgs e) { if (chart1.Series.Count != 0)//這裏判斷是否包含Series,也能夠用Series.Contains() { for (int i = 0; i < chart1.Series["Series1"].Points.Count; i++) { chart1.Series["Series1"].Points[i].ToolTip = "#VAL";//獲取值,能夠酌量添加 } } }
二、用getTollTip事件處理工具
//在顯示工具提示以前發生以獲取工具提示文本 chart1.GetToolTipText += new EventHandler<ToolTipEventArgs>(chart_GetToolTipText); void chart_GetToolTipText(object sender, ToolTipEventArgs e) { if (e.HitTestResult.ChartElementType == ChartElementType.DataPoint) { int i = e.HitTestResult.PointIndex; DataPoint dp = e.HitTestResult.Series.Points[i]; //分別顯示x軸和y軸的數值,其中{1:F3},表示顯示的是float類型,精確到小數點後3位。 e.Text = string.Format("次數:{0};數值:{1:F3} ", dp.XValue, dp.YValues[0]); } }