返回顶部

收藏

Android 平台创建 XY 图表的完整例子

更多

android_xy.gif

imgs/asCode/01234546_UwPA.gif

绘制网格线的方法

public static void  draw_the_grid(Canvas this_g,  Vector these_labels)
     {         
        double rounded_max = 0.0;
        double rounded_min = 0.0;
        double rounded_max_temp;
        Object curElt;  
        String[] cur_elt_array;
        int left_margin_d, right_margin_d;      

        if( draw_only_this_idx == -1)      
           curElt = these_labels.elementAt(0);  // default  it to 1st one if non set 
        else
           curElt = these_labels.elementAt(draw_only_this_idx);  // now just the 1st elt

        cur_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 and we go on
        final Paint paint = new Paint();  
        paint.setTextSize(15);

       left_margin_d =  getCurTextLengthInPixels(paint, Double.toString(rounded_max));
       //keep the position for later drawing -- leave space for the legend
       int p_height = 170;
       int p_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 --- 

标签:图表,Android,SDK

收藏

0人收藏

支持

0

反对

0

相关聚客文章
  1. fatkun 发表 2013-03-10 05:29:01 安装android sdk提示找不到JDK解决方法
  2. K-Res 发表 2016-01-31 07:36:02 iOS Android平台下的wchar_t默认size问题
  3. 草依山 发表 2013-12-13 08:00:00 手工下载Android的SDK
  4. Trinea 发表 2016-11-23 01:51:40 Android 7.1 源代码开放
  5. Trinea 发表 2016-12-08 04:44:54 Android 中文站及Google 正式发布 Google Developers 中文网站
  6. 博主 发表 2014-08-29 15:25:00 android-sdk
  7. 博主 发表 2017-12-27 08:28:37 Android埋点技术分析
  8. 南 靖男 发表 2018-07-06 02:35:08 flutter 免 Android Studio 安装 Android SDK
  9. 7 发表 2014-10-18 08:54:12 Android L SDK更新
  10. 博主 发表 2014-12-22 01:07:22 让AndroidSDK飞
  11. 博主 发表 2013-05-04 23:34:00 安装 Android SDK (setup Android SDK in eclipse)
  12. 博主 发表 2012-11-17 15:30:00 【用objective-c写android游戏】初次使用Stella SDK

发表评论