Charts: BarChart - xAxis Labels disappear if not a min of 2 on the screen

Created on 9 Oct 2017  路  12Comments  路  Source: danielgindi/Charts

Hi guys,

I am having an issue with a grouped (by months) yearly bar chart. The chart is dragEnabled so it scrolls as I have a visibleXRange of 1.2 (out of a group/year). The data I have has at least 2 groups/years.

chartView.setVisibleXRange(minXRange: 1.2, maxXRange: 1.2)
chartView.moveViewToX(endYear+1)
chartView.notifyDataSetChanged()

Now the problem is that my labels disappear if there aren't a minimum of 2 visible on the screen. See the gif below.
I already tried the notifyDataSetChanged(). I also tried removing the labelcount min max values from the AxisBase.

chart labels mov

Any help is greatly appreciated. Thanks!

Most helpful comment

@honcharenko13 I modified the BarChartRenderer, in drawDataSet after setting the colors:

//Corner radius
let cornerRadius = CGSize(width: 2, height: 2)
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: UIRectCorner.allCorners, cornerRadii: cornerRadius)
context.addPath(bezierPath.cgPath)
context.fillPath()

All 12 comments

pls tell how did you implement rounded corners?

@honcharenko13 I modified the BarChartRenderer, in drawDataSet after setting the colors:

//Corner radius
let cornerRadius = CGSize(width: 2, height: 2)
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: UIRectCorner.allCorners, cornerRadii: cornerRadius)
context.addPath(bezierPath.cgPath)
context.fillPath()

@roxanajula thanks. I thought I overlooked some property inside app without pod modification.
So in your case you need to copy library fully to project, right?

@honcharenko13 What i did is I created a CustomBarChartRenderer that inherits from BarChartRenderer, copied the code for drawDataSet from the library and override it, and then use the CustomBarChartRenderer on the chart. But I am not saying it is the best solution 馃槃

@honcharenko13 you should search in the issues "rounded corners" there were some discussions about this

@roxanajula thank you for detailed description. I will consider other library that I've found and it has ability to set rounded corners

I have also checked the xAxis.entries in my XAxisRenderer, and when there are 2 years visible they are correct, when the labels are not visible the xAxis.entries is equal to []

@liuxuan30 It seems that in the cases where the labels are not visible the xAxis.entries is empty. (when less than 2 labels are visible) Would you be so kind to point me into the direction at what I should look at/change? Thanks!

please first take a look at computeAxisValues() if axis.entries are generated correctly. If this is the case, why it's empty?

@roxanajula, can you tell how did you implement the year labels at the top of the chart?

@roxanajula you got more questions than answers :) your chart looks splendid :) ..

I made my own custom renderer based on the framework more than a year ago, the framework has a lot of releases since then, so unfortunately what I did back then won't help much with the current framework. :) Closing the issue now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BrandonShega picture BrandonShega  路  4Comments

sjdevlin picture sjdevlin  路  3Comments

PrashantKT picture PrashantKT  路  3Comments

heumn picture heumn  路  3Comments

kirti0525 picture kirti0525  路  3Comments