我正在尝试在eclipse / android Sdk中创建一个图表,我一步一步地遵循不同的教程,但到处都有我同样的问题,该图形不想显示(我没有错误,我可以编译我的程序)。目前我正在使用AChartEngine库。 有什么建议吗?
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低于
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);
}
}
布局xml在下面。
<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>
是的,此代码应显示图表 教程上有链接 - &gt; https://www.youtube.com/watch?v=-ThKImy6PPM 其他的东西,比如textview apeared,excepting graph,mayb我需要安装一些额外的功能吗?
答案 0 :(得分:1)
我对aChartEngine没有任何经验,但是你的意图我并不完全理解。我想这是因为aChartEngine代码本身会显示图表吗?
我看到的示例实际上在您的视图中呈现了图表。基本上你需要一个带有id图表的LinearLayout,它将被渲染成。参见:
和