zoukankan      html  css  js  c++  java
  • Adroid平台图表案例源码

    Android平台创建xy图表的案例分析源码介绍,来看一下详细的源码

    绘制网格线的方法

    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 ---


     

  • 相关阅读:
    项目有大小,生存各有道
    学习Spark——那些让你精疲力尽的坑
    学习Spark——环境搭建(Mac版)
    小程序新能力-个人开发者尝鲜微信小程序
    如何写出好代码
    华为手机nova2s使用第三方字体库
    std::string与std::wstring互相转换
    Steam安装Google Earth VR
    osgearth2.8关于RectangleNodeEditor编辑点不可见的问题
    Qt生成ui文件对应的.h和.cpp文件
  • 原文地址:https://www.cnblogs.com/vus520/p/2561915.html
Copyright © 2011-2022 走看看