ZedGraph5.1.5源码分析去掉鼠标悬浮内容闪烁问题(附源码下载)
场景
在使用ZedGraph绘制曲线图时,将鼠标悬浮时内容闪烁,且频率很高。

找到其源码,发现不论鼠标移动的范围大小,甚至乎不论鼠标是否移动,都要刷新一次Tooltip。
注:
博客主页:
https://blog.csdn.net/badao_liumang_qizhi
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。
实现
首先来到ZedGraph的官网
https://sourceforge.net/projects/zedgraph/
然后点击File下的zedgraph source

选择对应版本,这里是5.1.5

下载成功后,将zip解压
找到source下的工程文件,双击使用VS打开

然后找到ZedGraphControl.Events.cs

找到其ZedGraphControl_MouseMove方法此方法是鼠标移动时的事件处理
可以看到其对两个方法的处理,一个是HandlePointValues,这是对显示线上的点的坐标时的处理,一个是HandleCursorValues这是对获取最近曲线上的点的坐标时的处理。

这样看你的ZedGraph是开启的哪样设置。
假如是设置经过线上点时才显示
zgc.IsShowPointValues = true;
那么就要修改
HandlePointValues( mousePt );
这个方法
首先声明一个类变量
private object lastObj;
用来存储上一次使用的对象,然后找到其判断条件,添加当前是否与上一次是同一对象

