How to make a column chart value label display N/A for empty columns?
Hi, I have a column chart which displays the % of documents approved on time each month for the past 3 months by location. The value is the total that were approved on time out of the total documents, so a 0% represents that none of the documents were approved on time that month, whereas a blank bar represents that there were no documents for that month/office. For the blank bars I want the value labels to say N/A because without any bars it's really difficult to tell which month is which, but I'm not sure how to achieve this. Thoughts?
I did add some dummy data into the dataset so that even in months when an office doesn't have any documents, a row still exists for that office/month, with nulls for all of the document data including the approved_on_time field. In the document rows, approved_on_time is 1 if it was approved on time and 0 if it wasn't. I added the dummy data so that even when there are no documents for a particular office/month, the chart will still display all 3 months with no bars (rather than showing a No Results chart).
I don't speak javascript but I asked ChatGPT to rewrite it based on my goal and the current issue, and it actually worked:
widget.on('beforeviewloaded', (scope, args) => { Object.keys(args.options.plotOptions).forEach((chartType) => { const origFn = args.options.plotOptions[chartType].dataLabels.formatter; args.options.plotOptions[chartType].dataLabels.formatter = function (point) { const self = this; return function (point) { const formattedValue = origFn.apply(this, [point]); // Apply the original formatter // Convert the formatted value to a number const numericValue = parseFloat(formattedValue); // If the value is negative, display 'N/A'; otherwise, show the formatted value const value = (numericValue < 0 || isNaN(numericValue)) ? 'N/A' : formattedValue; return value; }; }.call({ original: true }); }); });
So thank you for getting me 99% of the way there, and thank the robots for figuring out the last piece!