免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1619 | 回复: 1
打印 上一主题 下一主题

Android 平台创建 XY 图表的完整例子 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-04-11 11:26 |只看该作者 |倒序浏览
  1. public static void  draw_the_grid(Canvas this_g,  Vector these_labels)
  2.      {         
  3.         double rounded_max = 0.0;
  4.         double rounded_min = 0.0;
  5.         double rounded_max_temp;
  6.         Object curElt;  
  7.         String[] cur_elt_array;
  8.         int left_margin_d, right_margin_d;      

  9.         if( draw_only_this_idx == -1)      
  10.            curElt = these_labels.elementAt(0);  // default  it to 1st one if non set
  11.         else
  12.            curElt = these_labels.elementAt(draw_only_this_idx);  // now just the 1st elt
  13.            
  14.         cur_elt_array = (String[])curElt;

  15.         rounded_max = get_ceiling_or_floor (Double.parseDouble(cur_elt_array[2]) , true);
  16.         rounded_min = get_ceiling_or_floor (Double.parseDouble(cur_elt_array[3]) , false);

  17.        // ok so now we have the max value of the set just get a cool ceiling and we go on
  18.         final Paint paint = new Paint();  
  19.         paint.setTextSize(15);
  20.         
  21.        left_margin_d =  getCurTextLengthInPixels(paint, Double.toString(rounded_max));
  22.        //keep the position for later drawing -- leave space for the legend
  23.        int p_height = 170;
  24.        int p_width = 220;
  25.        int[] tmp_draw_sizes = {2 + left_margin_d, 25,p_width - 2 -
  26.                 left_margin_d ,p_height - 25 -5};
  27.        drawSizes = tmp_draw_sizes; //keep it for later processing
  28.         
  29.         //with the mzrgins worked out draw the plotting grid
  30.        paint.setStyle(Paint.Style.FILL);
  31.        paint.setColor(Color.WHITE );  
  32.       
  33.        // Android does by coords
  34.        this_g.drawRect(drawSizes[0], drawSizes[1],drawSizes[0]+
  35.                 drawSizes[2], drawSizes[1]+ drawSizes[3] , paint);
  36.       
  37.        paint.setColor(Color.GRAY );      
  38.       
  39.         // finally draw the grid      
  40.       
  41.        paint.setStyle(Paint.Style.STROKE);
  42.        this_g.drawRect(drawSizes[0], drawSizes[1],drawSizes[0]+
  43.                 drawSizes[2], drawSizes[1]+ drawSizes[3] , paint);

  44.            for(int i=1; i < 5 ; i++)
  45.            {
  46.                this_g.drawLine(drawSizes[0], drawSizes[1] +
  47.                 (i * drawSizes[3] / 5), drawSizes[0] + drawSizes[2],
  48.                 drawSizes[1] + (i * drawSizes[3] / 5), paint);
  49.                this_g.drawLine(drawSizes[0]+ (i * drawSizes[2] / 5),
  50.                 drawSizes[1], drawSizes[0] + (i * drawSizes[2] / 5),
  51.                 drawSizes[1] + drawSizes[3], paint);
  52.            }

  53.           // good for one value
  54.            print_axis_values_4_grid(this_g, cur_elt_array[1] ,
  55.                 Double.toString(rounded_max) , Double.toString(rounded_min),
  56.                 cur_elt_array[0] , 2 ,0 );
  57.          
  58.      }  // --- end of draw_grid ---
复制代码

论坛徽章:
0
2 [报告]
发表于 2011-04-11 12:41 |只看该作者
学习了,谢谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP