简体   繁体   English

如何在angularjs中自定义Flot工具提示?

[英]How to customize flot tooltip in angularjs?

Is there a way to change flot tooltip look something like below image (mainly shape with arrow pointing down)? 有没有一种方法可以改变浮点工具提示的外观,例如下面的图像(主要是带有向下箭头的形状)?

在此处输入图片说明

Below is how I get my tooltip currently. 以下是我目前如何获得工具提示的方法。

在此处输入图片说明

my tooltip function 我的工具提示功能

var translateDateTooltip = function(value) {
    if (value == null || value == undefined)
        return value;
    var monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
    var myDate = new Date( value );
    return myDate.getDate() + " " + monthNames[myDate.getMonth()] + " "+myDate.getFullYear();
}

var toolTipContent = function(label, x, y, z) {
    // format the content of tooltip
    // "%s | Date: %x | Count: %y"
    var str = "";
    if (label == "Volume") {
        str = label+" | Date: "+translateDateTooltip(parseInt(x))+" | Volume Count: "+y;
    } else
        str = label+" | Date: "+translateDateTooltip(parseInt(x))+" | Count: "+y;
    return str;
};

As I said in my comment this level of customization is not available in the tooltip plugin, so code it yourself. 正如我在评论中说的那样,此级别的自定义在工具提示插件中不可用,因此请自行编写代码。 You don't even really need bootstrap. 您甚至根本不需要引导程序。

CSS for an "arrowed" tooltip . 用于“箭头” 工具提示的 CSS。

.tooltip {
      display: none;
      position: absolute;
      width: 100px;
      height: 20px;
      line-height: 20px;
      padding: 10px;
      font-size: 14px;
      text-align: center;
      color: rgb(113, 157, 171);
      background: rgb(255, 255, 255);
      border: 4px solid rgb(255, 255, 255);
      border-radius: 5px;
      text-shadow: rgba(0, 0, 0, 0.0980392) 1px 1px 1px;
      box-shadow: rgba(0, 0, 0, 0.0980392) 1px 1px 2px 0px;
}

.tooltip:after {
      content: "";
      position: absolute;
      width: 0;
      height: 0;
      border-width: 10px;
      border-style: solid;
      border-color: #FFFFFF transparent transparent transparent;
      top: 44px;
      left: 50px;
}

And add a plothover event: 并添加一个plothover事件:

plotArea.bind("plothover", function(event, pos, item) {
    var tip = $('.tooltip');
    if (item) {
      var offset = plot.getPlotOffset();
      var axis = plot.getAxes();
      var yValue = item.datapoint[1];
      var xValue = item.datapoint[0];
      tip.css('left', axis.xaxis.p2c(xValue));
      tip.css('top', axis.yaxis.p2c(yValue) + 20);
      tip.html(yValue.toFixed(0) + ' tasks used');
      tip.show();
    } else {
      tip.hide();
    }
  });

Example here , continued from your previous questions. 这里的示例,从您之前的问题继续。

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

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