繁体   English   中英

在FLOT图中自定义工具提示

[英]Customize tooltip in FLOT graph

我正在使用FLOT显示图形。

要显示tootip,我正在使用https://github.com/krzysu/flot.tooltip

现在,我想自定义工具提示的内容,因此我在使用回调来设置工具提示的内容。 程式码片段:

tooltip: true,
  tooltipOpts: {
    content: function(label, xval, yval, flotItem){
      var xAxis = plot.getXAxes();
      return xval;
    },
    defaultTheme: false
} 

但是它给我错误

caught TypeError: Object function (label, xval, yval, flotItem){
            var xAxis = plot.getXAxes();
            return xval;
           } has no method 'replace' 

有人可以帮我吗?

提前致谢。

该文档指出:

如果您需要对工具提示的生成方式进行更多控制,则可以传递一个回调函数(label,xval,yval,flotItem),该函数必须返回具有所述格式的字符串

xval是工具提示所在的x轴数字值。 它不是字符串。 它失败的replace方法是标准string.replace:

 > "".replace
 function replace() { [native code] }

我没有使用flot工具提示。 有更简单的方法来显示工具提示并对其进行自定义。 看看这个提琴手:

http://jsfiddle.net/Margo/yKG7X/5/

$(“#placeholder”)。bind(“ plothover”,function(event,pos,item){if(item){
$( “#提示”),删除()。

  var x = item.datapoint[0], y = item.datapoint[1]; showTooltip(item.pageX, item.pageY, x + " / " + y ); } }); 
function showTooltip(x, y, contents) {
    $('<div id="tooltip">' + contents + '</div>').css({
        position: 'absolute',
        display: 'none',
        top: y + 5,
        left: x + 5,
        border: '1px solid #fdd',
        padding: '2px',
        'background-color': '#fee',
        opacity: 0.80
    }).appendTo("body").fadeIn(200).fadeOut(6000);
}

希望能帮助到你 :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM