当前位置: 代码迷 >> Android >> android engine解决办法
  详细解决方案

android engine解决办法

热度:12   发布时间:2016-05-01 17:36:35.0
android engine
package mars.Activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import org.achartengine.ChartFactory;
import org.achartengine.chart.BarChart.Type;
import org.achartengine.model.CategorySeries;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.renderer.SimpleSeriesRenderer;
import org.achartengine.renderer.XYMultipleSeriesRenderer;


import android.app.ListActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class ActivityActivity extends ListActivity {
  /** Called when the activity is first created. */
private static final int SERIES_NR=2;
private ArrayList<Map<String,String>> maps=new ArrayList<Map<String,String>>();
  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  // setContentView(R.layout.main);
  //加入ListItem “调度查询”
  HashMap<String,String> map=new HashMap<String,String>();
  map.put("name", "柱状图");
  map.put("desc", "显示柱状图");
  maps.add(map);
  //构建listView适配器
  SimpleAdapter adapter=new SimpleAdapter(this, maps,android.R.layout.simple_expandable_list_item_2, 
  new String[]{"name","desc"}, new int[]{android.R.id.text1,android.R.id.text2});
  this.setListAdapter(adapter);
  }
  //listItem监听器
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
XYMultipleSeriesRenderer renderer = getBarDemoRenderer(); 

Intent intent = ChartFactory.getBarChartIntent ( this , getBarDemoDataset(), renderer, Type.DEFAULT);
 
  startActivity(intent); 

}
private XYMultipleSeriesDataset getBarDemoDataset() {
XYMultipleSeriesDataset dataset=new XYMultipleSeriesDataset();
final int nr=10;
Random r=new Random();
for(int i=0;i<SERIES_NR;i++)
{
CategorySeries series=new CategorySeries("Demo Series"+(i+1));
for(int k=0;k<nr;i++)
{
series.add(100+r.nextInt()%100);
}
dataset.addSeries(series.toXYSeries());
}
return dataset;


public XYMultipleSeriesRenderer getBarDemoRenderer() {

XYMultipleSeriesRenderer renderer=new XYMultipleSeriesRenderer();
SimpleSeriesRenderer r=new SimpleSeriesRenderer();
r.setColor(Color.BLUE);
renderer.addSeriesRenderer(r);
r=new SimpleSeriesRenderer();
r.setColor(Color.GREEN);
renderer.addSeriesRenderer(r);
setChartSettings(renderer);
return renderer; 

 
}
private void setChartSettings(XYMultipleSeriesRenderer renderer) {
// TODO Auto-generated method stub
renderer.setChartTitle("Chart Demo");
renderer.setXTitle("x value");
renderer.setXTitle("y value");
renderer.setXAxisMin(0.5);
renderer.setXAxisMax(10.5);
renderer.setYAxisMin(0);
renderer.setYAxisMax(210);



这是activity文件,下面的是manifest.xml文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="mars.Activity"
  相关解决方案