我可以在MpAndroid折线图中已经存在的圆孔上创建圆孔吗?

时间:2018-01-21 06:06:25

标签: android mpandroidchart linechart

我可以使用MPAndroid图表库动态创建线图,并且能够创建LineChart的阴影,但我不能创建另一个圆孔,而不是之前存在于MPAndroid折线图中的那个?

代码

  void plotGraph(List<StatementListApi> statementListApis) {

        HashMap<Integer, String> stringDoubleHashMap = new HashMap<>();
        stringDoubleHashMap.put(0, "0");
        stringDoubleHashMap.put(1, "0");
        stringDoubleHashMap.put(2, "0");
        stringDoubleHashMap.put(3, "0");
        stringDoubleHashMap.put(4, "0");
        stringDoubleHashMap.put(5, "0");
        stringDoubleHashMap.put(6, "0");

        for (int i = 0; i < statementListApis.size(); i++) {

            Date date = new Date(Long.parseLong(statementListApis.get(i).getRecordedDate()));
            System.out.println("date is" + date);

            if (stringDoubleHashMap.containsKey(date.getDay())) {

                Long aLong = statementListApis.get(i).getAmount() + Long.parseLong(stringDoubleHashMap.get(date.getDay()));

                stringDoubleHashMap.put(date.getDay(), aLong + "");

            } else {

                stringDoubleHashMap.put(date.getDay(), statementListApis.get(i).getAmount() + "");
            }
            System.out.println("size of hashmap" + stringDoubleHashMap.size());
        }


        List<String> xVals = new ArrayList<String>(stringDoubleHashMap.values());

        List<ILineDataSet> testDataSet1 = new ArrayList<>();

        List<Entry> entries = new ArrayList<>();

        ArrayList<String> Labels = new ArrayList<>();
        Labels.add("SUN");
        Labels.add("MON");
        Labels.add("TUE");
        Labels.add("WED");
        Labels.add("THU");
        Labels.add("FRI");
        Labels.add("SAT");

        for (int i = 0; i < xVals.size(); i++) {

            entries.add(new Entry(i, Float.parseFloat(xVals.get(i))));
            LineDataSet dataSet = new LineDataSet(entries, Labels.get(i));
            testDataSet1.add(dataSet);
            dataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
            dataSet.setColor(Color.RED);
            dataSet.setCircleColor(Color.WHITE);
            dataSet.setValueTextColor(Color.WHITE);

        }


        activityStatementBinding.lineChart.getXAxis().setTextColor(Color.WHITE);

        // for shadow
        activityStatementBinding.lineChart.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        activityStatementBinding.lineChart.getRenderer().getPaintRender().setShadowLayer(1, 10, 10, Color.BLACK);

        IMarker marker = new CustomMarkerView(this, R.layout.activity_marker_view);
        activityStatementBinding.lineChart.setMarker(marker);

        MarkerImage markerImage = new MarkerImage(this, R.drawable.ic_back_24);
        activityStatementBinding.lineChart.setMarker(markerImage);

        //Animation
        activityStatementBinding.lineChart.animateY(1700);

        YAxis leftAxis = activityStatementBinding.lineChart.getAxisRight();
        leftAxis.setEnabled(false);

        //used to remove the horizontal x-axis lines in graph
        YAxis rightAxis = activityStatementBinding.lineChart.getAxisLeft();
        rightAxis.setEnabled(false);

        activityStatementBinding.lineChart.getDescription().setEnabled(false);

        activityStatementBinding.lineChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);

        // used for removing the labels with color
        Legend legend = activityStatementBinding.lineChart.getLegend();
        legend.setEnabled(false);

//        activityStatementBinding.lineChart.moveViewTo(10, 0, RIGHT);

//        activityStatementBinding.lineChart.setScrollContainer(true);
//        activityStatementBinding.lineChart.setHorizontalScrollBarEnabled(true);


        activityStatementBinding.lineChart.getXAxis().setValueFormatter(new IndexAxisValueFormatter(Labels));
        activityStatementBinding.lineChart.setData(new LineData(testDataSet1));
        activityStatementBinding.lineChart.notifyDataSetChanged();
        activityStatementBinding.lineChart.invalidate();


    }

获取图片 enter image description here

必填图片 enter image description here

  

如何在已经存在的圆孔上实现圆孔?

2 个答案:

答案 0 :(得分:1)

您需要执行以下操作:

    lineDataSet.setCircleRadius(6);
    float circleHoleRadius = circleRadius/2;
    lineDataSet.setCircleHoleRadius(circleHoleRadius);
    //lineDataSet.setCircleColor(Color.RED);
    // Below line is to add transperancy to your color
    lineDataSet.setCircleColor(Color.argb(12,284,55,32));
    lineDataSet.setCircleColorHole(Color.WHITE);

您可以根据需要更改颜色和尺寸。快乐的编码:)

答案 1 :(得分:0)

    dataSet.setDrawCircles(true);
    dataSet.setDrawCircleHole(true);
    dataSet.setColor(yourColor);
    dataSet.setCircleRadius(20);  // required radius
    dataSet.setCircleColor(circleColor);
    dataSet.setCircleHoleColor(circleColor);
    dataSet.setCircleHoleRadius(10);  // hole radius
    dataSet.setDrawValues(true);

您必须启用dataSet.setDrawCircleHole(true);来绘制孔