Using function () to create a dynamic response

The following code works:

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

I am trying to show some dynamically calculated data in the "content", so I am trying to use a function. Even my simplest example does not work, I get the 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
source share
1 answer

I assume you use the tooltip for the tooltips here. I encoded a sample script, here , that uses a functionproperty format content. Please note that your feedback is incorrect:

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

But even without these arguments, I could not reproduce your mistake.

+2
source

Source: https://habr.com/ru/post/1523712/


All Articles