Android Mp Chart如何基于折线图中x和y轴的交点在X轴上显示标签

时间:2019-03-19 09:36:01

标签: java android mpandroidchart

在我的Android应用中,我正在使用Android折线图,x轴用标签表示,y轴是数字,我需要根据每个部分对齐标签,我该如何实现?请参考这张图片

https://drive.google.com/open?id=1MRrGKZiYKPlj-f3LenCI6JwTNxVTCkEO

标签应该像1对齐-> Jhow,2-> nihl 3-> biy,4-> hihiyr 5-> Suwn  请查看我的代码  标签是动态的,来自json数据

 ArrayList<Entry> yValue = new ArrayList<>();
                for (int i = 0;i<usergraphXaxiesData.size();i++) {
                usergraphXaxiesData.get(usergraphXaxiesData.size()-1);

                    yValue.add(new Entry(usergraphXaxiesData.get(i), usergraphYaxiesData.get(i)));
                    //userChart.getXAxis().setGranularity(usergraphXaxiesData.get(i));
                }
                userSet = new LineDataSet(yValue, "");
                userSet.setColor(getActivity().getResources().getColor(R.color.fbutton_color_orange));
                userSet.setLineWidth(3);
                userSet.setDrawValues(false);
                userSet.setAxisDependency(YAxis.AxisDependency.LEFT);
                final ArrayList<ILineDataSet> dataSets = new ArrayList<>();
                dataSets.add(userSet);
                userData = new LineData(dataSets);
                userChart.setData(userData);
                userChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
                userChart.getXAxis().setLabelCount(xVals.size()+1);
                userChart.getXAxis().setValueFormatter(new IndexAxisValueFormatter(xVals));
                final XAxis xAxis = userChart.getXAxis();

                xAxis.setDrawGridLines(false);
                xAxis.setAxisMaximum(xVals.size()+1);
                xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);

                xAxis.setAvoidFirstLastClipping(true);
                userChart.getXAxis().setGranularityEnabled(true) ;
                xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
                xAxis.setDrawGridLines(false);

0 个答案:

没有答案