63
Views
1
Comments
[OutSystems Charts] Inserting calculated percentage into the bar chart label
outsystems-charts
Reactive icon
Forge asset by OutSystems
Application Type
Reactive

Hello community,

I'm working with OutSystems Charts for reactive applications in version 1.3.0. Currently, I'm using a Column chart, where the 'SourceDataPointList' list is being filled correctly, and the 'value' attribute is an integer.

My need is to display the 'dataLabel' on each column of the chart with the value of the 'value' attribute, and next to it, a calculated value corresponding to the percentage of that value relative to the total. However, I'm having trouble performing this calculation and displaying the percentage.

Upon researching, I found that Highcharts has an attribute called 'percentage', but this value is not being filled. I'm using the following JSON in 'HighchartsJSON':

plotOptions: {

        series: {

            borderWidth: 0,

            cursor: 'pointer',

            dataLabels: {

                enabled: true,

                format: '{point.y:.0f} :{point.percentage:.1f} %'

            }

        }

    }

However, since the 'point.percentage' attribute does not have a value, the percentage is not displayed. I tried adding a 'load' event with the function that calculates and fills the 'percentage' attribute. In the examples provided on the Highcharts website, this works correctly, but when added to OutSystems, nothing happens. Apparently, the event is not being triggered.

Here is the code snippet I created to calculate the percentage:

    chart: {

        events: {

          load: function() {

              var series = this.series[0];

              var total = 0;

              (series.points).forEach(function(point, i){

                  total += point.y;

              });

              (series.points).forEach(function(points, i){

                  points.update({percentage:(points.y/total)*100});

              });

              (series.points).forEach(function(points, i){

                  points.update({dataLabels:{enabled:true,format:'{point.percentage:.2f}%'}});

              });

            }

        }

    },

No errors are logged in the console, and when I insert a console.log for testing, nothing is logged, which increases my suspicion that the event is not being executed.

Any help will be appreciated.

Thank you.


ChartTest_Bar.oml
Print_ChartBar.png
2022-11-12 11-28-30
Gonçalo Martins
Staff

Hello @David Marcondes 

Have you considered updating the OutSystems Charts version to the latest one that contains a new offer with many more options to achieve almost all the customizations you need?

If you can't for some reason, share a sample oml but bare in mind that you're using a really old version of this asset.

Cheers,
GM


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.