Using function() to create dynamic response

妖精的绣舞 提交于 2019-12-11 13:59:33

问题


The following code works:

tooltipOpts: {
  content: "%s : %y",
  shifts: {
  x: -30,
  y: -50
  }
}

I am trying to show some dynamically calculated data in "content" so am trying to use a function. Even my most basic example isn't working, I get error shown below:

 tooltipOpts: {
   content: function() {
     return "%s : %y";
   },
   shifts: {
     x: -30,
     y: -50
   }
 }


Uncaught TypeError: Object function () {
    return "%s : %y";
} has no method 'replace' 

回答1:


I'll assume you are using the tooltip plugin from here. I've coded up a fiddle example, here, that uses the function format of the content property. Note that your callback signature it incorrect:

content: function(label, xval, yval, flotItem){ // expects to pass these arguments
    return "%s : %y";
},

But even without those arguments, I couldn't reproduce your error.



来源:https://stackoverflow.com/questions/21356005/using-function-to-create-dynamic-response

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!