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();
@Override
protected 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 statistical
private double flagIn, flagOut, flagLeft;
private float clotheRate, studyRate, trafficRate, otherRate;
public DrawView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// Set the background color to light gray
canvas.drawColor(Color.LTGRAY);
// Define a Paint
Paint paint = new Paint();
// Anti-aliasing
paint.setAntiAlias(true);
// Draw the abscissa
paint.setColor(Color.BLACK);
canvas.drawLine(40, 200, 300, 200, paint);
// Draw the vertical axis
paint.setColor(Color.BLACK);
canvas.drawLine(40, 30, 40, 200, paint);
// raw a horizontal line
paint.setColor(Color.BLACK);
for (int i = 170; i > 20; i -= 30) {
canvas.drawLine(40, i, 280, i, paint);
}
// Set the title font size
paint.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 black
paint.setColor(Color.BLACK);
paint.setTextSize(15);
// Income, expenditure, balance
canvas.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 of
for (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>
炒股风暴
分享到:
相关推荐
如何在android内部写一个柱状图,然后展示出来。这里给出一个demo!
微信小程序Canvas绘制曲线图、饼图、柱状图、雷达图/蛛网图源码
Android利用canvas画各种图形
Android利用canvas画各种图形(点、直线、弧、圆、椭圆、文字、矩形、多边形、曲线、圆角矩形)
android 画曲线图 画三角形(多边形),可以画成股票K线图,儿童成长曲线等,使用android的canvas
Android 自定义画布canvas 实现绘制和清空画布功能,内含源码、apk
android 使用canvas把矩形图片变成圆角矩形显示 参考网址:http://blog.csdn.net/rhljiayou/article/details/7212620
利用Android 的View和SurfaceView等实现了折线图、柱状图、和饼图的动态的实现效果。给人一种霸气的感觉啦。
canvas扇形图饼图
Android画柱状图的demo,可运行,可以学习Canvas和Paint的相关知识
用Canvas画的折线图,将坐标点输入之后就能自动绘制。
canvas柱状图横向
jquery html5 图表用canvas绘制一个动画圆形饼图
Android Canvas画布使用Demo源码.rar
*柱状图 column *区域图 area 高清显示 设置canvas的尺寸为2倍大小,然后缩小到50%,建议都进行这样的设置,图表本身绘制时是按照高清显示配置的,不然整体效果会偏大 /* 例如设计图尺寸为320 x 300 */ .canvas...
用Canvas画的简单表格,画了一条曲线,需要的同学可以自己扩展
canvasTable是用canvas画布画柱状图、饼图、折线图1、折线图2、贝塞尔曲线
安卓Android源码——(Canvas画布).zip
Android下使用Canvas画图,详细参见博客:http://www.cnblogs.com/plokmju/p/android_Canvas.html