Page 1 of 1

Pie - Using Percent as Legend

Posted: Mon Feb 07, 2011 1:51 pm
by 7669317
When I use percent as legend on pie graphics, it uses 1% as total instead of 100%.

Example:
Having the values 3, 5, 2 will show respectively 0.3%, 0.5%, 0.2%.
It should be 30%, 50%, 20%. It works when using marks on the pie, but it doesn't work when using as legend.

On VCL version, this problem doesn't exist!

Thanks!

Re: Pie - Using Percent as Legend

Posted: Wed Feb 09, 2011 4:03 pm
by yeray
Hi Lourival,

I could reproduce it so I've added it to the defect list to be fixed in future releases (TJ71015388).
In the meanwhile you could use the legend's getItemText event to format the items in the legend:

Code: Select all

    private com.steema.teechart.styles.Pie pie1;
    private void initChart() {
        pie1 = new com.steema.teechart.styles.Pie(tChart1.getChart());
        pie1.add(3);
        pie1.add(5);
        pie1.add(2);

        tChart1.getLegend().setTextStyle(com.steema.teechart.legend.LegendTextStyle.PERCENT);

        tChart1.setLegendResolver(new LegendResolver() {
            @Override
            public Rectangle getBounds(Legend legend, Rectangle rectangle) {
                return rectangle;
            }

            @Override
            public LegendItemCoordinates getItemCoordinates(Legend legend, LegendItemCoordinates coordinates) {
                return coordinates;
            }

            @Override
            public String getItemText(Legend legend, LegendStyle legendStyle, int index, String text) {
                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)) + " %";
            }
        });
    }

Re: Pie - Using Percent as Legend

Posted: Thu Feb 10, 2011 1:25 pm
by 7669317
Hi Yeary,

Thanks for the solution. It worked fine.
If it's possible, let me know when you fix that!

I am really thankful!

Re: Pie - Using Percent as Legend

Posted: Thu Feb 10, 2011 2:45 pm
by yeray
Hi Lourival,

I've referenced this thread in the [TJ71015388] ticket. However, I recommend you to be aware at the following channels for new release announcements and what's implemented on them:
- Support forum
- RSS news feed
- Twitter
- Facebook

Re: Pie - Using Percent as Legend

Posted: Thu Feb 10, 2011 5:42 pm
by 7669317
Ok.
Thanks!

Re: Pie - Using Percent as Legend

Posted: Tue Feb 22, 2011 5:20 pm
by 7669317
Hi Yeary,

I continue having the problem. At truth, now, it's worst!
The solution works only on Percent legend. If I use any other type I will face a problem.
And it is also possible to use Percent with other information. It will cause a problem!
If you have any other way to do this, please tell me!

Thanks,

Re: Pie - Using Percent as Legend

Posted: Thu Feb 24, 2011 4:30 pm
by yeray
Hi Lourival,

Of course the workaround suggested can be improved. For example you could add a condition to the getItemText event:

Code: Select all

            public String getItemText(Legend legend, LegendStyle legendStyle, int index, String text) {
                if (legend.getTextStyle() == LegendTextStyle.PERCENT)
                {
                    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)) + " %";
                }
                else
                    return text;
            }