Getting duplicate values at xAxis MPChart

android, charts, mpandroidchart

Solution

I was facing the same issue to resolve it add the following line:

xAxis.setGranularityEnabled(true);

Check the link for more details about Axis.

Problem

Right Now I am facing this issue. I am getting repeated values in xAxis the first one and the last one.And graph values are not according to the values at respective x-axis values. and the second issue is if I want to display the values not in float but in int Rounded and change the their color to white. ``` ArrayList<String> xlabels = new ArrayList<String>(); xlabels.add("Jan"); xlabels.add("Feb"); xlabels.add("Mar"); xlabels.add("Apr"); xlabels.add("May"); xlabels.add("Jun"); ArrayList<String> values = new ArrayList<String>(); values.add("1"); values.add("20"); values.add("10"); values.add("80"); values.add("90"); values.add("24"); showLineChart(clickChart,xlabels,values,mColors[3]); ``` showLineChart Method: ``` private void showLineChart(LineChart chart,final List<String> xLabels, List<String> values,int color){ List<Entry> entries = new ArrayList<Entry>(); for(int i=0;i<values.size();i++){ entries.add(new Entry(i, Integer.parseInt(values.get(i)))); } LineDataSet dataSet = new LineDataSet(entries, "Numbers"); dataSet.setLineWidth(1.75f); dataSet.setCircleRadius(5f); dataSet.setCircleHoleRadius(2.5f); dataSet.setColor(Color.WHITE); dataSet.setCircleColor(Color.WHITE); dataSet.setHighLightColor(Color.WHITE); dataSet.setDrawValues(true); LineData data = new LineData(dataSet); ((LineDataSet) data.getDataSetByIndex(0)).setCircleColorHole(color); chart.getDescription().setEnabled(false); chart.setDrawGridBackground(false); chart.setTouchEnabled(true); chart.setBorderColor(Color.WHITE); chart.setDragEnabled(true); chart.setScaleEnabled(true); chart.setPinchZoom(false); chart.setBackgroundColor(color); YAxis yAxisLeft = chart.getAxisLeft(); yAxisLeft.setTextColor(Color.WHITE); yAxisLeft.setAxisLineColor(Color.WHITE); YAxis yAxisRight = chart.getAxisRight(); yAxisRight.setTextColor(Color.WHITE); yAxisRight.setAxisLineColor(Color.WHITE); XAxis xAxis = chart.getXAxis(); xAxis.setTextColor(Color.WHITE); xAxis.setAxisLineColor(Color.WHITE); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setAvoidFirstLastClipping(false); xAxis.isDrawLabelsEnabled(); xAxis.setDrawGridLines(false); xAxis.setValueFormatter(new IAxisValueFormatter() { @Override public String getFormattedValue(float value, AxisBase axis) { return xLabels.get((int)value); } }); chart.animateX(2500); chart.setData(data); chart.invalidate(); } ```

Original source