- 浏览: 212850 次
- 来自: ...
文章分类
最新评论
-
nbh219:
插件只有这几行代码吗jQuery.fn.dataTableEx ...
在Datatables中加入错误提示功能 -
radio123:
好用,谢了!就是有一点问题,如果DataGird 有分页栏,会 ...
JQuery Easy UI —— 如何让DataGrid自适应页面宽度 -
loafer:
这种方式是将工程发布为war还是ear?因为以前也这样写过,但 ...
Weblogic 10.3.6 解决Jar包冲突,hibernate等。 -
springdata:
spring data jpa相关代码demo下载:http: ...
Spring Data JPA 使用感受 -
coolboy09:
楼主,能否给个完整的例子?在下在用jqplot绘图时,在添加了 ...
jqPlot 实现动态显示数据,防止内存溢出的实现。
喜欢用jqplot的朋友一定碰到图形下标文字很长,会出现相互之间重叠的情况,如下图所示:
这是时候,我们就必须在显示底部文字的时候进行处理,比如限定文字的长度等,如:今年收入增...
下面给出扩展的源码:
jqplot.categoryAxisRenderer.extend.js
大家注意红色字体的代码,这是对原有的源码做了一些修改,增加了设置Tick最大长度的属性字段以及对Tick超过长度时候的控制。
使用方法:
在HTML或JSP中引入jqplot的插件:
<script type="text/javascript" src="../jqplot/jqplot.categoryAxisRenderer.min.js'}"></script>
然后在其后面引入扩展插件:
<script type="text/javascript" src="../jqplot/jqplot.categoryAxisRenderer.extend.js'}"></script>
并在创建jqplot的时候设置属性:
效果如下图所示:
这是时候,我们就必须在显示底部文字的时候进行处理,比如限定文字的长度等,如:今年收入增...
下面给出扩展的源码:
jqplot.categoryAxisRenderer.extend.js
/** * 本扩展插件是对jqplot插件jqplot.categoryAxisRenderer的扩展,主要修改了显示图形下标Tick的处理, * 在显示Tick之前,判断Tick标签的长度,当标题长度超过tickMaxLength定义的长度时,截获前 * tickMaxLength - 1个字符,然后加上省略号。 * * 作者:苏显斌 */ (function($) { $.jqplot.CategoryAxisRenderer.prototype.createTicks = function() { // we're are operating on an axis here var ticks = this._ticks; var userTicks = this.ticks; var name = this.name; // databounds were set on axis initialization. var db = this._dataBounds; var dim, interval; var min, max; var pos1, pos2; var tt, i; // X轴的标题文字最大长度 var tickMaxLength = this.tickMaxLength; // if we already have ticks, use them. if (userTicks.length) { // adjust with blanks if we have groups if (this.groups > 1 && !this._grouped) { var l = userTicks.length; var skip = parseInt(l/this.groups, 10); var count = 0; for (var i=skip; i<l; i+=skip) { userTicks.splice(i+count, 0, ' '); count++; } this._grouped = true; } this.min = 0.5; this.max = userTicks.length + 0.5; var range = this.max - this.min; this.numberTicks = 2*userTicks.length + 1; for (i=0; i<userTicks.length; i++){ tt = this.min + 2 * i * range / (this.numberTicks-1); // need a marker before and after the tick var t = new this.tickRenderer(this.tickOptions); t.showLabel = false; // t.showMark = true; t.setTick(tt, this.name); this._ticks.push(t); var t = new this.tickRenderer(this.tickOptions); // 当标题长度超过tickMaxLength定义的长度时,截获前tickMaxLength - 1个字符, // 然后加上省略号。 if (tickMaxLength) { var userTick = userTicks[i].length <= tickMaxLength ? userTicks[i] : userTicks[i].substring(0, (tickMaxLength - 1)) + '...'; t.label = userTick; } else { t.label = userTicks[i]; } // t.showLabel = true; t.showMark = false; t.showGridline = false; t.setTick(tt+0.5, this.name); this._ticks.push(t); } // now add the last tick at the end var t = new this.tickRenderer(this.tickOptions); t.showLabel = false; // t.showMark = true; t.setTick(tt+1, this.name); this._ticks.push(t); } // we don't have any ticks yet, let's make some! else { if (name == 'xaxis' || name == 'x2axis') { dim = this._plotDimensions.width; } else { dim = this._plotDimensions.height; } // if min, max and number of ticks specified, user can't specify interval. if (this.min != null && this.max != null && this.numberTicks != null) { this.tickInterval = null; } // if max, min, and interval specified and interval won't fit, ignore interval. if (this.min != null && this.max != null && this.tickInterval != null) { if (parseInt((this.max-this.min)/this.tickInterval, 10) != (this.max-this.min)/this.tickInterval) { this.tickInterval = null; } } // find out how many categories are in the lines and collect labels var labels = []; var numcats = 0; var min = 0.5; var max, val; var isMerged = false; for (var i=0; i<this._series.length; i++) { var s = this._series[i]; for (var j=0; j<s.data.length; j++) { if (this.name == 'xaxis' || this.name == 'x2axis') { val = s.data[j][0]; } else { val = s.data[j][1]; } if ($.inArray(val, labels) == -1) { isMerged = true; numcats += 1; labels.push(val); } } } if (isMerged && this.sortMergedLabels) { labels.sort(function(a,b) { return a - b; }); } // keep a reference to these tick labels to use for redrawing plot (see bug #57) this.ticks = labels; // now bin the data values to the right lables. for (var i=0; i<this._series.length; i++) { var s = this._series[i]; for (var j=0; j<s.data.length; j++) { if (this.name == 'xaxis' || this.name == 'x2axis') { val = s.data[j][0]; } else { val = s.data[j][1]; } // for category axis, force the values into category bins. // we should have the value in the label array now. var idx = $.inArray(val, labels)+1; if (this.name == 'xaxis' || this.name == 'x2axis') { s.data[j][0] = idx; } else { s.data[j][1] = idx; } } } // adjust with blanks if we have groups if (this.groups > 1 && !this._grouped) { var l = labels.length; var skip = parseInt(l/this.groups, 10); var count = 0; for (var i=skip; i<l; i+=skip+1) { labels[i] = ' '; } this._grouped = true; } max = numcats + 0.5; if (this.numberTicks == null) { this.numberTicks = 2*numcats + 1; } var range = max - min; this.min = min; this.max = max; var track = 0; // todo: adjust this so more ticks displayed. var maxVisibleTicks = parseInt(3+dim/10, 10); var skip = parseInt(numcats/maxVisibleTicks, 10); if (this.tickInterval == null) { this.tickInterval = range / (this.numberTicks-1); } // if tickInterval is specified, we will ignore any computed maximum. for (var i=0; i<this.numberTicks; i++){ tt = this.min + i * this.tickInterval; var t = new this.tickRenderer(this.tickOptions); // if even tick, it isn't a category, it's a divider if (i/2 == parseInt(i/2, 10)) { t.showLabel = false; t.showMark = true; } else { if (skip>0 && track<skip) { t.showLabel = false; track += 1; } else { t.showLabel = true; track = 0; } t.label = t.formatter(t.formatString, labels[(i-1)/2]); t.showMark = false; t.showGridline = false; } t.setTick(tt, this.name); this._ticks.push(t); } } }; })(jQuery);
大家注意红色字体的代码,这是对原有的源码做了一些修改,增加了设置Tick最大长度的属性字段以及对Tick超过长度时候的控制。
使用方法:
在HTML或JSP中引入jqplot的插件:
<script type="text/javascript" src="../jqplot/jqplot.categoryAxisRenderer.min.js'}"></script>
然后在其后面引入扩展插件:
<script type="text/javascript" src="../jqplot/jqplot.categoryAxisRenderer.extend.js'}"></script>
并在创建jqplot的时候设置属性:
$.jqplot(chartContainerId, chartData, { ... axes : { xaxis : { renderer : $.jqplot.CategoryAxisRenderer, rendererOptions : { fillToZero : true, tickMaxLength : 6 // 设置该属性后,将自动限制标题长度 }, ticks : ticks } ... } });
效果如下图所示:
发表评论
-
Java网络爬虫经验分享
2018-04-20 09:50 744最近三年很少写博客,虽然一直从事IT行业,但更多的是管理工作, ... -
亲测国外很快的Maven镜像
2016-11-23 14:29 4933亲测速度非常理想,并且不会像阿里的镜像很多包下载不下来。在自己 ... -
再谈Java获取classepath路径问题
2016-08-09 14:04 0网上很多文章介绍如何获取Java的classpath路径,这里 ... -
禁用HTML超链接URL的双击
2015-05-26 10:30 1042有时候我们希望控制用户在点击URL超链接的时候,只允许点击一次 ... -
Java中判断文件是否是图片文件
2014-08-17 23:20 18199使用Image读取文件时,如果是非图像文件,则会返回null。 ... -
Weblogic 10.3.6 解决Jar包冲突,hibernate等。
2014-07-06 16:30 7392Weblogic的jar包冲突困扰了我一段时间,一般使用的是如 ... -
javascript 动态显示家庭人物结构关系图
2014-01-07 23:53 7092<!DOCTYPE html PUBLIC &quo ... -
Jquery EasyUI中级篇
2013-12-23 16:08 2324JQuery EasyUI是一个很不错的Javascript开 ... -
JavaScript中,快速实现一个对象的复制!
2013-03-01 15:28 10351、第一种方式,通过JSON转换。 function cl ... -
Java路径问题解决方案汇集
2013-02-17 13:54 1502最近查看了网上很多关于路径问题资料大概总结了一下: Java ... -
EasyUI中,DataGrid的错误处理方式。
2013-02-06 17:06 0话说,JQuery EasyUI是一个非常优秀的JQuery框 ... -
再议JQuery中Ajax内存溢出问题。
2013-01-29 12:05 5816发现有人挺感兴趣Javascript中的内存溢出,本人经验发现 ... -
最近好新闻不断
2012-12-14 08:36 976Spring Framework 3.2 GA 发布 ... -
对jqplot的CategoryAxisRenderer插件进行扩展,底部Tick在鼠标在上时浮动显示名称。
2012-11-30 09:04 3411在前一篇文章中介绍了如何让jqplot的柱形图tick下标出现 ... -
zTree 如何自动选中节点
2012-11-20 13:40 6212下列代码可以使用在弹出树或者动态选中树的节点时使用: ... -
在Datatables中加入错误提示功能
2012-10-08 17:32 15291经常用Datatables的童鞋一定碰到过当采用服务端请求的时 ... -
jqplot 实用技巧——重绘
2012-09-18 08:46 4342技巧一: 当浏览器窗体大小改变时: $('#resizab ... -
jqPlot 实现动态显示数据,防止内存溢出的实现。
2012-09-12 16:06 6528jqPlot是一个十分强大、 ... -
让你的Play framework 1.2 支持Ajax!
2012-08-16 15:14 3291相信正在使用Play Framework 1.2的朋友一定会碰 ... -
Play Framework 使用后感想——大型项目还是回归原生态吧!
2012-08-07 08:04 21最近几个星期都在接触Play Framework的东西,总结一 ...
相关推荐
jQuery文字溢出显示省略号插件是一款基于dotdotdot.js插件实现的单行多行文本溢出显示省略号
CSS实现多行文字显示省略号效果.zip
dotdotdot.js插件是一款基于jQuery实现的单行多行文本文字内容超出溢出部分显示省略号的代码。
多格式多行文字显示省略号插件,总共有两种方法,一个是直接用jq写的简单代码。另一个是jq的插件,支持多种显示省略号的方式,例如在省略号后面加“查看详情”等,为了明显效果,把overflow注释了,在IE6下查看的话...
js文字超出省略号特效
文件为jquery简单封装方法,需要先引入jquery,调用方法: $(function(){ $('.test').wordLimit(30) })
HTML CSS 省略号代码 超过长度省略号显示点击全部可以显示等 超出范围自动变成省略号,但鼠标可以选择文字,酷吧……
wpf Textblock 文字过长时,中间用省略号代替。有好的方法,请回复
jquery实现超出部分省略号显示
视频与票的图标跟在标题后面显示,当标题过长时icon显示到省略号…后(textview省略号显示,图标自动靠后)。 二、问题解决 TextView可以通过 android:ellipsize=end android:singleLine=true实现单行省略, 但是...
网页文字溢出显示省略号jQuery插件代码.zip
Android动态点点省略号效果的等待控件,可直接运行查看效果
jquery带省略号分页,已经亲自测试过,最近公司要求的做的分页效果就是用的这片代码
带省略号显示的CStatic控件,扩展自CWnd类,能使用省略号方式按需显示长路径,按需设置格式。
//溢出用省略号显示 white-space:nowrap; //溢出不换行 但是第三条属性,只能显示一行,不能用在这里,那么如果显示多行呢? 超出两行隐藏: css3解决了这个问题,解决方法如下: display:-webkit-box; //将对象作为...
一个支持火狐浏览器的自动显示省略号插件,并附有应用示例,这个插件可以根据网页的布局大小智能显示出省略号,和CSS中的overflow属性有相似这处,本代码加入了JS的控制,更人性化的实现省略号的显示。
DIV内多行文字垂直居中,并且超过固定行数时显示省略号
Jquery中用于省略字符过长的插件。在网页中经常会遇到字符溢出,然后使用省略“...”字符来代替溢出的文本。
js 将多出的字符串用省略号代替 不是一般的那样获取字符串长度和字符字节来判断哦 ^_^ ;基本思路 ;很简单
该分页插件可以设置前后显示的页码数,中间带有类似省略号的分割符。使用时,注意要引入jquery。