在Activity中利用AChartEngine (ACE)显示图表.
在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));
相关推荐
jingwenjingwen 2013-03-14
GuangkuoDing 2011-06-13
nickey 2013-06-05
流媒体开发先行者 2014-08-05
jingwenjingwen 2014-06-25
feifei000 2014-02-12
Thik叮当 2014-01-17
suowolegeca 2014-01-16
jykenan 2014-01-16
zhangjikuan 2014-01-15
suowolegeca 2013-07-14
suowolegeca 2013-03-31
feifei000 2012-07-13
人走丿茶凉 2012-02-14