加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-15 00:27:45 所属栏目:Java 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 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

以下代码由PHP站长网 52php.cn收集自互联网

现在PHP站长网小编把它分享给大家,仅供参考

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],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[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 );
          
     } 

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究

如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读