I'm getting a few problems to get the percentage of the pie graph to 100%.
I use it to show the percentage of the values from query of the database.
The query returns integer values like:
34
27
1
2
Doing the math, we can get the follow percentage of each:
34 - 53,125%
27 - 42,1875%
1 - 1,5625%
2 - 3.125%
The pie just show 2 decimals (which is ok, because the default mask uses ##0.## '%' and i think that 2 decimals is ok.
But the result, you can see in the image below attached, doesn't sum the 100%, it always get 99,99%.
PS: We use the 2012.08.08 version
Ps2: We already has a "trick" posted into the forum somewhere else:
Code: Select all
if (series.getChart().getParent() instanceof TChart) {
TChart.class.cast(series.getChart().getParent()).setLegendResolver(new LegendResolver() {
public String getItemText(Legend legend, LegendStyle legendStyle, int index, String text) {
if (legend.getTextStyle() != LegendTextStyle.PERCENT) {
return text;
} else {
String tmps = text.substring(0, text.length() - 1).trim();
java.text.DecimalFormat df = new java.text.DecimalFormat("#.##");
tmps = tmps.replace(",", ".");
double tmpd = (Double.parseDouble(tmps) * 100);
return String.valueOf((df.format(tmpd)) + "%");
}
}
public LegendItemCoordinates getItemCoordinates(Legend legend, LegendItemCoordinates coordinates) {
return coordinates;
}
public Rectangle getBounds(Legend legend, Rectangle rectangle) {
return rectangle;
}
});
Am i doing something wrong ? Should teechart round the values to get 100% ?
Thanks