Setting Chart Tooltip is throwing a reference error since update last night

  • 1
  • Problem
  • Updated 4 years ago
  • Solved
  • (Edited)
Over the past few days I developed a script to use with charts to update their tooltip with additional data using the "Before Render Snippet" option on a chart

This was working and demo'd yesterday, however I came in this morning to a message from my boss saying none of the charts I modified are working.

I'm now getting this error "Uncaught TypeError: Cannot set property 'formatter' of undefined"

Inspecting the chart object I see the Tooltip node is no longer exposed, was this changed? 

I also checked the installed package and I can see the following

"Modified By Skuid, 18/02/2015 02:02" so it looks like a new minor version of the package was pushed last night? 

Below is a simpler version of my code that causes the same error:

var chart = arguments[0]
chart.tooltip.formatter = function(){
s = 'my test string';
return s;
}
 
Photo of Eoin O'Neill

Eoin O'Neill

  • 144 Points 100 badge 2x thumb

Posted 4 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
I'll ask "the Charts man" (J Tingle) to follow up with more details here, but my understanding is that with this point release, Skuid's default tooltip formatting settings for charts were moved into the plotOptions property for each Chart type (e.g. chartObj.plotOptions.funnel.tooltip) and into Series-specific tooltip properties (e.g. chartObj.series[0].tooltip), as appropriate for settings which should be global to the chart type (such as the pointFormatter for the Funnel chart) and settings which should be series-specific, since each series points can be on different fields (such as the number of decimals, prefix, and suffix, which will be different from field to field) This would account for the tooltip property having disappeared from the chart object in your before render snippet.

That being said, you should still be able to set a global tooltip property, but to future-proof yourself from any changes Skuid may make to our default Chart configurations for a particular Chart type, I would highly recommend that you always check to see if a given property, such as tooltip, is defined before assigning properties to it, like this:


var chart = arguments[0];
// Override the tooltip globally, for all series
// First, make sure tooltip has been defined,
// and if not, define it
var tooltip = chart.tooltip;
if (!tooltip) tooltip = chart.tooltip = {};
tooltip.formatter = function(){
    s = 'my test string';
    return s;
};
Photo of J.

J., Official Rep

  • 7,470 Points 5k badge 2x thumb
Charts man, here! Zach got the solution: chart.tooltip isn't defined. Previously, chart.tooltip was always defined, even if it was empty, so the snippet worked. With this latest release, we only define it when it's being used (no use in sending extra chart configuration off to the charting library). Does this get you back up and running?
Photo of Eoin O'Neill

Eoin O'Neill

  • 144 Points 100 badge 2x thumb
Thanks, will have a look at this now. 
Photo of Eoin O'Neill

Eoin O'Neill

  • 144 Points 100 badge 2x thumb
Yep, back up and running with that solution, appreciate the quick turnaround on a response.