Reputation: 51
I am trying to create a chart in eclipse/android Sdk, i was following different tutorials step by step, but everywhere i have the same problem, that graph doesn't want to show up(i have no errors and i can compile my program). Currently i am using AChartEngine library. Any suggestions?
package com.example.linegraph;
import org.achartengine.ChartFactory;
import org.achartengine.model.TimeSeries;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;
import android.content.Context;
import android.content.Intent;
public class LineGraph {
public Intent getIntent (Context context)
{
int[] x={1,2,3,4,5,6,7,8,9,10};
int[]y={11,22,33,44,55,66,77,88,99,11};
TimeSeries series =new TimeSeries("Line1");
for (int i=0;i<x.length;i++)
{
series.add(x[i],y[i]);
}
XYMultipleSeriesDataset dataset =new XYMultipleSeriesDataset();
dataset.addSeries(series);
XYMultipleSeriesRenderer mRenderer=new XYMultipleSeriesRenderer();
XYSeriesRenderer renderer =new XYSeriesRenderer();
mRenderer.addSeriesRenderer(renderer);
Intent intent=ChartFactory.getLineChartIntent(context, dataset, mRenderer,"Line Graph Title");
return intent;
}
}
MainActivity is below
package com.example.linegraph;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void lineGraphHandler (View view){
LineGraph line= new LineGraph();
Intent lineIntent=line.getIntent(this);
startActivity(lineIntent);
}
}
The layout xml is below.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
</RelativeLayout>
yes, this code should display the graph there's link on tutorial ->https://www.youtube.com/watch?v=-ThKImy6PPM other things ,like textview apeared, excepting graph, mayb i need to install some additional features?
Upvotes: 0
Views: 2120
Reputation: 5535
I do not have any experience with aChartEngine, but your intent stuff I don't completely understand. I guess that is so that the aChartEngine code itself will display the chart?
The examples I saw actually rendered the chart in your views. Basically you need a LinearLayout with id chart that it will render into. See:
and
Upvotes: 1