设置TeeChart的提示文本
使用第三方Steema的TeeChart控件,设置鼠标放在某一线条点上,显示某一点的数据标签问题(虚线型十字光标基准线,放在线上显示对应点的二维坐标轴数据数据),调用InitTeeChartTipTools方法即可:
/// <summary>
/// TeeChart线条的指示工具
/// </summary>
Steema.TeeChart.Tools.CursorTool cursorTool;
/// <summary>
/// 鼠标指示显示的文本
/// </summary>
private Steema.TeeChart.Tools.Annotation annotation;
/// <summary>
/// 初始化线条的提示工具信息
/// </summary>
private void InitTeeChartTipTools(Steema.TeeChart.TChart tChart)
{
//以线形式对标坐标轴
cursorTool = new Steema.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 = new Steema.TeeChart.Tools.Annotation(tChart.Chart);
annotation.Shape.Font.Name = "Arial";
annotation.Shape.Font.Size = ;
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 (int i = ; i < tChart.Series.Count; i++)
{
tChart.Series[i].MouseEnter += Line_MouseEnter;
tChart.Series[i].MouseLeave += Line_MouseLeave;
} tChart.MouseLeave += TChart_MouseLeave;
tChart.MouseEnter += TChart_MouseEnter;
} /// <summary>
/// 鼠标进入TeeChart的事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TChart_MouseEnter(object sender, EventArgs e)
{
cursorTool.Chart=tChartCurve.Chart;
} /// <summary>
/// 鼠标离开TeeChart的事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TChart_MouseLeave(object sender, EventArgs e)
{
cursorTool.Chart = null;
} /// <summary>
/// 当鼠标进入线条时,将TeeChart的cursorTool工具指示的线条设置为对应的线条
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Line_MouseEnter(object sender, EventArgs e)
{
cursorTool.Series = sender as Steema.TeeChart.Styles.Series;
} /// <summary>
/// 当鼠标离开线条时,将TeeChart的cursorTool工具指示的线条设置为null
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Line_MouseLeave(object sender, EventArgs e)
{
cursorTool.Series = null;
}
/// <summary>
/// 鼠标指示工具改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CursorTool_Change(object sender, Steema.TeeChart.Tools.CursorChangeEventArgs e)
{
try
{
Steema.TeeChart.Tools.CursorTool cursor = sender as Steema.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 -= ;//将文本放在鼠标上方
SizeF size = this.CreateGraphics().MeasureString(annotation.Text,
new Font(annotation.Shape.Font.Name, annotation.Shape.Font.Size));
if (annotation.Left + size.Width + >= annotation.Chart.Width)
{
annotation.Left -= (int)size.Width + ;//防止文本标签超出右边界而看不全
}
}
else
{
//将其设置到控件外部
annotation.Text = "";
annotation.Top = annotation.Chart.Height + ;
annotation.Left = annotation.Chart.Width + ;
}
}
catch (Exception ex)
{
annotation.Text = ex.Message;
annotation.Top = ;
annotation.Left = ;
}
}
/// <summary>
/// 计算某一点的Y值坐标
/// </summary>
/// <param name="series">曲线</param>
/// <param name="xvalue">对应的X轴的值</param>
/// <returns>计算得到的对应的Y轴的值</returns>
private double InterpolateLineSeries(Steema.TeeChart.Styles.Series series, double xvalue)
{
try
{
int index;
for (index = series.FirstVisibleIndex; index <= series.LastVisibleIndex; index++)
{
if (index == - || series.XValues.Value[index] > xvalue) break;
}
// safeguard
if (index < )
{
index = ;
}
else if (index >= series.Count)
{
index = series.Count - ;
}
// y=(y2-y1)/(x2-x1)*(x-x1)+y1
double dx = series.XValues[index] - series.XValues[index - ];
double dy = series.YValues[index] - series.YValues[index - ];
if (dx != 0.0)
{
return dy * (xvalue - series.XValues[index - ]) / dx + series.YValues[index - ];
}
else
{
return 0.0;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return 0.0;
}
}
设置TeeChart的提示文本的更多相关文章
- Android中的AutoCompleteTextView(随笔提示文本)组件的简单使用
		
Android中的随笔提示文本组件AutoCompleteTextView的使用,此组件用于输入文本,然后就会在所配置的适配器中的数据进行查找显示在组件下面. 这里值得注意的是AutoComplete ...
 - Android自己主动提示文本框(AutoCompleteTextView)
		
自己主动提示文本框(AutoCompleteTextView)能够加强用户体验,缩短用户的输入时间(百度的搜索框就是这个效果). 首先.在xml中定义AutoCompleteTextView控件: a ...
 - Wireshark设置interface 时提示“There are no interfaces on which a capture can be done ”
		
Wireshark设置interface 时提示“There are no interfaces on which a capture can be done ” 解决方法: 今天在电脑上安装了WIR ...
 - IntelliJ设置鼠标悬浮提示和修改快捷键
		
IntelliJ设置鼠标悬浮提示和修改快捷键 设置鼠标悬浮提示 修改快捷键 进入设置菜单 删除原来的快捷键(注:你可以选择保留原来的快捷键,同时使用两个快捷键) Good Luck
 - JS实现动态提示文本框可输入剩余字数(类似发表微博数字提示)
		
一.实现效果: 为了更直观的体现用户在文本框输入文本时能看到自己输入了多少字,项目中需要通过判断提示文本框剩余可输入字数. html & JS: <div> <textare ...
 - Android Studio如何设置代码自动提示
		
在用Eclipse时候,你可以进行设置,设置成不管你输入任何字母,都能进行代码的提示,在Android Studio中也可以 设置,而且比Eclipse设置来的简单.当然如果你觉得代码自动提示会降低你 ...
 - 在MyEclipse8.6中设置jQuery自动提示 - 肖飞figo的云计算专栏 - 博客频道 - CSDN.NET
		
body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...
 - 设置select,option文本居中
		
设置select,option文本居中 可以通过 padding 属性设置内边距,使它看上去居中: select{ # 从左到右依次表示上内边距,右内边距,下内边距,左内边距: padding :0 ...
 - JTextPane或JTextPane设置了滚动条,文本增加后,滚动条自动下滑,追加文本的例子
		
http://zhizaibide1987.iteye.com/blog/1012955 https://zhidao.baidu.com/question/2116908942184706107.h ...
 
随机推荐
- 使用JdbcTemplate访问数据库
			
参考源端:https://blog.csdn.net/liaodehong/article/details/76974827 今天用Spring Boot访问一下数据库,并且把数据返回到页面中,进行增 ...
 - 基于 Lucene 的桌面文件搜索
			
开源2010年,自己在学习 Lucene 时开发的一款桌面文件搜索工具,这么多年过去了,代码一直静静存放在自己的硬盘上,与其让其沉睡,不如分享出来. 这款工具带有明显的模仿 Everything 的痕 ...
 - c# 二维码支持中文
			
/// <summary> /// 生成二维码,保存成图片 /// </summary> static void Generate1(string text) { Barcod ...
 - 如何在ArcMap中监听键盘鼠标事件(转)
			
如何在ArcMap中监听键盘鼠标事件(转) Link: http://www.cnblogs.com/dyllove98/p/3155551.html 昨天有个朋友想要实现一个功能,就是在ArcMap ...
 - go_接口
			
duck typeing 隐式的实现接口的方法就等于实现了接口 main函数 package main import ( "fmt" "learngo/retriever ...
 - ora-01045错误的解决办法
			
问题: 在用PL/SQL进行登录时,出现:”ora-01045 :user system lacks create session privilege; logon denied”. 原因:该用户没有 ...
 - Python_05-文件操作
			
目录: 1 文件操作 1.1 快速入门 1.1.1 用Python创建一个新文件 1.1.2 文件内容追加,从0到9的10个随机整数 ...
 - iOS下nil 、NULL、 Nil 、NSNull的区别
			
1.nil,定义一个空的实例,指向OC中对象的空指针. 示例代码: NSString *someString = nil; NSURL *someURL = nil; id someObject = ...
 - Win2003+apache+PHP+SqlServer2008 配置
			
Win2003+apache+PHP+SqlServer2008 配置 安装前的准备: 1.Apache2.2.2 2.PHP5.2.17 3.SqlServer2008 4.sqlncli. ...
 - mybatis框架入门程序:演示通过mybatis实现数据库的插入操作中实现返回结果的获取
			
1.mybatis实现数据库的插入操作可以查看https://www.cnblogs.com/wyhluckdog/p/10149895.html这篇博文,这里面的插入操作没有返回结果,所以这篇博文就 ...