0

I am trying to plot a bar chart , and want to set labels on the bar chart. But the label for the last entry is not showing. Below is how I set my graph. The machines arraylist contains the labels, which I copy into my string array mac[].

            String[] mac = new String[machines.size()];;
            for(int i=0;i<machines.size();++i)
            {
               mac[i] = machines.get(i);
            }


            BarChart chart1 = (BarChart) findViewById(R.id.chart1);
            BarDataSet bds2 = new BarDataSet(barEntries, "Target");
            BarDataSet bds1 = new BarDataSet(barEntries1,"Prepared");
            bds1.setColor(Color.parseColor("#F44336"));
            BarData ddata1 = new BarData(bds1,bds2);
            chart1.setScaleEnabled(true);
            chart1.setPinchZoom(true);
            chart1.setData(ddata1);
            XAxis xa1 = chart1.getXAxis();
            xa1.setValueFormatter(new MyAxisValueFormatter(mac));

            xa1.setCenterAxisLabels(true);
            chart1.setTouchEnabled(true);
            chart1.setDragEnabled(true);
            chart1.setScaleEnabled(true);
            float groupSpace = 0.0f;
            float barSpace = 0.0f; 
            chart1.fitScreen();
            ddata1.setBarWidth(barWidth);
            xa1.setLabelCount(machines.size(),true);
            chart1.groupBars( 0.0f,groupSpace, barSpace);
            chart1.setFitBars(true); // make the x-axis fit exactly all bars
            chart1.setVisibility(View.VISIBLE);
            xa1.setGranularity(1f);
            xa1.setAxisMinimum(0);
            xa1.setGranularityEnabled(true);
            xa1.setCenterAxisLabels(true);
            chart1.invalidate();

This is my MyAxisValueFormatter class

 public class MyAxisValueFormatter implements IAxisValueFormatter
    {
        private String [] m;
        public MyAxisValueFormatter(String[] arr)
        {
            this.m = arr;
        }

        @Override
        public String getFormattedValue(float value, AxisBase axis) {
         return m[(int) value];
        }

        @Override
        public int getDecimalDigits() {
            return 0;
        }


    }

Now I am pretty sure that the machines arraylist size is 12, but the number of labels on my graph are only 11, i.e, the last label is not displayed. I tried displaying the value variable in the MyAxisValueFormatter class's getFormattedValue function, in the logs. And got this. According to the documentation "value" represents the position of the label on the axis (x or y).

The logs are:

07-24 21:21:28.299 26339-26339/com.example.quickstart I/flag: -0.5
07-24 21:21:28.300 26339-26339/com.example.quickstart I/flag: 0.5909091
    1.6818182
    2.7727275
    3.8636365
    4.9545455
    6.0454545
    7.1363635
    8.227273
    9.318182
    10.409091
    11.5
07-24 21:21:28.304 26339-26339/com.example.quickstart I/flag: 0.0
    1.0681819
    2.1363637
    3.2045455
    4.2727275
    5.3409095
07-24 21:21:28.305 26339-26339/com.example.quickstart I/flag: 6.4090915
    7.4772735
    8.545455
    9.613637
    10.681819
    11.750001
07-24 21:21:28.310 26339-26339/com.example.quickstart I/flag: 0.0
    1.0681819
    2.1363637
    3.2045455
    4.2727275
    5.3409095
    6.4090915
    7.4772735
    8.545455
    9.613637
07-24 21:21:28.311 26339-26339/com.example.quickstart I/flag: 10.681819
    11.750001
07-24 21:21:28.313 26339-26339/com.example.quickstart I/flag: 0.0
    1.0681819
07-24 21:21:28.314 26339-26339/com.example.quickstart I/flag: 2.1363637
07-24 21:21:28.315 26339-26339/com.example.quickstart I/flag: 3.2045455
    4.2727275
    5.3409095
07-24 21:21:28.316 26339-26339/com.example.quickstart I/flag: 6.4090915
    7.4772735
07-24 21:21:28.317 26339-26339/com.example.quickstart I/flag: 8.545455
    9.613637
07-24 21:21:28.318 26339-26339/com.example.quickstart I/flag: 10.681819
07-24 21:21:28.344 26339-26339/com.example.quickstart I/flag: 0.0
07-24 21:21:28.345 26339-26339/com.example.quickstart I/flag: 1.0681819
    2.1363637
    3.2045455
    4.2727275
    5.3409095
    6.4090915
    7.4772735
    8.545455
    9.613637
    10.681819
    11.750001
07-24 21:21:28.348 26339-26339/com.example.quickstart I/flag: 0.0
    1.0681819
07-24 21:21:28.349 26339-26339/com.example.quickstart I/flag: 2.1363637
    3.2045455
    4.2727275
