Pie chart / not showing % option?


#1

if I create a pie chart such as this:

I can show the label and how the data representing the volume.
But I can’t show also the percentage.

Example:"[quote]634 rows / 63%[/quote]"


#2

can I do with a piece of code in the chart handler?


#3

We can’t see your screenshot.


#4

Better ? (issue with Dropbox, apologies)


#5

You can just put in tab DataSource -> Advanced this code into handler.finish:

var sum = 0; data.items.reduce(function(a, b) { sum+=a.value; // value is name of field which you calculate return b; }); $.each(data.items, function(index,object){ object.sum = sum;});

and in Dashboard -> Style -> Labels -> template put this:

#=Math.round((dataItem.value*100/dataItem.sum),1)# %

where “value” is name of field, which value you want to show.


#6

added as requested:

[code]handlers.finish = function(data, logger) {
logger.debug('Data is processed: ', data);

var sum = 0;
data.items.reduce(function(a, b) {
sum+=a.dyrr; // value is name of field which you calculate
return b;
});
$.each(data.items, function(index,object){
object.sum = sum;});

return true;
}[/code]

the process failed:

[quote]11:35:06 DEBUG - Data is initialized: {
items: [object Object],[object Object],[object Object],[object Object],[object Object]
}
11:35:06 INFO - Initialization succeeded.
11:35:06 INFO - Request initialization succeeded.
11:35:06 INFO - Request succeeded.
11:35:06 INFO - Aggregation succeeded.
11:35:06 DEBUG - Data is processed: {
items: [object Object],
groups: [object Object]
}
[color=#FF0000]11:35:06 ERROR - Post-processing failed: TypeError: data.items.reduce is not a function[/color][/quote]


#7

Try this one, please

var sum = 0;
$.each( data.items, function(index, object){
sum+= object.dyrr;})
$.each(data.items, function(index,object){
object.sum = sum;});
And tell, please, what browser do you use.


#8

Hi,
I’m trying to do the same here and are using the example that you have posted. But I’m just getting NaN % om my graphs, any idea what I’m am doing wrong?





#9

Please, provide a screenshot of Dashboard -> Style -> Tooltip section.


#10

Here it is.



#11

Wrap your code in the Advanced tab into:

var handlers = {};
handlers.finish = function(data, logger) {
// your code here
return true;
}


#12

Hi Dmitry

Thanks for the help so far!
I added the handler wrapping but are getting the same result, any idea or other way to show the percentage?



#13

Put the code to Data source -> Advanced.


#14

Hi,
This is regarding the same issue.

In this Ordre Count is 16.
Tapt count is 7.

I need to display it as percentage : 70% and 30 %

When I enter #=Math.round((dataItem.value*100/dataItem.sum),1)# % this calculation on

Dashboard–>Style–>Labels ----> Template I got the value as Nan%

But when I copy this code #=(dataItem.value)# % on Dashboard–>Style–>Labels ----> Template
it return as Ordre % and Tapt %. That means dataitem.value will return the value of a field not the count.

These are the screen shots. Pls help me to resolve this







#15

Here is my screen shots of Dashboard Style and Results




#16

Hi and also when I harcoded the sum value in DataSource—>Advanced—> handlers.finish

this won’t return on dataitem.sum on Dashboard—> Style —> Labels—> Template


#17

Good Afternoon,

Has there been any progress on this issue? I am experiencing the same NaN% issue when following all of the steps listed above. Any help would be greatly appreciated.

Thanks,