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

Display text as X-axis value/label Options · View
hennamullaji
#1 Posted : Tuesday, February 23, 2010 2:40:55 PM
Rank: Member

Groups: Registered

Joined: 2/9/2010
Posts: 16
Location: Earth
Hello,

I am creating a line chart to display the following data.

Date -> Score

Jan 1 -> 10
Jan 2 -> 12
Jan 3 -> 9
Jan 4 -> 10

The
Code:
series.getPoints().addXY()
method takes only float values for X as well as Y axis, but I need to add "Jan 1" a text value to the X-axis.

I would appreciate if someone can help me with this.

Regards,
M
pturchenko
#2 Posted : Tuesday, February 23, 2010 3:49:13 PM
Rank: Guest

Groups:

Joined: 7/9/2009
Posts: 3,383
Hi. Please use series.getPoints().addDate() method instead of the one you use. Also, set chartArea.getDefaultXAxis().setValueType(ValueType.Date).
hennamullaji
#3 Posted : Wednesday, February 24, 2010 9:46:27 AM
Rank: Member

Groups: Registered

Joined: 2/9/2010
Posts: 16
Location: Earth
I need to display "Jan 1" or "Jan 2" as a text on the X-axis NOT date "1/1/2010". I want to display a line or bar chart for something similar to the table below:
Name -> Score

Adam -> 20
John -> 15
Greg -> 18
Alice -> 16

It would be helpful if someone can provide me code snippet(s) to solve my problem

Thanks,
M
Baydalka Volodymyr
#4 Posted : Wednesday, February 24, 2010 1:27:22 PM
Rank: Developers Team


Groups: Registered, Administrators

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

Now you just need to change the label format

Code:
double[] values = { 20, 15, 18, 16};
Calendar calendar = Calendar.getInstance();

calendar.set(2010, 0, 1, 12, 0, 0);

for (int i = 0; i < values.length; i++)
{
    series.getPoints().addDate(calendar.getTime(), values[i]);
    calendar.add(Calendar.DAY_OF_MONTH, 1);
}

area.getDefaultXAxis().setValueType(ValueType.Date);
area.getDefaultXAxis().setLabelsMode(LabelsMode.SeriesLabels);
area.getDefaultXAxis().setFormat("MMM d");


But if need to set custom text values, use next code

Code:
double[] values = { 20, 15, 18, 16};
String[] labels = { "Adam", "John", "Greg", "Alice" };

for (int i = 0; i < values.length; i++)
{
    ChartPoint chartPoint = new ChartPoint(i, values[i]);
    
    chartPoint.setAxisLabel(labels[i]);
    
    series.getPoints().add(chartPoint);
}

area.getDefaultXAxis().setLabelsMode(LabelsMode.SeriesLabels);


Best regards,
Volodymyr Baydalka
Andriod development and support team
hennamullaji
#5 Posted : Thursday, February 25, 2010 5:39:52 AM
Rank: Member

Groups: Registered

Joined: 2/9/2010
Posts: 16
Location: Earth
Hey thanks Volodymyr Baydalka.I tried something similar yesterday in my code and it worked.I too made two arrays, the concept I used was frrom some of your previous posts and code.
Thanks once again.
hennamullaji
#6 Posted : Thursday, February 25, 2010 1:15:39 PM
Rank: Member

Groups: Registered

Joined: 2/9/2010
Posts: 16
Location: Earth
I am having some display issues with the chart.
Since I have other views to be shown on the same screen, whenever I give WRAP_CONTENT to both width and height of the chartview I get the chart displayed above the other views.

I tried giving a particular value for width and height instead of WRAP_CONTENT , but, then only half of the chart is displayed.

I did some horizontal and vertical scaling to show the entire chart below the other views, but I am unable to display it entirely.

Thanks,
M
hennamullaji attached the following image(s):
Screenshot1.JPG (60kb) downloaded 54 time(s).
Screenshot2.JPG (54kb) downloaded 54 time(s).
Baydalka Volodymyr
#7 Posted : Thursday, February 25, 2010 5:10:24 PM
Rank: Developers Team


Groups: Registered, Administrators

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

Try to use next attributes for ChartView in your XML-layout file.

Code:
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"


There is complete sample that demonstrates how to show chart with other views through java code or XML-layout file.
File Attachment(s):
aiChartLayout.zip (13kb) downloaded 11 time(s).
Volodymyr Baydalka
Andriod development and support team
hennamullaji
#8 Posted : Friday, February 26, 2010 9:35:29 AM
Rank: Member

Groups: Registered

Joined: 2/9/2010
Posts: 16
Location: Earth
Hey thanks a lot...Baydalka. It works with the chart properly displayed below the other views.
Thanks a lot once again.
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.