YAxis yAxis = mChart.getAxisLeft();
//设置x轴的最大值
yAxis.setAxisMaximum(yMax);
// 设置y轴的最大值
yAxis.setAxisMinimum(yMin);
// 不显示y轴
yAxis.setDrawAxisLine(false);
// 设置y轴数据的位置
yAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
// 不从y轴发出横向直线
yAxis.setDrawGridLines(false);
// 是否显示y轴坐标线
yAxis.setDrawZeroLine(true);
// 设置y轴的文字颜色
yAxis.setTextColor(mChart.getResources().getColor(R.color.char_text_color));
// 设置y轴文字的大小
yAxis.setTextSize(12);
// 设置y轴数据偏移量
//yAxis.setXOffset(30);
// yAxis.setYOffset(-3);
yAxis.setXOffset(15);
// 设置y轴label 数量
yAxis.setLabelCount(5, false);
// 设置y轴的最小刻度
yAxis.setGranularity(5);//interval
* 7,缩放和动画设置
Matrix matrix = new Matrix();
// 根据数据量来确定 x轴缩放大倍
if (mLabels.size() <= 10) {
matrix.postScale(1.0f, 1.0f);
} else if (mLabels.size() <= 15) {
matrix.postScale(1.5f, 1.0f);
} else if (mLabels.size() <= 20) {
matrix.postScale(2.0f, 1.0f);
} else {
matrix.postScale(3.0f, 1.0f);
}
// 在图表动画显示之前进行缩放
mChart.getViewPortHandler().refresh(matrix, mChart, false);
// x轴执行动画
mChart.animateX(500);
* 8, 无数据时,显示文案
/**
* 显示无数据的提示
*
* @param mChart
*/
public static void NotShowNoDataText(Chart mChart) {
mChart.clear();
mChart.notifyDataSetChanged();
mChart.setNoDataText(“你还没有记录数据”);
mChart.setNoDataTextColor(Color.WHITE);
// 记得最后要刷新一下
mChart.invalidate();
}
* 9,设置marker (1)首先需要继承MarkerView 实现一个自定义View
public class ChartMarkerView extends MarkerView {
private TextView textView;
/**
* Constructor. Sets up the MarkerView with a custom layout resource.
*
* @param context
* @param layoutResource the layout resource to use for the MarkerView
*/
public ChartMarkerView(Context context, int layoutResource) {
super(context, layoutResource);
textView = (TextView) findViewById(R.id.marker_view_text);
}
@Override
public void refreshContent(Entry e, Highlight highlight) {
float value = e.getY();
textView.setText(DecimalFormatUtils.getIntOrFloatRemainOne(value));