Data set values on Horizontal Bar chart disappear on zooming along y-axis
The values next to the bar in horizontal bar graph disappear on scaling along y-axis. It reappears when scrolled to far left
I am having the same issue...
Could one of you please explain this issue further, perhaps with a video if you can?
Starting from this initially and zooming just a bit till zero/start goes off the chart makes the values on top of the bars disappear (as seen here). While zoomed in, any time the start appears in the chart again, the values also reappear.
Deleting the useless parts, the minimal dummy code below can still reproduce the issue:
HorizontalBarChart horizontalBarChart;
List<BarEntry> barEntries = new ArrayList<>();
barEntries.add(new BarEntry(1, 1));
barEntries.add(new BarEntry(2, 2));
barEntries.add(new BarEntry(3, 3));
BarDataSet dataSet = new BarDataSet(barEntries, "Label");
YAxis yAxisLeft = horizontalBarChart.getAxisLeft();
yAxisLeft.setAxisMinimum(0);
BarData barData = new BarData(dataSet);
horizontalBarChart.setData(barData);
int chartHeightDp = 10 + 30 * entries.length;
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
horizontalBarChart.setMinimumHeight((int) (chartHeightDp * (metrics.densityDpi / 160f)));
horizontalBarChart.invalidate();
Upon investigating it quickly, it seems like this block of code is triggered:
if (!mViewPortHandler.isInBoundsX(buffer.buffer[j]))
continue;
and the drawing of the values is skipped.
Yeah that definitely looks like the cause. It should check the Y-value on horizontal bar charts instead of the X-value. I'll fix this soon.
I'm using version v3.1.0 and seeing a very similar issue. But it is happening in the vertical version of the Bar chart. A few columns disappear in a given zoom level and drag position. Very weird.
Maybe it's related?
I have this problem too. I did a video. Android Emulator - Pixel_2_API_26_5554 2020-03-31 16-34-32.zip
I found the problem seen in the video posted some minutes ago.
The BarEntry values must be added ordered (ascendent) by "X" value. This code will generate the issue:
ArrayList<BarEntry> binClassEntries = new ArrayList<BarEntry>(); for(int i = 0; i <20; i++) binClassEntries.add(new BarEntry((float)20-i,(float)new Random().nextInt(2000)));
This code works:
ArrayList<BarEntry> binClassEntries = new ArrayList<BarEntry>(); for(int i = 0; i <20; i++) binClassEntries.add(new BarEntry((float)i,(float)new Random().nextInt(2000)));
Any update or resolution?
I'm using version v3.1.0 and seeing a very similar issue. But it is happening in the vertical version of the Bar chart. A few columns disappear in a given zoom level and drag position. Very weird.
Maybe it's related?
You can resolve it?
I got this problem, too...but it only happens when my inserted entries aren't in ascending order.
I have no idea why it works, but yeah. Sorting my values fixed the disappearing bars issue
I still didn't find any solution for the original issue. The best I could possibly do is disable scaling on the X axis (.setScaleXEnabled(false)).
Based on the comments, I managed to formulate my solution to the rendering issue of bars when zooming. I created a class called 'DataXY' which has 2 attributes, 'valueX' and 'valueY'. Then, I iterate through the list of data that I want to display in the chart and add them to a 'mutableListOf<DataXY>()'. This option solves the case where there are different X values with different Y values, and the Y values need to be accumulated for the same X value. By creating the necessary logic, the data can be accumulated in a list of type 'DataXY'. If this list is sorted (ascending), the visual bug is resolved. After sorting this list, it is iterated through, and the data from the 'DataXY' objects are added to a new list of 'BarEntry', which is displayed in the chart.