suowolegeca 2012-02-28
在Activity中利用AChartEngine (ACE)显示图表.
基本思路: 设定数据,渲染器,并且显示到GraphicsView中 .
具体操作:
1.布局文件(itemchartactivity.xml)中增加:
<LinearLayout android:id="@+id/chart" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.72"/>
2 .AndoridManifest.xml中增加:
<activity android:name="org.achartengine.GraphicalActivity" />
3.itemChartActivity中增加:
private AbstractDemoChart mChart; private XYMultipleSeriesDataset mDataset; //数据集 private XYMultipleSeriesRenderer mRenderer; //渲染器 private GraphicalView mChartView; //显示图表 private LinearLayout layout; //用于绑定图表控件。 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.itemchartactivity); mChart = new AbstractDemoChart(this); /******* 1.构建数据. ********/ //标题 titles = new String[] { "New tickets","平均值"}; //时间轴 , 数值 getDataXY(titles.length); //通过访问数据库,给dates, values 赋值. mDataset = mChart.buildDateDataset(titles, dates, values); /*******2.构建显示时用的渲染图*/ getRenderer();
/*******3.在GraphicalView中显示.*/ layout = (LinearLayout) findViewById(R.id.chart); //绑定控件 mChartView = ChartFactory.getTimeChartView(this, mDataset, mRenderer, "MM/dd/yyyy"); layout.addView(mChartView, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));