Search in sources :

Example 16 with IAxisValueFormatter

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);
}
Also used : ArrayList(java.util.ArrayList) IAxisValueFormatter(com.github.mikephil.charting.formatter.IAxisValueFormatter) BarData(com.github.mikephil.charting.data.BarData) AxisBase(com.github.mikephil.charting.components.AxisBase) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Aggregations

IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)16 AxisBase (com.github.mikephil.charting.components.AxisBase)15 XAxis (com.github.mikephil.charting.components.XAxis)13 YAxis (com.github.mikephil.charting.components.YAxis)11 Legend (com.github.mikephil.charting.components.Legend)7 ArrayList (java.util.ArrayList)7 SpannableString (android.text.SpannableString)5 Entry (com.github.mikephil.charting.data.Entry)5 OsmandSettings (net.osmand.plus.OsmandSettings)4 BarData (com.github.mikephil.charting.data.BarData)3 LineData (com.github.mikephil.charting.data.LineData)3 ILineDataSet (com.github.mikephil.charting.interfaces.datasets.ILineDataSet)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 SuppressLint (android.annotation.SuppressLint)2 TextView (android.widget.TextView)2 MarkerView (com.github.mikephil.charting.components.MarkerView)2 LineDataSet (com.github.mikephil.charting.data.LineDataSet)2 IBarDataSet (com.github.mikephil.charting.interfaces.datasets.IBarDataSet)2 RadarMarkerView (com.xxmassdeveloper.mpchartexample.custom.RadarMarkerView)2