fade_red.xml
<?xml version="1.0" encoding="utf-8"?>
CustomValueFormatter
class CustomValueFormatter extends ValueFormatter {
int maxValue;
public CustomValueFormatter(int maxValue) {
this.maxValue = maxValue;
}
@Override
public String getAxisLabel(float value, AxisBase axis) {
int newValue = (int) value + maxValue;
return newValue + "";
}
@Override
public String getPointLabel(Entry entry) {
int newValue = (int) entry.getY() + maxValue;
return newValue + "";
}
}
данные диаграммы и настройки
chart.setDragEnabled(true);
chart.setScaleXEnabled(false);
chart.setScaleYEnabled(true);
chart.getAxisRight().setEnabled(false);
chart.getAxisLeft().setDrawAxisLine(false);
chart.getXAxis().setEnabled(false);
chart.getLegend().setEnabled(false);
chart.getDescription().setText("");
chart.setTouchEnabled(true);
ArrayList<Entry> list = new ArrayList<>();
int maxValue = 1000;
for (int i = 0; i < 10; i++) {
list.add(new Entry(i, (100 * i) - 1000));
}
chart.getAxisLeft().setAxisMaximum(0);
chart.getAxisLeft().setAxisMinimum(-maxValue);
chart.getAxisLeft().setLabelCount(5);
CustomValueFormatter valueFormatter = new CustomValueFormatter(maxValue);
chart.getAxisLeft().setValueFormatter(valueFormatter);
LineDataSet dataset = new LineDataSet(list, "");
int color = ContextCompat.getColor(this, R.color.orange);
dataset.setColor(color);
dataset.setDrawCircles(false);
dataset.setDrawFilled(true);
Drawable drawable = ContextCompat.getDrawable(this, R.drawable.fade_red);
dataset.setFillDrawable(drawable);
ArrayList<ILineDataSet> sets = new ArrayList<>();
sets.add(dataset);
LineData lineData = new LineData(sets);
lineData.setValueFormatter(valueFormatter);
chart.setData(lineData);