android - (MPAndroidChart-LineChart) 我没有在我的应用程序中得到最后一个标签

标签 android mpandroidchart linechart

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

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

and 是来源和结果截图。

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

  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();

enter image description here

最佳答案

取而代之的是:

bottomAxis.setLabelCount(entries.size());

使用这个重载版本:

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

第二个参数,boolean force 强制具有确切的标签数。没有它,有时该方法不起作用,就像您的情况一样。从源码可以看出:

sets the number of label entries for the y-axis max = 25, min = 2, default: 6, be aware that this number is not fixed (if force == false) and can only be approximated.

关于android - (MPAndroidChart-LineChart) 我没有在我的应用程序中得到最后一个标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48115765/

相关文章:

android - MPAndroidChart BarChart 禁用右侧图例

c# - MVVM 模式中的 Viewpager

android - 使用gradlew assembleRelease命令生成带签名的APK时,将使用哪个签名版本?

android - MPAndroidChart PieChart 在 ScrollView 内部使用时不显示

java - 如何修复折线图十字准线的位置

javascript - 悬停工具提示上的 Google 折线图未显示值

r - Highcharts 中的 dash_styles

java - Listview-点击标题显示描述

java - 旋转 android 时出现 NullPointerException(显示改变大小)

android - 在 MPAndroidChart 负值不显示在图表坐标