PhilJay / MPAndroidChart

A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.
Other
37.64k stars 9.02k forks source link

Horizontal bar chart labels got duplicated #4119

Open slavaantonenko opened 6 years ago

slavaantonenko commented 6 years ago

Hello,

I have a Horizontal Bar Chart, everything looks very well except of one this. When I have only one entry, something strange happens. I have one bar as expected but the labels are being duplicated. I tried to searched for several hours what causing it but couldn't find. Gone step by step and follow the entries and labels but nothing. All the time I had only one label but on the view it got duplicated.

What I get:

horizontalbar_screen

This is my code:

tvChartTitle.setText("Title");
horizontalBarChart.setData(horizontalBarData);

horizontalBarChart.getAxisLeft().setEnabled(false); 
horizontalBarChart.getAxisRight().setEnabled(false); 
horizontalBarChart.getLegend().setEnabled(false); 
horizontalBarChart.getDescription().setEnabled(false); 
horizontalBarChart.getAxisLeft().setAxisMinimum(0); 
horizontalBarChart.setScaleEnabled(false); 

XAxis xAxis = horizontalBarChart.getXAxis();
xAxis.setDrawGridLines(false); 
xAxis.setDrawAxisLine(false); 
xAxis.setTextColor(getResources().getColor(R.color.barChartText)); 
xAxis.setLabelCount(horizontalBarData.getDataSetLabels().length); 
xAxis.setValueFormatter(new IndexAxisValueFormatter(labels)); 
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); 

IBarDataSet iBarDataSet = horizontalBarChart.getData().getDataSetByIndex(0);
iBarDataSet.setValueTextColor(getResources().getColor(R.color.barChartText)); 
iBarDataSet.setValueTextSize(12f); 
iBarDataSet.setHighlightEnabled(false); 
iBarDataSet.setValueFormatter(new CustomIValueFormatter());

horizontalBarData.setBarWidth(0.5f); 
horizontalBarChart.getAxisLeft().setAxisMaximum(iBarDataSet.getYMax() + 1); 

horizontalBarChart.setVisibility(View.VISIBLE);
horizontalBarChart.invalidate();

Android: API 25 Library version: 3.0.3

Thanks in advance.

slavaantonenko commented 6 years ago

Anyone?