AnsweredAssumed Answered

Total in centre of pie/donut with slice labels

Question asked by Dean Flinter on Dec 12, 2017
Latest reply on Dec 12, 2017 by Dean Flinter

Hi,

 

I tried combining the totals in bar chart as seen here: Stacked-Bar chart with Category Total Labels at the top of the plot panel - JSFiddle  with one that has the total at the centre of a pie/donut chart as seen here: Donut chart with a total label in the center - JSFiddle

 

I want to preserve the slice labels so I used the approach from the bar one to add a new label to the pie. However the chart does not appear. There is no error, it's just blank. Code is below

 

var cccOptions = this.chartDefinition;

var eps = Dashboards.propertiesArrayToObject(cccOptions.extensionPoints);  

 

 

eps.plot_add = function() {

                return new pv.Label()

.text(

function() {

          var data = this.scene.group.parent;

          var valueDimName = this.panel.visualRoles.value

.firstDimensionName();

          var valueDim = data.dimensions(valueDimName);

          var total = valueDim.sumAbs();

         return valueDim.format(total);

        }

        )

.font('bold 12px sans-serif')

.visible(function() { return !this.index; })

.left(null)

.top(null)

.textAngle(0)

.textAlign('center')

.textBaseline('middle')

                  

  };

cccOptions.extensionPoints = Dashboards.objectToPropertiesArray(eps);

 

If however, I change the .text part to simply .text('Test'), the chart appears with Test in the centre as seen below

 

DonutTotal.PNG

 

It appears the function in .text is causing the issue despite working as per the example fiddle. It is clearly because the function is for a different purpose which is not suitable for what I want but unfortunately I do not know enough about this to fix it.

 

Duarte Leao your help is much appreciated

 

Thanks!


Dean

Outcomes