c# 设置TeeChart控件的提示文本
使用第三方Steema的TeeChart控件,设置鼠标放在某一线条点上,显示某一点的数据标签问题(虚线型十字光标基准线,放在线上显示对应点的二维坐标轴数据数据),调用InitTeeChartTipTools方法即可:
//////TeeChart线条的指示工具 /// Steema.TeeChart.Tools.CursorToolcursorTool; //////鼠标指示显示的文本 /// privateSteema.TeeChart.Tools.Annotationannotation; //////初始化线条的提示工具信息 /// privatevoidInitTeeChartTipTools(Steema.TeeChart.TCharttChart) { //以线形式对标坐标轴 cursorTool=newSteema.TeeChart.Tools.CursorTool(tChart.Chart); cursorTool.Style=Steema.TeeChart.Tools.CursorToolStyles.Both; cursorTool.Pen.Style=System.Drawing.Drawing2D.DashStyle.Dash; cursorTool.Pen.Color=Color.Black; cursorTool.FollowMouse=true; cursorTool.Change+=CursorTool_Change; //设置提示文本的信息 annotation=newSteema.TeeChart.Tools.Annotation(tChart.Chart); annotation.Shape.Font.Name="Arial"; annotation.Shape.Font.Size=12; annotation.Shape.Pen.Visible=true; annotation.Shape.Shadow.Visible=false; annotation.Shape.ShapeStyle=Steema.TeeChart.Drawing.TextShapeStyle.Rectangle; annotation.Position=Steema.TeeChart.Tools.AnnotationPositions.LeftBottom; annotation.TextAlign=StringAlignment.Center; for(inti=0;i///鼠标进入TeeChart的事件 /// /// /// privatevoidTChart_MouseEnter(objectsender,EventArgse) { cursorTool.Chart=tChartCurve.Chart; } /// ///鼠标离开TeeChart的事件 /// ////// privatevoidTChart_MouseLeave(objectsender,EventArgse) { cursorTool.Chart=null; } /// ///当鼠标进入线条时,将TeeChart的cursorTool工具指示的线条设置为对应的线条 /// ////// privatevoidLine_MouseEnter(objectsender,EventArgse) { cursorTool.Series=senderasSteema.TeeChart.Styles.Series; } /// ///当鼠标离开线条时,将TeeChart的cursorTool工具指示的线条设置为null /// ////// privatevoidLine_MouseLeave(objectsender,EventArgse) { cursorTool.Series=null; } /// ///鼠标指示工具改变事件 /// ////// privatevoidCursorTool_Change(objectsender,Steema.TeeChart.Tools.CursorChangeEventArgse) { try { Steema.TeeChart.Tools.CursorToolcursor=senderasSteema.TeeChart.Tools.CursorTool; if(cursor!=null&&cursor.Series!=null) { annotation.Text=string.Format("({0},{1})",cursor.XValue.ToString("f1"),cursor.YValue.ToString("f1")); annotation.Top=cursor.Series.GetVertAxis.CalcYPosValue(InterpolateLineSeries(cursor.Series,cursor.XValue)); annotation.Left=tChartCurve.Axes.Bottom.CalcXPosValue(cursor.XValue); annotation.Top-=20;//将文本放在鼠标上方 SizeFsize=this.CreateGraphics().MeasureString(annotation.Text, newFont(annotation.Shape.Font.Name,annotation.Shape.Font.Size)); if(annotation.Left+size.Width+12>=annotation.Chart.Width) { annotation.Left-=(int)size.Width+12;//防止文本标签超出右边界而看不全 } } else { //将其设置到控件外部 annotation.Text=""; annotation.Top=annotation.Chart.Height+5; annotation.Left=annotation.Chart.Width+5; } } catch(Exceptionex) { annotation.Text=ex.Message; annotation.Top=5; annotation.Left=5; } } /// ///计算某一点的Y值坐标 /// ///曲线 /// 对应的X轴的值 /// 计算得到的对应的Y轴的值 privatedoubleInterpolateLineSeries(Steema.TeeChart.Styles.Seriesseries,doublexvalue) { try { intindex; for(index=series.FirstVisibleIndex;index<=series.LastVisibleIndex;index++) { if(index==-1||series.XValues.Value[index]>xvalue)break; } //safeguard if(index<1) { index=1; } elseif(index>=series.Count) { index=series.Count-1; } //y=(y2-y1)/(x2-x1)*(x-x1)+y1 doubledx=series.XValues[index]-series.XValues[index-1]; doubledy=series.YValues[index]-series.YValues[index-1]; if(dx!=0.0) { returndy*(xvalue-series.XValues[index-1])/dx+series.YValues[index-1]; } else { return0.0; } } catch(Exceptionex) { Console.WriteLine(ex.Message); return0.0; } }
以上就是c#设置TeeChart控件的提示文本的详细内容,更多关于c#设置提示文本的资料请关注毛票票其它相关文章!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。