我正在使用com.github.PhilJay:MPAndroidChart
库来获取android图,但它显示了
数据集值位于错误位置,如下所示:
在上图中,紫色lineSet
显示错误yAxis
值的值。
我设置值的代码是:
if (chart_lab.getData() != null && chart_lab.getData().getDataSetCount() > 0) {
set1 = (LineDataSet) chart_lab.getData().getDataSetByIndex(0);
set1.setValues(values);
set2 = (LineDataSet) chart_lab.getData().getDataSetByIndex(1);
set2.setValues(hbpVals2);
/*ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
dataSets.add(set1); // add the datasets
dataSets.add(set2);
// create a data object with the datasets
LineData data = new LineData(dataSets);
chart_lab.setData(data);*/
chart_lab.getData().notifyDataChanged();
chart_lab.notifyDataSetChanged();
chart_lab.animateY(500);
} else {
// create a dataset and give it a type
set1 = new LineDataSet(values, "Diastolic BP(mmHg)");
set1.setCubicIntensity(0.1f);
set1.enableDashedLine(10f, 5f, 0f);
set1.enableDashedHighlightLine(10f, 5f, 0f);
set1.setColor(Color.RED);
set1.setCircleColor(Color.BLACK);
set1.setLineWidth(2f);
set1.setHighLightColor(Color.RED);
set1.setCircleRadius(4f);
set1.setDrawCircleHole(false);
set1.setValueTextSize(9f);
//set1.setDrawFilled(true);
set1.setFormLineWidth(1f);
set1.setFormLineDashEffect(new DashPathEffect(new float[]{10f, 5f}, 0f));
set1.setFormSize(15.f);
set2 = new LineDataSet(hbpVals2, "Systolic BP(mmHg)");
set2.setCubicIntensity(0.1f);
set2.setAxisDependency(YAxis.AxisDependency.RIGHT);
set2.setColor(activity.getResources().getColor(R.color.colorPrimary));
set2.setCircleColor(activity.getResources().getColor(R.color.colorPrimaryDark));
set2.setLineWidth(2f);
set2.setCircleRadius(4f);
set2.setFillAlpha(65);
set2.setFillColor(Color.RED);
set2.setDrawCircleHole(false);
set2.setHighLightColor(Color.rgb(244, 117, 117));
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
dataSets.add(set1); // add the datasets
dataSets.add(set2);
// create a data object with the datasets
LineData data = new LineData(dataSets);
// set data
chart_lab.setData(data);
chart_lab.animateY(500);
chart_lab.invalidate();
chart_lab.refreshDrawableState();
}
如果有人知道这个问题,请帮忙。
答案 0 :(得分:0)
我通过从上面的代码中删除以下行解决了我的问题:
set2.setAxisDependency(YAxis.AxisDependency.RIGHT);