本文介绍了(MPAndroidChart-LineChart)我没有在应用程序中得到最后一个标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在使用MPAndroidChart v3.0.2.问题是最新数据('05일')没有显示...

I use MPAndroidChart v3.0.2 now.The problem is that lasst data('05일') is not showing...

这是我进行调试时的值xVals:1일,2일,5일

This is the value while I get on DebugxVals : 1일, 2일, 5일

and这是源代码和结果屏幕截图.

and It is the source and the result screenshot.

我认为'5일'进入'红色圆圈'...但是我不知道原因.

I think the '5일' enter the 'red circle'... but I don't know the reason..

  LineChart chart = (LineChart) findViewById(R.id.chart);
    if (ExRegList.length() == 0) {
        chart.clear();
        chart.setDescription(null);
        chart.setNoDataText("데이터가 존재하지 않습니다."); // There is no data.
        chart.invalidate();
    } else {
        ArrayList<Entry> entries = new ArrayList<Entry>();
        final String[] xVals = new String[ExRegList.length()];

        try {
            for (int i = 0; i < ExRegList.length(); i++) {
                JSONObject obj = ExRegList.getJSONObject(i);
                String date = obj.getString("REG_DT").split("-")[2] + "일";
                xVals[i] = date;
                int score = obj.getInt("ANSWER02");
                switch (score) {
                    case 1:
                        entries.add(new Entry(i,3f));//매우만족
                        break;
                    case 2:
                        entries.add(new Entry(i,2f));
                        break;
                    case 3:
                        entries.add(new Entry(i,1f));
                        break;
                    case 4:
                        entries.add(new Entry(i,0f));//매우불만족
                        break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        LineDataSet lineDataSet = new LineDataSet(entries, "");
        lineDataSet.setLineWidth(2);
        lineDataSet.setDrawCircleHole(true);
        lineDataSet.setDrawCircles(true);
        lineDataSet.setDrawHorizontalHighlightIndicator(false);
        lineDataSet.setDrawHighlightIndicators(false);
        lineDataSet.setDrawValues(false);

        LineData lineData = new LineData(lineDataSet);
        chart.setData(lineData);

        XAxis xAxis = chart.getXAxis();
        xAxis.setValueFormatter(new IndexAxisValueFormatter(xVals));
        XAxis bottomAxis = chart.getXAxis();
        bottomAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        bottomAxis.setDrawLabels(true);
        bottomAxis.setDrawGridLines(false);
        bottomAxis.setDrawAxisLine(true);
        bottomAxis.setLabelCount(entries.size());

        YAxis yAxis = chart.getAxisLeft();
        yAxis.setLabelCount(4, true);
        yAxis.setAxisMinimum(0.0f);
        yAxis.setAxisMaximum(3.0f);

        yAxis.setValueFormatter(new IAxisValueFormatter() {

            @Override
            public String getFormattedValue(float value, AxisBase yAxis) {
                String format = "";
                switch ((int) value) {
                    case 3:
                        format = "매우 만족";
                        break;
                    case 2:
                        format = "만족";
                        break;
                    case 1:
                        format = "불만족";
                        break;
                    case 0:
                        format = "매우 불만족";
                        break;
                    default:
                        break;
                }
                return format;
            }
        });
        yAxis.setTextColor(Color.BLACK);

        YAxis yRAxis = chart.getAxisRight();
        yRAxis.setDrawLabels(false);
        yRAxis.setDrawAxisLine(false);
        yRAxis.setDrawGridLines(false);

        chart.setFocusable(false);
        chart.setPinchZoom(false);
        chart.setDoubleTapToZoomEnabled(false);
        chart.setDrawGridBackground(false);
        chart.setDescription(null);
        chart.getLegend().setEnabled(false);
        chart.animateY(2000, Easing.EasingOption.EaseInCubic);
        chart.invalidate();

推荐答案

代替此:

bottomAxis.setLabelCount(entries.size());

使用此重载版本:

bottomAxis.setLabelCount(entries.size(), true);

第二个参数,boolean force强制具有准确的标签数.没有它,有时该方法将无法正常工作,就像您的情况一样.从源代码中,您可以看到:

Second parameter, boolean force forces to have exact number of labels. Without it, sometimes the method doesn't work, like in your case. From source code you can see:

这篇关于(MPAndroidChart-LineChart)我没有在应用程序中得到最后一个标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 02:38