我在项目中使用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
,则会显示如下:
在两种方式中,线条都搞砸了。我做错了什么?
答案 0 :(得分:1)
右轴的轴线会干扰您的图表。试试这个:
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);