1 y轴取整 ,如下图
####解决方法
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return (int) value + "";
}
});
y 轴对应显示的值取整
解决办法
data.setValueFormatter(new MonthlyIntegerYValueFormatter());
LineDataSet set1;
if (valueList != null && mChart != null) {
mChart.getXAxis().setLabelCount(valueList.size(), true);
}
if (mChart.getData() != null &&
mChart.getData().getDataSetCount() > 0) {
set1 = (LineDataSet) mChart.getData().getDataSetByIndex(0);
set1.setValues(valueList);
mChart.getData().notifyDataChanged();
mChart.notifyDataSetChanged();
} else {
// create a dataset and give it a type
set1 = new LineDataSet(valueList, "DataSet 1");
set1.setMode(LineDataSet.Mode.LINEAR);
set1.setAxisDependency(YAxis.AxisDependency.LEFT);
set1.setColor(chartColor);
set1.setDrawValues(true);
set1.setDrawCircleHole(false);
set1.setDrawCircles(true);
set1.setCircleColor(chartColor);
set1.setValueTextSize(9f);
set1.setDrawFilled(false);
set1.setCircleRadius(4f);
set1.setLineWidth(3f);
set1.setFillAlpha(255);
// if (Utils.getSDKInt() >= 18) {
// // fill drawable only supported on api level 18 and above
// Drawable drawable = ContextCompat.getDrawable(getActivity(), R.drawable.fade_blue);
// set1.setFillDrawable(drawable);
// } else {
// set1.setFillColor(getResources().getColor(R.color.color_main_blue));
// }
set1.setHighLightColor(Color.TRANSPARENT);//设置高亮色
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
dataSets.add(set1); // add the datasets
// create a data object with the datasets
LineData data = new LineData(dataSets);
//此为y轴数值取整关键步骤
data.setValueFormatter(new MonthlyIntegerYValueFormatter());
// set data
mChart.setData(data);
}
MonthlyIntegerYValueFormatter 源码
public class MonthlyIntegerYValueFormatter implements IValueFormatter {
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
return (int) (value) + "";
}
}