Pie - Using Percent as Legend

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
Softwell
Newbie
Newbie
Posts: 24
Joined: Tue Sep 16, 2008 12:00 am

Pie - Using Percent as Legend

Post by Softwell » Mon Feb 07, 2011 1:51 pm

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!

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Pie - Using Percent as Legend

Post by Yeray » Wed Feb 09, 2011 4:03 pm

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)) + " %";
            }
        });
    }
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Softwell
Newbie
Newbie
Posts: 24
Joined: Tue Sep 16, 2008 12:00 am

Re: Pie - Using Percent as Legend

Post by Softwell » Thu Feb 10, 2011 1:25 pm

Hi Yeary,

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

I am really thankful!

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Pie - Using Percent as Legend

Post by Yeray » Thu Feb 10, 2011 2:45 pm

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
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Softwell
Newbie
Newbie
Posts: 24
Joined: Tue Sep 16, 2008 12:00 am

Re: Pie - Using Percent as Legend

Post by Softwell » Thu Feb 10, 2011 5:42 pm

Ok.
Thanks!

Softwell
Newbie
Newbie
Posts: 24
Joined: Tue Sep 16, 2008 12:00 am

Re: Pie - Using Percent as Legend

Post by Softwell » Tue Feb 22, 2011 5:20 pm

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,

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Pie - Using Percent as Legend

Post by Yeray » Thu Feb 24, 2011 4:30 pm

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;
            }
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply