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! To enable all features please Login or Register.

Notification

Icon
Error

Options
View
Go to last post Go to first unread
elvin  
#1 Posted : Wednesday, March 21, 2012 10:01:46 AM(UTC)
elvin
Rank: Newbie

Groups: Registered
Joined: 3/21/2012(UTC)
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 3:30:03 PM(UTC)
Baydalka Volodymyr
Rank: Member

Groups: Registered
Joined: 7/28/2009(UTC)
Posts: 447
Man

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 12:02:15 PM(UTC)
elvin
Rank: Newbie

Groups: Registered
Joined: 3/21/2012(UTC)
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 9:09:12 PM(UTC)
Baydalka Volodymyr
Rank: Member

Groups: Registered
Joined: 7/28/2009(UTC)
Posts: 447
Man

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-2017 ArtfulBits. All rights reserved.