Jump to content
Changes to the Jaspersoft community edition download ×

Pie chart with percentage (how to find the total?)


leeyuiwah

Recommended Posts

(This question can also be cast as "how to find the final total while walking through each row of a dataset")

I want to plot a pie chart.  In the label expression, I want to show the
percentage of each category in the overall total (i.e. the value of each
key with respect to the overall total)

So I wrote the Label Expression to be

NumberFormat.getPercentInstance().format($F{num_incidents}.floatValue()/$V{totalNumIncident}.longValue())

Here the $F{num_incidents} is the value of each row while
$V{totalNumIncident} is my lame attempt to final the overall total

$V{totalNumIncident} is calculated with the following settings

Calculation Type: Sum
Reset Type: Report
Increment Type: None
Variable Expression: $F{num_incidents}
Initial Value Expression: new Long(0)

However, what I found is that the variable $V{totalNumIncident} was
the *running total* at the time each row of the dataset was examined
(i.e. when each category in the pie chart was plotted) but not the *final
total*, so the precentages were all wrong.

The final total (of all categories) can only be known when all rows have
been walked through (all categories plotted), but when I plot each
category, I need to know the final total.  It looks like I need two
passes of walking through the data.  But I don't know how to express
that in iReport.

Thanks!

Clement
 

Link to comment
Share on other sites

  • Replies 12
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

In JasperReports version 3.1.0, we have introduced two new properties to control the appearenace of section labels and legend labels. These two are called labelFormat and legendLabelFormat.

You can use {0}, {1} and {2} for displaying the key, the value and the percentage in pie charts.

For these formats to be used, you have to leave the labelExpression empty.

I hope this helps.

Teodor

 

Link to comment
Share on other sites

  • 2 weeks later...

Teodord,

Thanks for your advice. I am using the last releases of iReport (3.1.2) and Jasperserver (3.1.0) but I cannot see in Ireport the new properties you described.

But it's true that by changing the "theme" property from nothing to "simple" I get a pie with labels containing both key and percentage, which is good for me.

So my question is : what have I to do to access the new properties you spoke about. Am I obliged to use a "theme" definition?

Thanks for your answer.

Link to comment
Share on other sites

Teoder,

Thanks for your answer.  Now that after I upgrade to JS 3.1, I have the same question as Gaby38 and mpgm above.  I could not an editable property called  labelFormat or legendFormat.

In fact, even if I save the JRXML file, there are no such string in the file.

I do see that if I changed the theme from "nothing" to simple, then in the labels the percentages would be displayed.  Unfortunately this is not good enough for me, because I am also asked to display the value.

Thanks! Happy New Year!

Clement

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

These two new settings for pie charts are available to all chart themes. You are not forced to use a particular chart theme to make use of them.

However, the problem is that they are still missing from the iReport editor and we should log this as a bug.

In the meantime, the only way to get around this is to edit them manually in the JRXML.

Check the pie chart samples in the /demo/samplescharts folder of the JR project package.

 

I hope this helps.

Teodor

 

Link to comment
Share on other sites

Gaby38,

 

Sorry, there is no simple way to set the font. You can set the legend font, but not the label font.

 

To set the label font you would need to make a change to the chart customizer to expose this property. I've had this request before. It would be great if you could log this as an enhancement request.

 

Regards,
Matt

Link to comment
Share on other sites

  • 4 weeks later...

Hi,



How to display the fractional values in Pie chart...........

<pie3DPlot labelFormat="{0} {2}" legendLabelFormat="{0} {1}">
     <plot/>
    </pie3DPlot

Using this i can display only decimal values.....
Like 20% 55%..........

I want to display output in pie chart like 12.25%, 55.30%, 0.05%.........

How can implement this..............



Post Edited by pentaho pentaho at 02/17/09 13:08
Link to comment
Share on other sites

  • 4 months later...

pentaho
Wrote:
 

Hi,



How to display the fractional values in Pie chart...........

<pie3DPlot labelFormat="{0} {2}" legendLabelFormat="{0} {1}">
     <plot/>
    </pie3DPlot

Using this i can display only decimal values.....
Like 20% 55%..........

I want to display output in pie chart like 12.25%, 55.30%, 0.05%.........

How can implement this..............



Post Edited by pentaho pentaho at 02/17/09 13:08

Please give me your ideas for create aboue pie chart.

Link to comment
Share on other sites

  • 2 years later...

I use {2} in a pie chart to display the percentage. However 2 problems remain:

1. format decimal presicion (i need 2 fraction digits)

2. Exclude "0 %" values. Zeroes come from my datasource and shell be present in a crosstab above the chart but not in the chart itself. A subreport would be a workaround.

I can implement 1+2 in JasperReports. Question about that:

- is there an interest to have this features in the official project?

- if yes, a discussion of the XML-design for configuration is needed.

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...