旸君颜 2011-04-29
绘制一个XY集是一种很常见的任务,基于Android平台的绘制很简单,它让所有的GUI在XML中定义的(虽然它也可以通过代码创建)模型是相当不错的。大部分的图形处理一个样本查看,但在大多数情况下,图应该是一个部分的实施走上屏幕布局XML定义为一所以在这里展示我们ImageView
布局对象。
在Android环境中,有一整套程序的图形通常是位图实现像素,Canvas是用来绘制位图的画布,通过这一点我们可以得出元(文字,线条等)它描述了漆的颜色,款式等。
下面是效果图
图形界面我们通过Xml定义。
1.XML的GUI布局
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="#4B088A">
<TableRowandroid:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="20px">
<TextView
android:id="@+id/some"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Somelayoutitemshere"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:textColor="#ff8000"
android:textstyle="bold"
/>
</TableRow>
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#FFE6E6E6"
/>
<TableRow>
<ImageView
android:id="@+id/testy_img"
android:layout_marginLeft="20px"
android:padding="20px"
/>
</TableRow>
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#FFE6E6E6"/>
<TableRowandroid:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="20px">
<TextView
android:id="@+id/more"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Morelayoutitemshere"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:textColor="#ff8000"
android:textstyle="bold"
/>
</TableRow>
</TableLayout>这个布局文件是TableLayout布局,它定义了三行,行之间通过一条线割开
2.图表的实现
为了实现我们的图表,我们首先创建一个位图,然后关联到我们的布局文件,有了位图,我们就可以绘制图表,做缩放,色彩和数据显示 等效果。
2.1绘制位图
首先我们使布局连接到XML对象的,那么我们创建位图。我们通过quicky_XY方法来实现所有的绘制,最后显示在屏幕上。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);ImageView image = (ImageView) findViewById(R.id.testy_img);
Bitmap emptyBmap = Bitmap.createBitmap(250, 200, Config.ARGB_8888);
int width = emptyBmap.getWidth();
intheight=emptyBmap.getHeight();
Bitmapcharty=Bitmap.createBitmap(width,height,
Bitmap.Config.ARGB_8888);charty = quicky_XY(emptyBmap);
image.setImageBitmap(charty); }
2.2绘制网格
有了位图后,将它与Canvas相关联
Canvas canvas = new Canvas(bitmap)
然后将所有的元素绘制到Canvas上,我们需要定义一些用于放置标签和数据点空间的网格。
public static void draw_the_grid(Canvas this_g, Vector these_labels) {
doublerounded_max=0.0;
doublerounded_min=0.0;
doublerounded_max_temp;
ObjectcurElt;
String[]cur_elt_array;
int left_margin_d, right_margin_d;if (draw_only_this_idx == -1)
curElt=these_labels.elementAt(0);//defaultitto1stoneifnon
//set
else
curElt=these_labels.elementAt(draw_only_this_idx);//nowjustthe
// 1st eltcur_elt_array = (String[]) curElt;
rounded_max = get_ceiling_or_floor(
Double.parseDouble(cur_elt_array[2]),true);
rounded_min=get_ceiling_or_floor(
Double.parseDouble(cur_elt_array[3]), false);// ok so now we have the max value of the set just get a cool ceiling
//andwegoon
finalPaintpaint=newPaint();
paint.setTextSize(15);left_margin_d = getCurTextLengthInPixels(paint, Double
.toString(rounded_max));
//keepthepositionforlaterdrawing--leavespaceforthelegend
intp_height=170;
intp_width=220;
int[]tmp_draw_sizes={2+left_margin_d,25,
p_width-2-left_margin_d,p_height-25-5};
drawSizes = tmp_draw_sizes; // keep it for later processing// with the mzrgins worked out draw the plotting grid
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);// Android does by coords
this_g
.drawRect(drawSizes[0],drawSizes[1],drawSizes[0]
+ drawSizes[2], drawSizes[1] + drawSizes[3], paint);paint.setColor(Color.GRAY);
// finally draw the grid
paint.setStyle(Paint.Style.STROKE);
this_g
.drawRect(drawSizes[0],drawSizes[1],drawSizes[0]
+ drawSizes[2], drawSizes[1] + drawSizes[3], paint);for (int i = 1; i < 5; i++) {
this_g.drawLine(drawSizes[0],
drawSizes[1]+(i*drawSizes[3]/5),drawSizes[0]
+drawSizes[2],drawSizes[1]
+(i*drawSizes[3]/5),paint);
this_g.drawLine(drawSizes[0]+(i*drawSizes[2]/5),
drawSizes[1],drawSizes[0]+(i*drawSizes[2]/5),
drawSizes[1]+drawSizes[3],paint);
}// good for one value
print_axis_values_4_grid(this_g,cur_elt_array[1],Double
.toString(rounded_max),Double.toString(rounded_min),
cur_elt_array[0], 2, 0);} // --- end of draw_grid ---
2.3绘图和缩放
这些数据点需要一到屏幕上的坐标数据范围正确的映射遍历数据点和调用drawLine
接连两个点会完成我们的图表。数据点通过数据为载体,现在将调用plot_array_list
private static Point scale_point(int this_x , double this_y , Point drawPoint ,
<p>intscr_x,intscr_y,intscr_width,intsrc_height,</p>
<p>doublemaxX,doubleminX,doublemaxY,doubleminY)</p>
<p>{</p>
<p>inttemp_x,temp_y;</p>
<p>Pointtemp=newPoint();</p>
<p>if(maxY==minY)//skipbaddata</p>
<p>returnnull;</p>
<p>//don'ttouchitifisnothing</p>
<p>try</p>
<p>{</p>
<p>temp_x=scr_x+(int)(((double)this_x-minX)*</p>
<p>((double)scr_width/(maxX-minX)));</p>
<p>temp_y=scr_y+(int)((maxY-this_y)*</p>
<p>((double)src_height/(maxY-minY)));</p>
<p>temp.x=temp_x;</p>
<p>temp.y=temp_y;</p>
<p>drawPoint=temp;</p>
<p>}</p>
<p>catch(Exceptione)</p>
<p>{</p>
<p>return(null);</p>
<p>}</p>
<p>returntemp;</p>
<p>}//---endofscale_point--</p>
<p>publicstaticbooleanplot_array_list(Canvasthis_g,Vectorthis_array_list,</p>
<p>Vectorthese_labels,Stringthis_title,intonly_this_idx)</p>
<p>{</p>
<p>intidx;</p>
<p>intlRow;</p>
<p>intnParms;</p>
<p>inti,points_2_plot,shifted_idx;</p>
<p>intprev_x,prev_y;</p>
<p>intcur_x=0,cur_y=0;</p>
<p>//DimShowMarkerAsObject</p>
<p>Pointcur_point=newPoint();</p>
<p>cur_point.set(0,0);</p>
<p>doublecur_maxX,cur_minX,cur_maxY=20,cur_minY=0,cur_rangeY;</p>
<p>intcur_start_x,cur_points_2_plot;</p>
<p>intPOINTS_TO_CHANGE=30;</p>
<p>doublecur_OBD_val;</p>
<p>//ObjectcurElt;</p>
<p>StringcurElt;</p>
<p>String[]cur_elt_array;</p>
<p>ObjectcurElt2;</p>
<p>String[]cur_elt_array2;</p>
<p>finalPaintpaint=newPaint();</p>
<p>try//catchinthisblockforsomething</p>
<p>{</p>
<p>points_2_plot=this_array_list.size();</p>
<p>{</p>
<p>cur_start_x=0;</p>
<p>cur_points_2_plot=points_2_plot;</p>
<p>cur_maxX=cur_points_2_plot;</p>
<p>cur_minX=0;</p>
<p>}</p>
<p>//'CreatetheplotpointsforthisseriesfromtheChartPointsarray:</p>
<p>curElt=(String)this_array_list.elementAt(0);</p>
<p>//thelineshavetocomeoutgood</p>
<p>paint.setStyle(Paint.Style.STROKE);</p>
<p>//</p>
<p>//for(nParms=0;nParms<cur_elt_array.length;nParms++)</p>
<p>nParms=only_this_idx;</p>
<p>{</p>
<p>//getcuritemlabels</p>
<p>curElt2=these_labels.elementAt(nParms);</p>
<p>cur_elt_array2=(String[])curElt2;</p>
<p>cur_maxY=get_ceiling_or_floor</p>
<p>(Double.parseDouble(cur_elt_array2[2]),true);</p>
<p>cur_minY=get_ceiling_or_floor</p>
<p>(Double.parseDouble(cur_elt_array2[3]),false);</p>
<p>cur_points_2_plot=this_array_list.size();</p>
<p>cur_maxX=cur_points_2_plot;</p>
<p>curElt=(String)this_array_list.elementAt(0);</p>
<p>cur_OBD_val=Double.parseDouble(curElt);</p>
<p>cur_point=scale_point(0,cur_OBD_val,cur_point,</p>
<p>drawSizes[0],drawSizes[1],drawSizes[2],drawSizes[3],</p>
<p>cur_maxX,cur_minX,cur_maxY,</p>
<p>cur_minY);//'(CInt(curAxisValues.Mins(nParms-2)/5)+1)*5)</p>
<p>cur_x=cur_point.x;</p>
<p>cur_y=cur_point.y;</p>
<p>paint.setColor(Color.GREEN);</p>
<p>//thepointisonlycoolwhensamplesarelow</p>
<p>if(cur_points_2_plot<POINTS_TO_CHANGE)</p>
<p>this_g.drawRect(cur_x-2,cur_y-2,cur_x-2+4,</p>
<p>cur_y-2+4,paint);</p>
<p>prev_x=cur_x;</p>
<p>prev_y=cur_y;</p>
<p>//'goandplotpointforthisparm--pontafterthe1stone</p>
<p>for(lRow=cur_start_x+1;lRow<cur_start_x+</p>
<p>cur_points_2_plot-1;lRow++)</p>
<p>{</p>
<p>curElt=(String)this_array_list.elementAt(lRow);</p>
<p>cur_OBD_val=Double.parseDouble(curElt);</p>
<p>//'workoutanapproxifcurYvaluesnotavail(e.g.nothing)</p>
<p>//if(!(cur_elt_array[nParms]==null))//skipbadone</p>
<p>if(cur_OBD_val==Double.NaN)continue;//skipbadone</p>
<p>{</p>
<p>cur_point=scale_point(lRow,cur_OBD_val,cur_point,</p>
<p>drawSizes[0],drawSizes[1],</p>
<p>drawSizes[2],drawSizes[3],</p>
<p>cur_maxX,cur_minX,cur_maxY,cur_minY);</p>
<p>cur_x=cur_point.x;</p>
<p>cur_y=cur_point.y;</p>
<p>if(cur_points_2_plot<POINTS_TO_CHANGE)</p>
<p>this_g.drawRect(cur_x-2,cur_y-2,cur_x-2+4,</p>
<p>cur_y-2+4,paint);</p>
<p>this_g.drawLine(prev_x,prev_y,cur_x,cur_y,paint);</p>
<p>prev_x=cur_x;</p>
<p>prev_y=cur_y;</p>
<p>}//'ifendofthis_array(lRow,nParms-1)<>nothing</p>
<p>}//endofforlrow</p>
<p>}//endoffornParmns</p>
<p>//this_g.invalidate();</p>
<p>return(true);</p>
<p>}</p>
<p>catch(Exceptione)</p>
<p>{</p>
<p>return(false);</p>
<p>}</p>
} // --- end of plot_array_list --
Java完整代码:
package com.wjq.chart;
import java.util.Vector;
import android.app.Activity;
importandroid.graphics.Bitmap;
importandroid.graphics.Canvas;
importandroid.graphics.Color;
importandroid.graphics.Paint;
importandroid.graphics.Point;
importandroid.graphics.Rect;
importandroid.graphics.RectF;
importandroid.graphics.Typeface;
importandroid.graphics.Bitmap.Config;
importandroid.graphics.Paint.FontMetrics;
importandroid.os.Bundle;
import android.widget.ImageView;public class Main extends Activity {
staticintdraw_only_this_idx=-1;
static int[] drawSizes;@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);ImageView image = (ImageView) findViewById(R.id.testy_img);
Bitmap emptyBmap = Bitmap.createBitmap(250, 200, Config.ARGB_8888);
int width = emptyBmap.getWidth();
intheight=emptyBmap.getHeight();
Bitmapcharty=Bitmap.createBitmap(width,height,
Bitmap.Config.ARGB_8888);charty = quicky_XY(emptyBmap);
image.setImageBitmap(charty); }
public static Bitmap quicky_XY(Bitmap bitmap) {
//xodetogetbitmapontoscreen
Bitmapoutput=Bitmap.createBitmap(bitmap.getWidth(),bitmap
.getHeight(),Config.ARGB_8888);
Canvas canvas = new Canvas(output);final int color = 0xff0B0B61;
finalPaintpaint=newPaint();
finalRectrect=newRect(0,0,bitmap.getWidth(),bitmap.getHeight());
finalRectFrectF=newRectF(rect);
final float roundPx = 12;// get the little rounded cornered outside
paint.setAntiAlias(true);
canvas.drawARGB(0,0,0,0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);// ---- NOw just draw on this bitmap
// Set the labels info manually
String[]cur_elt_array=newString[4];
cur_elt_array[0]="Voltage";
cur_elt_array[1]="volts";
cur_elt_array[2]="93";//max
cur_elt_array[3] = "0"; // minVector labels = new Vector(); labels.add(cur_elt_array);
draw_the_grid(canvas, labels);
// se the data to be plotted and we should on our way
Vector data_2_plot = new Vector();
data_2_plot.add("0.2");
data_2_plot.add("1.2");
data_2_plot.add("9.6");
data_2_plot.add("83.2");
data_2_plot.add("44.2");
data_2_plot.add("20.2");
data_2_plot.add("16.2");plot_array_list(canvas, data_2_plot, labels, "the title", 0);
canvas.drawBitmap(bitmap, rect, rect, paint);
return output; }
public static void draw_the_grid(Canvas this_g, Vector these_labels) {
doublerounded_max=0.0;
doublerounded_min=0.0;
doublerounded_max_temp;
ObjectcurElt;
String[]cur_elt_array;
int left_margin_d, right_margin_d;if (draw_only_this_idx == -1)
curElt=these_labels.elementAt(0);//defaultitto1stoneifnon
//set
else
curElt=these_labels.elementAt(draw_only_this_idx);//nowjustthe
// 1st eltcur_elt_array = (String[]) curElt;
rounded_max = get_ceiling_or_floor(
Double.parseDouble(cur_elt_array[2]),true);
rounded_min=get_ceiling_or_floor(
Double.parseDouble(cur_elt_array[3]), false);// ok so now we have the max value of the set just get a cool ceiling
//andwegoon
finalPaintpaint=newPaint();
paint.setTextSize(15);left_margin_d = getCurTextLengthInPixels(paint, Double
.toString(rounded_max));
//keepthepositionforlaterdrawing--leavespaceforthelegend
intp_height=170;
intp_width=220;
int[]tmp_draw_sizes={2+left_margin_d,25,
p_width-2-left_margin_d,p_height-25-5};
drawSizes = tmp_draw_sizes; // keep it for later processing// with the mzrgins worked out draw the plotting grid
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);// Android does by coords
this_g
.drawRect(drawSizes[0],drawSizes[1],drawSizes[0]
+ drawSizes[2], drawSizes[1] + drawSizes[3], paint);paint.setColor(Color.GRAY);
// finally draw the grid
paint.setStyle(Paint.Style.STROKE);
this_g
.drawRect(drawSizes[0],drawSizes[1],drawSizes[0]
+ drawSizes[2], drawSizes[1] + drawSizes[3], paint);for (int i = 1; i < 5; i++) {
this_g.drawLine(drawSizes[0],
drawSizes[1]+(i*drawSizes[3]/5),drawSizes[0]
+drawSizes[2],drawSizes[1]
+(i*drawSizes[3]/5),paint);
this_g.drawLine(drawSizes[0]+(i*drawSizes[2]/5),
drawSizes[1],drawSizes[0]+(i*drawSizes[2]/5),
drawSizes[1]+drawSizes[3],paint);
}// good for one value
print_axis_values_4_grid(this_g,cur_elt_array[1],Double
.toString(rounded_max),Double.toString(rounded_min),
cur_elt_array[0], 2, 0);} // --- end of draw_grid ---
private static Point scale_point(int this_x, double this_y,
PointdrawPoint,intscr_x,intscr_y,intscr_width,
intsrc_height,doublemaxX,doubleminX,doublemaxY,doubleminY){
inttemp_x,temp_y;
Point temp = new Point();if (maxY == minY) // skip bad data return null;
// don't touch it if is nothing
try{
temp_x=scr_x
+(int)(((double)this_x-minX)*((double)scr_width/(maxX-minX)));
temp_y=scr_y
+ (int) ((maxY - this_y) * ((double) src_height / (maxY - minY)));temp.x = temp_x;
temp.y=temp_y;
drawPoint=temp;
} catch (Exception e) {return (null); }
return temp;
} // --- end of scale_point --
public static boolean plot_array_list(Canvas this_g,
Vectorthis_array_list,Vectorthese_labels,Stringthis_title,
intonly_this_idx){
intidx;
intlRow;
intnParms;
inti,points_2_plot,shifted_idx;
intprev_x,prev_y;
intcur_x=0,cur_y=0;
//DimShowMarkerAsObject
Pointcur_point=newPoint();
cur_point.set(0, 0);double cur_maxX, cur_minX, cur_maxY = 20, cur_minY = 0, cur_rangeY; int cur_start_x, cur_points_2_plot;
int POINTS_TO_CHANGE = 30; double cur_OBD_val;
// Object curElt;
StringcurElt;
String[]cur_elt_array;
ObjectcurElt2;
String[] cur_elt_array2;final Paint paint = new Paint();
try // catch in this block for some thing
{
points_2_plot=this_array_list.size();
{
cur_start_x=0;
cur_points_2_plot=points_2_plot;
cur_maxX=cur_points_2_plot;
cur_minX=0;
}// 'Create the plot points for this series from the ChartPoints // array:
curElt = (String) this_array_list.elementAt(0);
// the lines have to come out good
paint.setStyle(Paint.Style.STROKE);
//
//for(nParms=0;nParms<cur_elt_array.length;nParms++)
nParms=only_this_idx;
{// get cur item labels
curElt2=these_labels.elementAt(nParms);
cur_elt_array2 = (String[]) curElt2;cur_maxY = get_ceiling_or_floor(Double
.parseDouble(cur_elt_array2[2]),true);
cur_minY=get_ceiling_or_floor(Double
.parseDouble(cur_elt_array2[3]), false);cur_points_2_plot = this_array_list.size(); cur_maxX = cur_points_2_plot;
curElt = (String) this_array_list.elementAt(0); cur_OBD_val = Double.parseDouble(curElt);
cur_point = scale_point(0, cur_OBD_val, cur_point,
drawSizes[0],drawSizes[1],drawSizes[2],drawSizes[3],
cur_maxX,cur_minX,cur_maxY,cur_minY);//'(CInt(curAxisValues.Mins(nParms
//-2)/5)
// + 1) * 5)cur_x = cur_point.x; cur_y = cur_point.y;
paint.setColor(Color.GREEN);
// the point is only cool when samples are low
if(cur_points_2_plot<POINTS_TO_CHANGE)
this_g.drawRect(cur_x-2,cur_y-2,cur_x-2+4,
cur_y - 2 + 4, paint);prev_x = cur_x; prev_y = cur_y;
// 'go and plot point for this parm -- pont after the 1st one
for(lRow=cur_start_x+1;lRow<cur_start_x
+cur_points_2_plot-1;lRow++){
curElt = (String) this_array_list.elementAt(lRow);cur_OBD_val = Double.parseDouble(curElt);
// 'work out an approx if cur Y values not avail(e.g.
//nothing)
//if(!(cur_elt_array[nParms]==null))//skipbadone
if(cur_OBD_val==Double.NaN)
continue;//skipbadone
{cur_point = scale_point(lRow, cur_OBD_val, cur_point,
drawSizes[0],drawSizes[1],drawSizes[2],
drawSizes[3],cur_maxX,cur_minX,cur_maxY,
cur_minY);cur_x = cur_point.x; cur_y = cur_point.y;
if (cur_points_2_plot < POINTS_TO_CHANGE)
this_g.drawRect(cur_x-2,cur_y-2,
cur_x - 2 + 4, cur_y - 2 + 4, paint);this_g.drawLine(prev_x, prev_y, cur_x, cur_y, paint);
prev_x=cur_x;
prev_y = cur_y;} // ' if end of this_array(lRow, nParms - 1)<> nothing
} // end of for lrow
} // end of for nParmns
// this_g.invalidate();
return(true);
}catch(Exceptione){
return(false);
}} // --- end of plot_array_list --
public static void print_axis_values_4_grid(Canvas thisDrawingArea,
Stringcur_units,Stringcur_max,Stringcur_min,Stringcur_label,
intx_guide,intthis_idx){
Stringthis_str;
doubledelta=(Double.valueOf(cur_max).doubleValue()-Double.valueOf(
cur_min).doubleValue()) / 5;final Paint paint = new Paint(); paint.setColor(Color.WHITE);
paint.setTypeface(Typeface.SANS_SERIF); paint.setTextSize(8);
for (int i = 0; i < 6; i++) {
this_str=Double
.toString((Double.valueOf(cur_min).doubleValue()+delta
*i));
finalintpoint=this_str.indexOf('.');
if(point>0){
//Ifhasadecimalpoint,mayneedtoclipoffafterorforce2
//decimalplaces
this_str=this_str+"00";
this_str=this_str.substring(0,point+3);
}else{
this_str=this_str+".00";
}if (i == 5) {
thisDrawingArea.drawText(this_str,x_guide-2,drawSizes[1]
+drawSizes[3]-(i*drawSizes[3]/5),paint);
}else{
thisDrawingArea.drawText(this_str,x_guide-2,drawSizes[1]
+drawSizes[3]-(i*drawSizes[3]/5)-3,paint);
}} paint.setTextSize(10);
switch (this_idx) {
case0:
thisDrawingArea.drawText(""+cur_label+"-"+cur_units,
x_guide - 2, drawSizes[1] - 15, paint);break;
default:
thisDrawingArea.drawText(""+cur_label+"-"+cur_units,
x_guide - 2 - 30, drawSizes[1] - 15, paint);break; }
}
private static int getCurTextLengthInPixels(Paint this_paint,
Stringthis_text){
FontMetricsfp=this_paint.getFontMetrics();
Rectrect=newRect();
this_paint.getTextBounds(this_text,0,this_text.length(),rect);
returnrect.width();
}public static double get_ceiling_or_floor(double this_val, boolean is_max) {
doublethis_min_tmp;
intthis_sign;
intthis_10_factor=0;
double this_rounded;if (this_val == 0.0) {
this_rounded=0.0;
returnthis_rounded;
}this_min_tmp = Math.abs(this_val);
if (this_min_tmp >= 1.0 && this_min_tmp < 10.0)
this_10_factor=1;
elseif(this_min_tmp>=10.0&&this_min_tmp<100.0)
this_10_factor=10;
elseif(this_min_tmp>=100.0&&this_min_tmp<1000.0)
this_10_factor=100;
elseif(this_min_tmp>=1000.0&&this_min_tmp<10000.0)
this_10_factor=1000;
elseif(this_min_tmp>=10000.0&&this_min_tmp<100000.0)
this_10_factor = 10000;// 'cover when min is pos and neg
if(is_max){
if(this_val>0.0)
this_sign=1;
else
this_sign = -1;} else {
if(this_val>0.0)
this_sign=-1;
else
this_sign = 1;}
if (this_min_tmp > 1)
this_rounded=(double)(((int)(this_min_tmp/this_10_factor)+this_sign)*this_10_factor);
else{
this_rounded=(int)(this_min_tmp*100.0);
//'coversameasabovebfirnumberupto.001lessthanthait
//willskip
if(this_rounded>=1&&this_rounded<9)
this_10_factor=1;
elseif(this_rounded>=10&&this_rounded<99)
this_10_factor=10;
elseif(this_rounded>=100&&this_rounded<999)
this_10_factor = 100;this_rounded = (double) (((int) ((this_rounded) / this_10_factor) + this_sign) * this_10_factor); this_rounded = (int) (this_rounded) / 100.0;
}
if (this_val < 0) this_rounded = -this_rounded;
return this_rounded;
}}
源码下载:<a href="http://files.cnblogs.com/salam/XYChart.rar">http://files.cnblogs.com/salam/XYChart.rar</a>