然后在最后方法返回时将当前对象赋值给上一次对象。
lastObj = nearestObj;
完整参考代码
private Point HandlePointValues( Point mousePt )
{
int iPt;
GraphPane pane;
object nearestObj; using ( Graphics g = this.CreateGraphics() )
{ if ( _masterPane.FindNearestPaneObject( mousePt,
g, out pane, out nearestObj, out iPt ) )
{
if (nearestObj is CurveItem && iPt >= && !object.Equals(nearestObj, lastObj))
{
CurveItem curve = (CurveItem)nearestObj;
// Provide Callback for User to customize the tooltips
if ( this.PointValueEvent != null )
{
string label = this.PointValueEvent( this, pane, curve, iPt );
if ( label != null && label.Length > )
{
this.pointToolTip.SetToolTip( this, label );
this.pointToolTip.Active = true;
}
else
this.pointToolTip.Active = false;
}
else
{ if ( curve is PieItem )
{
this.pointToolTip.SetToolTip( this,
( (PieItem)curve ).Value.ToString( _pointValueFormat ) );
}
// else if ( curve is OHLCBarItem || curve is JapaneseCandleStickItem )
// {
// StockPt spt = (StockPt)curve.Points[iPt];
// this.pointToolTip.SetToolTip( this, ( (XDate) spt.Date ).ToString( "MM/dd/yyyy" ) + "\nOpen: $" +
// spt.Open.ToString( "N2" ) +
// "\nHigh: $" +
// spt.High.ToString( "N2" ) + "\nLow: $" +
// spt.Low.ToString( "N2" ) + "\nClose: $" +
// spt.Close.ToString
// ( "N2" ) );
// }
else
{
PointPair pt = curve.Points[iPt]; if ( pt.Tag is string )
this.pointToolTip.SetToolTip( this, (string)pt.Tag );
else
{
double xVal, yVal, lowVal;
ValueHandler valueHandler = new ValueHandler( pane, false );
if ( ( curve is BarItem || curve is ErrorBarItem || curve is HiLowBarItem )
&& pane.BarSettings.Base != BarBase.X )
valueHandler.GetValues( curve, iPt, out yVal, out lowVal, out xVal );
else
valueHandler.GetValues( curve, iPt, out xVal, out lowVal, out yVal ); string xStr = MakeValueLabel( curve.GetXAxis( pane ), xVal, iPt,
curve.IsOverrideOrdinal );
string yStr = MakeValueLabel( curve.GetYAxis( pane ), yVal, iPt,
curve.IsOverrideOrdinal ); this.pointToolTip.SetToolTip( this, "( " + xStr + ", " + yStr + " )" ); //this.pointToolTip.SetToolTip( this,
// curve.Points[iPt].ToString( this.pointValueFormat ) );
}
} this.pointToolTip.Active = true;
}
}
else
this.pointToolTip.Active = false;
}
else
this.pointToolTip.Active = false; //g.Dispose();
}
lastObj = nearestObj;
return mousePt;
}
具体其他优化与功能修改可自行发掘。
如果在ZedGraph中设置的是显示最近曲线上的点的坐标,即
zgc.IsShowCursorValues = true;
那么就要修改源码的HandleCursorValues方法
同样声明一个类变量存储上次获得的点
private Point lastMovedPoint;
然后在方法中加上判断并通过
this.pointToolTip.AutomaticDelay = ;
设置提示延迟1秒。最后再将当前点赋值给类变量。
lastMovedPoint = mousePt;
完整示例代码
private Point HandleCursorValues( Point mousePt )
{
GraphPane pane = _masterPane.FindPane(mousePt);
if (pane != null && pane.Chart._rect.Contains(mousePt) && !mousePt.Equals(lastMovedPoint))
{
// Provide Callback for User to customize the tooltips
if (this.CursorValueEvent != null)
{
string label = this.CursorValueEvent(this, pane, mousePt);
if (label != null && label.Length > )
{
this.pointToolTip.AutomaticDelay = ;
this.pointToolTip.SetToolTip(this, label);
this.pointToolTip.Active = true;
}
else
{
this.pointToolTip.Active = false;
}
lastMovedPoint = mousePt;
}
else
{
double x, x2, y, y2;
pane.ReverseTransform(mousePt, out x, out x2, out y, out y2);
string xStr = MakeValueLabel(pane.XAxis, x, -, true);
string yStr = MakeValueLabel(pane.YAxis, y, -, true);
string y2Str = MakeValueLabel(pane.Y2Axis, y2, -, true);
this.pointToolTip.AutomaticDelay = ;
this.pointToolTip.SetToolTip(this, "( " + xStr + ", " + yStr + ", " + y2Str + " )");
this.pointToolTip.Active = true;
} }
else
this.pointToolTip.Active = false; return mousePt; }
注:
这里只着重修改当用户重写此事件的情况下,即this.CursorValueEvent !=
null时,具体情况可跟据自己需要进行修改。
ZedGraph5.1.5源码与修改版源码下载
关注公众号:
霸道的程序猿
回复:
ZedGraph源码修改
ZedGraph5.1.5源码分析去掉鼠标悬浮内容闪烁问题(附源码下载)的更多相关文章
- Spring源码分析之IOC的三种常见用法及源码实现(二)
Spring源码分析之IOC的三种常见用法及源码实现(二) 回顾上文 我们研究的是 AnnotationConfigApplicationContext annotationConfigApplica ...
- [源码分析]Java1.8中StringJoiner的使用以及源码分析
[源码分析]StringJoiner的使用以及源码分析 StringJoiner是Java里1.8新增的类, 或许有一部分人没有接触过. 所以本文将从使用例子入手, 分析StringJoiner的源码 ...
- HDFS源码分析之FSImage文件内容(一)总体格式
FSImage文件是HDFS中名字节点NameNode上文件/目录元数据在特定某一时刻的持久化存储文件.它的作用不言而喻,在HA出现之前,NameNode因为各种原因宕机后,若要恢复或在其他机器上重启 ...
- Spring源码分析之IOC的三种常见用法及源码实现(一)
1.ioc核心功能bean的配置与获取api 有以下四种 (来自精通spring4.x的p175) 常用的是前三种 第一种方式 <?xml version="1.0" enc ...
- DRF cbv源码分析 restful规范10条 drf:APIView的源码 Request的源码 postman的安装和使用
CBV 执行流程 路由配置:url(r'^test/',views.Test.as_view()), --> 根据路由匹配,一旦成功,会执行后面函数(request) --> 本质就是执 ...
- 源码分析 Kafka 消息发送流程(文末附流程图)
温馨提示:本文基于 Kafka 2.2.1 版本.本文主要是以源码的手段一步一步探究消息发送流程,如果对源码不感兴趣,可以直接跳到文末查看消息发送流程图与消息发送本地缓存存储结构. 从上文 初识 Ka ...
- Spring事务源码分析专题(一)JdbcTemplate使用及源码分析
Spring中的数据访问,JdbcTemplate使用及源码分析 前言 本系列文章为事务专栏分析文章,整个事务分析专题将按下面这张图完成 对源码分析前,我希望先介绍一下Spring中数据访问的相关内容 ...
- Java源码分析:Guava之不可变集合ImmutableMap的源码分析
一.案例场景 遇到过这样的场景,在定义一个static修饰的Map时,使用了大量的put()方法赋值,就类似这样-- public static final Map<String,String& ...
- Spring源码分析之IOC的三种常见用法及源码实现(三)
上篇文章我们分析了AnnotationConfigApplicationContext的构造器里refresh方法里的invokeBeanFactoryPostProcessors,了解了@Compo ...
随机推荐
- Java中的8种基本数据类型
JAVA中的8种基本数据类型:byte short int long float double char boolean 特别说明: 1)char类型占2个字节,可以表示汉字.汉字和英文字符都占2个字 ...
- python随机生成字符
Python2: Unicode是一种通用的编码方式,不论是英文字母.汉字.日语还是其他文字都能够对应一个唯一的Unicode编码(序号). chr(100) # 得到整数对应的ascii码(小于25 ...
- JAVA编程学习之JAVA集合
一.JAVA集合类 为了保存数量不确定的数据,以及保存具有映射关系的数据(关联数组),java提供了集合类.所有集合类位于java.util包下. 集合类就像容是器,现实生活中容器的功能,无非就是添加 ...
- bind() 理解 【转】
bind()可稍后执行 call() apply() 为了搞清这个陌生又熟悉的bind,google一下,发现javascript1.8.5版本中原生实现了此方法,目前IE9+,ff4+,chro ...
- 《数据结构与算法分析-Java语言描述》 分享下载
书籍信息 书名:<数据结构与算法分析-Java语言描述> 原作名:Data Structures and Algorithm Analysis in Java 作者: 韦斯 (Mark A ...
- .Net Core中IOC容器的使用
打代码之前先说一下几个概念,那就是什么是IOC.DI.DIP 虽然网上讲这些的已经有很多了,我这里还是要再赘述一下 IOC容器就是一个工厂,负责创建对象的 IOC控制反转:只是把上端对下端的依赖,换成 ...
- [redis读书笔记] 第一部分 数据结构与对象 简单动态字符串
本读书笔记主要来自于<<redis设计与实现>> -- 黄键宏(huangz) redis主要设计了字符串,链表,字典,跳跃表,整数集合,压缩列表来做为基本的数据结构,实现键值 ...
- linux web站点常用压力测试工具httperf
一.工具下载&&安装 软件获取 ftp://ftp.hpl.hp.com/pub/httperf/ 这里使用的是如下的版本 ftp://ftp.hpl.hp.com/pub/httpe ...
- Flutter Widgets 之 FutureBuilder
注意:无特殊说明,Flutter版本及Dart版本如下: Flutter版本: 1.12.13+hotfix.5 Dart版本: 2.7.0 展示异步任务状态 当有一个Future(异步)任务需要展示 ...
- 基于webpack的vue开发环境搭建
1.新建并初始化项目(npm int -y),安装webpack,webpack-cli webpack-dev-server 安装eslint,eslint-plugin-vue,配置eslint语 ...