Rendering Issue when modifying valueAxis


#1

Hi Plumsail Team,

I’m trying to add some additional information(totals) to my value Axis and it’s seems to be working fine. But i get the following message after exiting the editor.

An Error has occurred during rendering. Please, get more detail in the browser console.

This is the script:

var handlers = {};
handlers.preRender = function(config, logger) {
  
  var categories = [];
  
  for(var i = 0; i < data.groups.length; i++){
      var groupItems = data.groups[i].items.length;
      categories.push(" Priority " + (categories.length*1+1) + ": " + groupItems + "");
  }

      var title = categories;
      config.legend.labels = title;
  
      config.valueAxis.title = {
            text: "YTD Total by Priority: &nbsp;" + categories
      }

   return true;

}

My preview looks fine.

Can you please help me out again or advise if there is a better way of adding those totals. Thank you!


#2

Dear Christian,
As you can see, the code works fine in the preview, but it doesn’t work when the chart is rendered.
The issue is that you are using data from Data Source section inside Dashboard Advanced section. Data is available globally during preview, but it’s not available globally when the chart is placed on a page.

What you need to do, is to define data as window.data in Data Source -> Advanced section, like this:

window.data = data;

Then use only references to window.data in Dashboard -> Advanced section:

var handlers = {};
handlers.preRender = function(config, logger) {
  
  var categories = [];
  
  for(var i = 0; i < window.data.groups.length; i++){
      var groupItems = window.data.groups[i].items.length;
      categories.push(" Priority " + (categories.length*1+1) + ": " + groupItems + "");
  }

      var title = categories;
      config.legend.labels = title;
  
      config.valueAxis.title = {
            text: "YTD Total by Priority: &nbsp;" + categories
      }

   return true;

}

That should work. Just make sure to define window.data in the appropriate event, after all the others, so it returns the correct data.


#3

Wow! You did it again!

It works perfectly now. I remembered having to do that for another list. I’ll keep this in mind moving forward.
Again, Love the tool! Great product.

PS: was able to figure out styling too. it was the order i placed it.

config.valueAxis.title = {
    text: "YTD Total by Priority: &nbsp;" + categories
  }
config.valueAxis.title.font = "20px 'Segoe UI',sans-serif";

Thanks you!