我在项目中使用MPAndroidChart。而且我在使用Y轴线时遇到了一些麻烦。
这是我的代码:
chart = (LineChart) rootView.findViewById(R.id.chart);
List<Entry> entries = new ArrayList<Entry>();
entries.add(new Entry(1, 0));
entries.add(new Entry(6, 15));
entries.add(new Entry(7, 9));
entries.add(new Entry(15, 90));
chart.setDescription("");
YAxis yRight = chart.getAxisRight();
YAxis yLeft = chart.getAxisLeft();
XAxis xAxis = chart.getXAxis();
yRight.setDrawLabels(false);
yRight.setDrawAxisLine(false);
//chart.setVisibleYRange(0, 100, YAxis.AxisDependency.LEFT);
yLeft.setDrawAxisLine(false);
yLeft.setDrawGridLines(true);
yLeft.setAxisMaxValue(100f);
yLeft.setAxisMinValue(0f);
yLeft.setLabelCount(5, true);
yLeft.setTextColor(Color.parseColor("#414345"));
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawAxisLine(false);
xAxis.setDrawGridLines(false);
xAxis.setTextColor(Color.parseColor("#414345"));
LineDataSet dataSet = new LineDataSet(entries, "Label");
dataSet.setColor(Color.parseColor("#5dd054"));
dataSet.setValueTextColor(Color.parseColor("#313234"));
dataSet.setDrawValues(false);
dataSet.setDrawCircles(false);
LineData lineData = new LineData(dataSet);
chart.setData(lineData);
chart.invalidate();
如果我将
yLeft.setDrawGridLines(true)
设置为true
,则显示如下:如果我将
yLeft.setDrawGridLines(false)
设置为false
,则显示如下:两种方式都搞砸了。我做错了什么?
最佳答案
右轴的轴线会干扰您的图表。尝试这个:
XAxis xl = chart.getXAxis();
xl.setDrawAxisLine(true);
xl.setDrawGridLines(false);
YAxis yl = chart.getAxisLeft();
yl.setDrawAxisLine(true);
yl.setDrawGridLines(false);
YAxis yr = chart.getAxisRight();
yr.setDrawAxisLine(true);
yr.setDrawGridLines(false);
关于android - MPAndroidChart的y轴网格线被弄乱了。如何正确安排?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39599508/