whitespace COMPANY whitespace SERVICES whitespace PRODUCTS whitespace PURCHASE whitespace SUPPORT whitespace CONTACTS whitespace Home whitespace Contact Us whitespace Site Map whitespace
whitespace
SUPPORT
whitespace
FORUM
whitespace
FAQS
whitespace
SUBSCRIPTION
whitespace
REQUEST ON-LINE
whitespace
whitespace

Technical Support Forum

Welcome Guest Search | Active Topics | Log In | Register

percent on piechart? Options · View
elvin
#1 Posted : Wednesday, March 21, 2012 8:01:46 AM
Rank: Newbie

Groups: Registered

Joined: 3/21/2012
Posts: 3
Location: China
Is there a way to set labels on with values and percent on each slice? and how can i add click event on every slice?
Baydalka Volodymyr
#2 Posted : Wednesday, March 21, 2012 1:30:03 PM
Rank: Developers Team


Groups: Registered, Administrators

Joined: 7/28/2009
Posts: 447
Hi,

An easy way to show the percentage use point label format. Example:
chartSeries.setLabelFormat("%PERCENT0$#.##% %%");

Regarding click events

Code:

chartView.setOnTouchListener(new View.OnTouchListener()
{
    
    @Override
    public boolean onTouch(View v, MotionEvent event)
    {
        ChartView cv = (ChartView)v;
        
        if(event.getAction() == MotionEvent.ACTION_DOWN)
        {
            for (Object obj : cv.getChart().hitTest((int)event.getX(), (int)event.getY()))
            {
                if(obj instanceof ChartPoint)
                {
                    //YOUR CODE
                }
            }
        }
        
        return false;
    }
});


Best regards,
Volodymyr Baydalka
Andriod development and support team
elvin
#3 Posted : Thursday, March 22, 2012 10:02:15 AM
Rank: Newbie

Groups: Registered

Joined: 3/21/2012
Posts: 3
Location: China
That worked beautifully! Thank you! And here is another question. I want the legend label shows the string according from string array.and the label on pie chart is value and percent.The label and the value separate by newline(\n)? It there a way to solve it? Thanks. Sorry for my poor English.
the following is the code:
Code:

chartView = (ChartView) pieChart.findViewById(R.id.chartView);
            series = new ChartSeries(ChartTypes.Pie);
            series.setLabelFormat("{XVALUE0} {YVALUE0,#.##}%");
            double[] data = {289.04, 60.96};
            double[] percent = {83,17};
            String[] labels = {"Africa","Asia"};
            ChartLegend legend = new ChartLegend();
            ChartLegendItemsBinder itemsBinder = null;
            legend.setDock(Dock.Top);
            legend.setAlignment(Alignment.Center);
            for (int i = 0; i < data.length; i++) {
                point = series.getPoints().addXY(data[i], percent[i]);
                point.setLabel(labels[i]);
                itemsBinder = new ChartLegendItemsBinder(labels[i]);
            }
            legend.setItemsProvider(new LegendItemsProvider.PointItemsProvider(itemsBinder));
            legend.setLayoutMode(LayoutMode.Vertical);
            series.setShowLabel(true);
            chartView.getLegends().add(legend);
            chartView.getSeries().add(series);
Baydalka Volodymyr
#4 Posted : Friday, March 23, 2012 7:09:12 PM
Rank: Developers Team


Groups: Registered, Administrators

Joined: 7/28/2009
Posts: 447
Hi,

Your code need some modification.

Code:
series.setLabelFormat("{XVALUE0} {YVALUE0,#.##}%");
double[] data = {289.04, 60.96};
double[] percent = {83,17};
String[] labels = {"Africa","Asia"};
for (int i = 0; i < data.length; i++) {
    ChartPoint point = series.getPoints().addXY(data[i], percent[i]);
    point.setLabel(labels[i]);
}

ChartLegend legend = new ChartLegend();
ChartLegendItemsBinder itemsBinder = new ChartLegendItemsBinder("{LABEL} {XVALUE0} {YVALUE0,#.##}%");
legend.setDock(Dock.Top);
legend.setItemsProvider(new LegendItemsProvider.PointItemsProvider(itemsBinder));
legend.setLayoutMode(LayoutMode.Vertical);
series.setShowLabel(true);
chartView.getLegends().add(legend);


Best regards,
Volodymyr Baydalka
Andriod development and support team
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Company | Services | Practices | Technologies | Career | Contacts | Privacy
© 2005-2016 ArtfulBits. All rights reserved.