http://developer.aiwgame.com/canvas-draw-bar-charts-and-pie-charts-in-android.html

Canvas draw bar charts and pie charts in android!
Below is the result:

Main Activity PieColumar.java:

package com.dean;import android.app.Activity;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.Path;import android.graphics.RectF;import android.os.Bundle;import android.view.Menu;import android.view.View;import com.entity.CountEntity;public class PieColumar extends Activity {CountEntity entity = new CountEntity();@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);DrawView myView = new DrawView(PieColumar.this);setContentView(myView);}public class DrawView extends View {private int value, location;// For statisticalprivate double flagIn, flagOut, flagLeft;private float clotheRate, studyRate, trafficRate, otherRate;public DrawView(Context context) {super(context);}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);// Set the background color to light graycanvas.drawColor(Color.LTGRAY);// Define a PaintPaint paint = new Paint();// Anti-aliasingpaint.setAntiAlias(true);// Draw the abscissapaint.setColor(Color.BLACK);canvas.drawLine(40, 200, 300, 200, paint);// Draw the vertical axispaint.setColor(Color.BLACK);canvas.drawLine(40, 30, 40, 200, paint);// raw a horizontal linepaint.setColor(Color.BLACK);for (int i = 170; i > 20; i -= 30) {canvas.drawLine(40, i, 280, i, paint);}// Set the title font sizepaint.setTextSize(18);paint.setColor(Color.RED);canvas.drawText(getResources().getString(R.string.graph_page_count), 65,26, paint);canvas.drawText(getResources().getString(R.string.graph_page_consume), 100,250, paint);// Set the font of each item is blackpaint.setColor(Color.BLACK);paint.setTextSize(15);// Income, expenditure, balancecanvas.drawText(getResources().getString(R.string.second_page_countIn), 60,220, paint);canvas.drawText(getResources().getString(R.string.second_page_countOut),130, 220, paint);canvas.drawText(getResources().getString(R.string.second_page_countLeft),200, 220, paint);canvas.drawText(getResources().getString(R.string.graph_page_top),5, 40, paint);canvas.drawText(getResources().getString(R.string.graph_page_right), 265,218, paint);// The vertical axis corresponds to the value offor (value = 300, location = 180; value 1500) {entity.setIncome(1500);canvas.drawText(flagIn + "", 100, 45, paint);} else if (entity.getIncome() > 0 && entity.getIncome() 1500) {entity.setOutcome(1500);canvas.drawText(flagOut + "", 160, 45, paint);} else if (entity.getOutcome() > 0 && entity.getOutcome()1500) {entity.setLeft(1500);canvas.drawText(flagLeft + "", 220, 45, paint);} else if (entity.getLeft() >= 0 && entity.getLeft()

CountEntity.java

package com.entity;public class CountEntity {double outClothe = 400;double outStudy = 200;double outTraffic = 150;double outOther = 450;double income = 1200;double outcome = 1050;double left = 150;public double getOutClothe() {return outClothe;}public void setOutClothe(double outClothe) {this.outClothe = outClothe;}public double getOutStudy() {return outStudy;}public void setOutStudy(double outStudy) {this.outStudy = outStudy;}public double getOutTraffic() {return outTraffic;}public void setOutTraffic(double outTraffic) {this.outTraffic = outTraffic;}public double getOutOther() {return outOther;}public void setOutOther(double outOther) {this.outOther = outOther;}public double getIncome() {return income;}public void setIncome(double income) {this.income = income;}public double getOutcome() {return outcome;}public void setOutcome(double outcome) {this.outcome = outcome;}public double getLeft() {return left;}public void setLeft(double left) {this.left = left;}}

strings.xml

<?xml version="1.0" encoding="utf-8"?><resources>    <string name="app_name">Android Developer - AiwGame.com</string>    <string name="graph_page_count">Income, expenditure, balance of histogram</string>    <string name="graph_page_consume">Income</string>    <string name="second_page_countIn">Expend</string>    <string name="second_page_countOut">Balance</string>    <string name="second_page_countLeft">Subtotal</string>    <string name="graph_page_top">$</string>    <string name="graph_page_right">...</string>    <string name="second_page_moneyoutOne">Clothes</string>    <string name="second_page_moneyoutTwo">Study</string>    <string name="second_page_moneyoutThree">Traffic</string>    <string name="second_page_moneyoutFour">Other</string>
 
炒股风暴

更多相关文章

  1. Android的风暴前夕

随机推荐

  1. android 检查网络状态
  2. QQ上的tabhost效果
  3. android软键盘开关
  4. Android_Google android SDK源码(1)
  5. drawable animation 循环播放
  6. android开机自启广播无效果的曲线解决方
  7. Android(安卓)Studio安装配置
  8. android 3d页面跳转
  9. Android(安卓)Studio报错:Unsupported met
  10. Android(安卓)类似HTML 中Table的网格Tab