2
我想使用AFreeChart在我的活動中顯示圖表,我已經檢查瞭如此多的文檔拋出互聯網,但我沒有找到任何完整的示例,我的意思是如何構建圖表並顯示它之後在我的佈局中,我需要顯示它嗚嗚嗚GUI(像我的GUI中的圖像一樣),我正在使用eclipse(android 4.2)。afreechart Android eclipse esample
有誰知道如何在android中使用AfreeChart?謝謝
我想使用AFreeChart在我的活動中顯示圖表,我已經檢查瞭如此多的文檔拋出互聯網,但我沒有找到任何完整的示例,我的意思是如何構建圖表並顯示它之後在我的佈局中,我需要顯示它嗚嗚嗚GUI(像我的GUI中的圖像一樣),我正在使用eclipse(android 4.2)。afreechart Android eclipse esample
有誰知道如何在android中使用AfreeChart?謝謝
好的,因爲這是一個較舊的帖子,我不確定你是否能夠找到這個問題的答案。這是在您的活動中顯示自由圖表需要做的事情。
創建一個自定義視圖擴展ImageView的,像blelow
public class ChartView extends ImageView
{
private Bitmap bitmap;
private RectShape rectArea;
private Canvas canvas;
private AFreeChart chart;
public ChartView(Context context, AttributeSet attributeSet)
{
super(context, attributeSet);
}
public ChartView(Context context)
{
super(context);
intChart();
}
private void intChart()
{
//Setting different width and height based on the orientation.
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
{
bitmap = Bitmap.createBitmap(400, 200, Bitmap.Config.ARGB_8888);
rectArea = new RectShape(0.0, 0.0, 400, 200);
}
else
{
bitmap = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888);
rectArea = new RectShape(0.0, 0.0, 200, 200);
}
}
public void drawChart(AFreeChart chart)
{
canvas = new Canvas(bitmap);
this.chart = chart;
this.chart.draw(canvas, rectArea);
setImageBitmap(bitmap);
}
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
}
}
創建活動,如下圖所示,你都準備好去。我假設你已經創建了你的AFreeChart對象傳遞給視圖。
public class ChartActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.chart);
ViewGroup viewGroup = (ViewGroup)getWindow().getDecorView().findViewById(android.R.id.content);
ChartView chartView = new ChartView(this);
chartView.drawChart(ChartFactory.createChart()/*Returns AFreechart object*/);
viewGroup.addView(chartView);
}
}
chart.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
希望這有助於
使用合適的標籤(Android)和重寫你的問題,因爲它會被關閉,如果它仍然像它現在。 – vorrtex 2013-03-16 11:18:47