Forum Discussion

lring's avatar
lring
Cloud Apps
11-27-2024
Solved

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...
  • lring's avatar
    lring
    12-06-2024

    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!