use of com.github.mikephil.charting.formatter.IAxisValueFormatter in project MPAndroidChart by PhilJay.
the class BarChartPositiveNegative method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_barchart_noseekbar);
setTitle("BarChartPositiveNegative");
chart = findViewById(R.id.chart1);
chart.setBackgroundColor(Color.WHITE);
chart.setExtraTopOffset(-30f);
chart.setExtraBottomOffset(10f);
chart.setExtraLeftOffset(70f);
chart.setExtraRightOffset(70f);
chart.setDrawBarShadow(false);
chart.setDrawValueAboveBar(true);
chart.getDescription().setEnabled(false);
// scaling can now only be done on x- and y-axis separately
chart.setPinchZoom(false);
chart.setDrawGridBackground(false);
XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
xAxis.setTypeface(tfRegular);
xAxis.setDrawGridLines(false);
xAxis.setDrawAxisLine(false);
xAxis.setTextColor(Color.LTGRAY);
xAxis.setTextSize(13f);
xAxis.setLabelCount(5);
xAxis.setCenterAxisLabels(true);
xAxis.setGranularity(1f);
YAxis left = chart.getAxisLeft();
left.setDrawLabels(false);
left.setSpaceTop(25f);
left.setSpaceBottom(25f);
left.setDrawAxisLine(false);
left.setDrawGridLines(false);
// draw a zero line
left.setDrawZeroLine(true);
left.setZeroLineColor(Color.GRAY);
left.setZeroLineWidth(0.7f);
chart.getAxisRight().setEnabled(false);
chart.getLegend().setEnabled(false);
// THIS IS THE ORIGINAL DATA YOU WANT TO PLOT
final List<Data> data = new ArrayList<>();
data.add(new Data(0f, -224.1f, "12-29"));
data.add(new Data(1f, 238.5f, "12-30"));
data.add(new Data(2f, 1280.1f, "12-31"));
data.add(new Data(3f, -442.3f, "01-01"));
data.add(new Data(4f, -2280.1f, "01-02"));
xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return data.get(Math.min(Math.max((int) value, 0), data.size() - 1)).xAxisValue;
}
});
setData(data);
}
Aggregations