0
我想在eclipse/android Sdk中創建一個圖表,我一直在按照不同的教程一步一步地做,但是到處都有同樣的問題,圖形不想顯示出來沒有錯誤,我可以編譯我的程序)。目前我正在使用AChartEngine庫。 有什麼建議嗎?在Android中使用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>
是,此代碼應顯示圖形 有關於教程鏈接 - >https://www.youtube.com/watch?v=-ThKImy6PPM 別的東西,比如TextView的apeared,除了圖形,MAYB我需要安裝一些額外的功能?
那你試試?你能顯示你的layout.xml和其他活動文件嗎?所以用戶可以正確處理你的問題。 – hakiko 2013-03-06 16:10:36
'lineGraphHandler'在什麼階段被調用,爲什麼你要傳遞'View'? – Ricky 2013-03-06 16:41:52