江湖开发者 | Java粉
网站地图
首页> Android> Android 折线图 趋势图
2015
12-16

Android 折线图 趋势图

Android 折线图 趋势图


百度网盘:

链接: http://pan.baidu.com/s/1i41heTn 密码: xxy8


引用achartengine.jar


Y7]2S$_}55KIRV8DXC(OT0Z.png

调用代码:

public class MainActivity extends Activity {
	
	TrendChart  mTrendChart;
	GraphicalView mChartView;
	
	LinearLayout mChart;
	
	int max=3500;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_main);
		
		mTrendChart= new TrendChart();
		mChart=(LinearLayout)findViewById(R.id.ll_chart_1);
		
		ArrayList<double[]> xValues=new ArrayList<double[]>();
		ArrayList<double[]> yValues=new ArrayList<double[]>();
		
		double[] x1={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,
			18,19,20,21,22,23,24,25,26,27,28,29,30,31};
		double[] y1={100,200,300,400,500,600,700,800,900,1000,1100,
			1200,1300,1400,1500,1600,1700,1800,1900,2000,2100,2200,
			2300,2400,2500,2600,2700,2800,2900,3000,3100};
		
		
		double[] x2={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
			20,21,22,23,24,25,26,27,28,29,30,31};
		double[] y2={100,200,300,400,500,600,700,800,900,1000,1100,
			1200,1300,1400,1500,1600,1700,1800,1900,2000,2100,2200,
			2300,2400,2500,2600,2700,2800,2900,3000,3100};
		
		for(int i=0,j=y2.length;i<j/2;i++){
			double temp = y2[i];
			y2[i]=y2[j-1-i];
			y2[j-1-i]=temp;
		}
		
		xValues.add(x1);
		yValues.add(y1);
		xValues.add(x2);
		yValues.add(y2);
		mChartView= mTrendChart.getView(MainActivity.this, 
			getXYMultipleSeriesDataset(xValues, yValues),max);
		
		mChart.addView(mChartView);
		
	}

	
	public XYMultipleSeriesDataset getXYMultipleSeriesDataset(
		ArrayList<double[]> xValues,
		ArrayList<double[]> yValues) {

		String[] titles= new String[] {"投诉总量    ","环比总量"};
		XYMultipleSeriesDataset xyMultipleSeriesDataset =
			mTrendChart.buildDataset(titles, xValues, yValues);
		return xyMultipleSeriesDataset;
	}

}


Java江湖     
全部评论:

表情验证码,看不清楚,换一张

随机文章

云标签

公众号

微信

分享:分享我们的知识;专注:专注个人技术的提升;