MPAndroidChart 접선 도 사용

MPAndroidChart 접선 도 사용 (건어물)
참조:
`compile 'com.github.PhilJay:MPAndroidChart:v2.0.8` 

XML:


접선 도:
//     ,arrD arrY        xy      ;arrD1 arrY1        xy   ;
LineData mLineData = getLineData(arrD, arrY, 2000,arrD1,arrY1);
//mLineData       ,        ;
showChart(mLineChart, mLineData, Color.TRANSPARENT);

다음은 방법 이다.
/**
     *       
     *       x  ,     lineDataSets  add  Entry   ,     x y   ;          ;
     * http://blog.csdn.net/qq_36576738/article/details/62215810
     *
     * @param count             
     * @param range     range      
     * @return
     */
    private LineData getLineData(int count[], int countY[], float range,int count1[], int countY1[]) {
        ArrayList xValues = new ArrayList();
        for (int i = 0; i < count.length; i++) {
            // x      ,            
            xValues.add("" + count[i]);   ///  TODO i
        }

        // y    
        ArrayList yValues = new ArrayList();
        for (int i = 0; i < countY.length; i++) {
            float value = (float) countY[i];
            yValues.add(new Entry(value, i));
        }

        //         ; y1   ����������
        //    Y1    ,X                   ,    Y ;
        ArrayList yValues1 = new ArrayList();
        for (int i = 0; i < countY1.length; i++) {
            float value = (float) countY1[i];
            yValues1.add(new Entry(value, i));
        }
        LineDataSet lineDataSet1 = new LineDataSet(yValues1,"  ");
        lineDataSet1.setLineWidth(0.5f);
        lineDataSet1.setCircleSize(0.5f);
        lineDataSet1.setCircleColorHole(Color.BLUE);
        lineDataSet1.setColor(Color.BLUE);
        lineDataSet1.setCircleColor(Color.BLUE);
        lineDataSet1.setHighLightColor(Color.TRANSPARENT);
        //--------  -------


        // create a dataset and give it a type
        // y      
        LineDataSet lineDataSet = new LineDataSet(yValues, " 1");
//        LineDataSet lineDataSet = new LineDataSet(yValues, "     " /*       */);
        // mLineDataSet.setFillAlpha(110);
        // mLineDataSet.setFillColor(Color.RED);

        // y         
        lineDataSet.setLineWidth(1f); //   
        lineDataSet.setCircleSize(1f);//        
        lineDataSet.setCircleColorHole(Color.RED);
        lineDataSet.setColor(Color.RED);//     
        lineDataSet.setCircleColor(Color.RED);//      
        lineDataSet.setHighLightColor(Color.TRANSPARENT); //        

        //������������
        ArrayList lineDataSets = new ArrayList();
        lineDataSets.add(lineDataSet); // add the datasets

        //   lineDataSets                           add  ;
        lineDataSets.add(lineDataSet1);



        // create a data object with the datasets
        //    x             ;  X       ,  Entry    XY     ,    http://blog.csdn.net/qq_36576738/article/details/62215810
        LineData lineData = new LineData(xValues, lineDataSets); 

        return lineData;
    }

표시:
 //                   ,          ;
    private void showChart(LineChart lineChart, LineData lineData, int color) {
        lineChart.setDrawBorders(false);  //           

        // no description text
        lineChart.setDescription("");//     
        //          ,     ,  listview emtpyview
        lineChart.setNoDataTextDescription("You need to provide data for the chart.");

        // enable / disable grid background
        lineChart.setDrawGridBackground(true); //         
        lineChart.setDrawBorders(true);
        lineChart.setGridBackgroundColor(Color.WHITE); //       ,               
//        lineChart.setGridBackgroundColor(Color.WHITE & 0x70FFFFFF); //       ,               

        // enable touch gestures
        lineChart.setTouchEnabled(false); //         

        // enable scaling and dragging
        lineChart.setDragEnabled(false);//       
        lineChart.setScaleEnabled(false);//       

        // if disabled, scaling can be done on x- and y-axis separately
        lineChart.setPinchZoom(false);//

//        lineChart.setBackgroundColor(Color.rgb(256, 256, 256));//     
        lineChart.setBackgroundColor(color);//     

        // add data
        lineChart.setData(lineData); //     

        // get the legend (only possible after setting data)
        Legend mLegend = lineChart.getLegend(); //        ,      y value 

        // modify the legend ...
        // mLegend.setPosition(LegendPosition.LEFT_OF_CHART);
        mLegend.setForm(Legend.LegendForm.CIRCLE);//   
        mLegend.setFormSize(6f);//   
        mLegend.setTextColor(Color.WHITE);//   
//      mLegend.setTypeface(mTf);//   
        lineChart.getAxisRight().setEnabled(false);
//        lineChart.getAxisLeft().setEnabled(false);
        lineChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
        Legend legend = lineChart.getLegend();
        legend.setEnabled(false);

        lineChart.animateX(0); //        ,x  time
//        lineChart.invalidate(); //       ;
    }

좋은 웹페이지 즐겨찾기