XY chart in Android

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
Simone
Newbie
Newbie
Posts: 1
Joined: Tue Dec 20, 2011 12:00 am

XY chart in Android

Post by Simone » Thu Dec 22, 2011 9:22 pm

Hi,

I want to draw an XY chart.

I used the following code but I haven't get the awaited result.

Code: Select all

public class XY_ChartActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        LinearLayout layout = (LinearLayout) findViewById(R.id.chartPanel);
        TChart chart = new TChart(this);
        chart.getGraphics3D().getAspect().setView3D(false);
        Line series = new Line();
        series.add(12.0,1.1);
        series.add(14.0,1.3);
        series.add(16.0,1.4);
        series.add(20.0,1.6);
        series.add(24.0,2.0);
        series.add(26.0,2.3);
        series.add(25.0,2.4);
        series.add(23.0,2.6);
        series.add(19.0,2.1);
        chart.addSeries(series);
        layout.addView(chart);
    }
}
Below there is the image of the chart that I got:
Image

Below there is instead the image of the chart that I want:
Image

Did I use a wrong series? Can you help me?

Thanks you!

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: XY chart in Android

Post by Narcís » Fri Dec 23, 2011 8:04 am

Hi Simone,

No, you didn't use the wrong series but by default their X values are sorted ascendingly. To get the plot you want you should set XValues.Order to none before populating series:

Code: Select all

        Line series = new Line(tChart1.getChart());

        series.getXValues().setOrder(ValueListOrder.NONE);

        series.add(12.0,1.1);
        series.add(14.0,1.3);
        series.add(16.0,1.4);
        series.add(20.0,1.6);
        series.add(24.0,2.0);
        series.add(26.0,2.3);
        series.add(25.0,2.4);
        series.add(23.0,2.6);
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply