addison_lin 发表于 2012-1-14 14:15:16

Android平台下图表绘制相关方法

很多网友可能会遇到图表绘制等问题,在Android平台下如何我们需要绘制饼图、K线图应该如何处理呢? 在Android平台下绘图的API大多数由Canvas提供类似Win32或Symbian中的DC,提供大量的绘制方法.
对于饼图即PieChart而言,比较简单,首先计算每个区域的百分比,然后通过drawArc方法绘制弧形,方法原型如下:
public void drawArc (RectF oval, float startAngle, float sweepAngle, boolean useCenter, Paint paint)
ovalThe bounds of oval used to define the shape and size of the arc
startAngleStarting angle (in degrees) where the arc begins
sweepAngleSweep angle (in degrees) measured clockwise
useCenterIf true, include the center of the oval in the arc, and close it if it is being stroked. This will draw a wedge
paintThe paint used to draw the arc
       对于K线图而言,分为两种:
       1. 静止不动型的
       炒股软件的K线图,这类直接根据数据,在x,y轴上描点即可,比较简单。
       2. 水平滚动型的
       Windows任务管理器的CPU使用了历史记录图表
       相对于这类,使用一个TimerTask不断刷新就可以了,不过要注意的是历史数据数组的溢出问题。一般用于长时间持续显示。
       有关实现的代码Android123将在一周内提供下载,目前还有细节调试中,希望对Android开发者有用。

页: [1]
查看完整版本: Android平台下图表绘制相关方法