问题
I am using ios-chart
library and I have a CombinedBarChart
in which I made zoom on it by default
combinedBarChart.setScaleMinima(2, scaleY: 1)
combinedBarChart.setScaleEnabled(false)
I would like that each x-axis label will stay above each bar but I cannot make it work properly.
Here is my example:
As you can see, x-axis labels does not correspond with their bars respectively.
How can I make that each x-axis label will be above of its bar?
Thanks in advance!
回答1:
I was not able to reproduce the problem by adding this to my combinedChart:
combinedBarChart.setScaleMinima(2, scaleY: 1)
combinedBarChart.setScaleEnabled(false)
But until you upload your code, I can suggest the following:
Make sure
combinedBarChart.xAxis.granularity = 1
2. Shift the graph a bit to the left.
var shift = -0.2
var entries: [BarChartDataEntry] = []
for index in 0..<datapoints.count {
let value1 = Double(datapoints[index])
let value2 = Double(datapoints[index])
entries.append(BarChartDataEntry(x: Double(index)+shift, yValues: [value1, value2]))
}
By lowering the number of bars shown on each screen, you create more space between bars and that might solve the problem:
combinedBarChart.setVisibleXRange(minXRange: 4.0, maxXRange: 4.0)
You might also want to change all the month names to a 3 digit name, like Jan, Feb, Mar, ... to see if that makes the problem go away. If it does, and you don´t want to use 3 digit names, you can add white spaces at the end of the month names to make them all equally long. Like "January ", "February ", "March ", "August ", "September", "October ", "December ".
来源:https://stackoverflow.com/questions/44843745/how-can-i-fit-x-axis-labels-according-with-its-bar