07-24 21:21:28.350 26339-26339/com.example.quickstart I/flag: 5.3409095
    6.4090915
    7.4772735
07-24 21:21:28.351 26339-26339/com.example.quickstart I/flag: 8.545455
    9.613637
    10.681819

Now I am not getting why doesn't 11.750001 get printed in the last line. And also why does the value of x increase by 0.6 approx like from 0 to 1.0681819 and not to 1. I am probably making a trivial mistake which is causing my labels positioning on the axis to get messed up. All I want is to get all my labels displayed. Please look into this. Any assistance appreciated.

This is a scrot of my current running app. As you can see there are only 11 labels, when there should be 12.

Screen Shot

EDIT:

barentries values are, the values after FTP12:

07-24 21:56:50.612 1755-1982/com.example.quickstart I/FTP12: 0000002500 
07-24 21:56:50.615 1755-1982/com.example.quickstart I/FTP12: 0000007350 
07-24 21:56:50.619 1755-1982/com.example.quickstart I/FTP12: 0000004500 
07-24 21:56:50.622 1755-1982/com.example.quickstart I/FTP12: 0000007000 
07-24 21:56:50.624 1755-1982/com.example.quickstart I/FTP12: 0000007000 
07-24 21:56:50.626 1755-1982/com.example.quickstart I/FTP12: 0000003500 
07-24 21:56:50.628 1755-1982/com.example.quickstart I/FTP12: 0000009000 
07-24 21:56:50.631 1755-1982/com.example.quickstart I/FTP12: 0000007151 
07-24 21:56:50.633 1755-1982/com.example.quickstart I/FTP12: 0000004378 
07-24 21:56:50.635 1755-1982/com.example.quickstart I/FTP12: 0000006810 
07-24 21:56:50.637 1755-1982/com.example.quickstart I/FTP12: 0000003405 
07-24 21:56:50.639 1755-1982/com.example.quickstart I/FTP12: 0000008756 

barentries1 values are, the values after barentries1:

07-24 21:59:20.008 3331-3435/com.example.quickstart I/barentries1: 000000000001504 
07-24 21:59:20.013 3331-3435/com.example.quickstart I/barentries1: 000000000002842 
07-24 21:59:20.017 3331-3435/com.example.quickstart I/barentries1: 000000000001796 
07-24 21:59:20.020 3331-3435/com.example.quickstart I/barentries1: 000000000003658 
07-24 21:59:20.023 3331-3435/com.example.quickstart I/barentries1: 000000000001965 
07-24 21:59:20.025 3331-3435/com.example.quickstart I/barentries1: 000000000000796 
07-24 21:59:20.027 3331-3435/com.example.quickstart I/barentries1: 000000000007631 
07-24 21:59:20.029 3331-3435/com.example.quickstart I/barentries1: 000000000006323 
07-24 21:59:20.032 3331-3435/com.example.quickstart I/barentries1: 000000000000496 
07-24 21:59:20.033 3331-3435/com.example.quickstart I/barentries1: 000000000003531 
07-24 21:59:20.035 3331-3435/com.example.quickstart I/barentries1: 000000000002313 
07-24 21:59:20.037 3331-3435/com.example.quickstart I/barentries1: 000000000000954 
07-24 21:59:20.040 3331-3435/com.example.quickstart I/barentries1: 000000000005071 

machines values are, the values after machines:

07-24 22:00:14.244 3639-3709/com.example.quickstart I/machines: TEMP-2 
07-24 22:00:14.249 3639-3709/com.example.quickstart I/machines: TEMP-3 
07-24 22:00:14.254 3639-3709/com.example.quickstart I/machines: TEMP-1 
07-24 22:00:14.257 3639-3709/com.example.quickstart I/machines: BENTLER-1 
07-24 22:00:14.263 3639-3709/com.example.quickstart I/machines: BENTLER-2 
07-24 22:00:14.265 3639-3709/com.example.quickstart I/machines: DEMAN 
07-24 22:00:14.267 3639-3709/com.example.quickstart I/machines: ANNE-LOSE 
07-24 22:00:14.269 3639-3709/com.example.quickstart I/machines: TEMP-3 
07-24 22:00:14.272 3639-3709/com.example.quickstart I/machines: ANNEALD-1 
07-24 22:00:14.274 3639-3709/com.example.quickstart I/machines: TEMP-1 
07-24 22:00:14.276 3639-3709/com.example.quickstart I/machines: BENTLER-1 
07-24 22:00:14.278 3639-3709/com.example.quickstart I/machines: DEMAN 
07-24 22:00:14.280 3639-3709/com.example.quickstart I/machines: ANNE-LOSE 
rexGibbs
  • 1
  • 4

0 Answers0