在 ListView Multi Chart Activity 中绘制额外的 upper/lower 限制

Draw extra upper/lower limit in ListViewMultiChartActivity

我已经下载了 MPAndroidChart Example 以便进行一些更改,所以我决定更改 ListViewMultiChartActivity 和 LineChartItem 我添加了 upper/lower 限制和 运行 应用程序并且它正在工作但是当我向下滚动时,在 linechart 中添加了我没有创建的其他 upper/lower 限制,这很奇怪。我添加了一些图片和代码

我正在使用 Android Studio 和 Android 8.0 API 26 和 mpandroidchart 3.1.0-alpha 只有当我向下滚动得更快时才会发生这种情况,但如果我滚动得更慢,它就不会发生。我看到的问题是 upper/lower 限制属于其他折线图并且在一个图中重叠。

https://user-images.githubusercontent.com/34872326/50542025-3ede8280-0b80-11e9-9463-1153a26caa0d.jpg

https://user-images.githubusercontent.com/34872326/50542022-3e45ec00-0b80-11e9-9c75-d9f15634bac4.jpg

holder.chart.getDescription().setEnabled(false);
holder.chart.setDrawGridBackground(false);

XAxis xAxis = holder.chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
xAxis.setTypeface(mTf);
xAxis.setDrawGridLines(false);
xAxis.setDrawAxisLine(true);

YAxis leftAxis = holder.chart.getAxisLeft();
leftAxis.setTypeface(mTf);
leftAxis.setLabelCount(5, false);
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)

YAxis rightAxis = holder.chart.getAxisRight();
rightAxis.setTypeface(mTf);
rightAxis.setLabelCount(5, false);
rightAxis.setDrawGridLines(false);
rightAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)


LimitLine upper_limit = new LimitLine(mChartData.getYMax(), "Max Value");
upper_limit.setLineWidth(2f);
upper_limit.enableDashedLine(10f, 10f, 0f);
upper_limit.setLabelPosition(LimitLine.LimitLabelPosition.RIGHT_TOP);
upper_limit.setTextSize(10f);


LimitLine lower_limit = new LimitLine(mChartData.getYMin(), "Min Value");
lower_limit.setLineWidth(2f);
lower_limit.enableDashedLine(10f, 10f, 0f);
lower_limit.setLabelPosition(LimitLine.LimitLabelPosition.RIGHT_BOTTOM);
lower_limit.setTextSize(10f);

leftAxis.addLimitLine(upper_limit);
leftAxis.addLimitLine(lower_limit);
leftAxis.setDrawLimitLinesBehindData(true);



// set data
holder.chart.setData((LineData) mChartData);

// do not forget to refresh the chart
// holder.chart.invalidate();
holder.chart.animateX(750);

return convertView;

我找到了答案。我需要把 leftAxis.removeAllLimitLines();在添加限制之前,因为该行代码防止限制重叠 –