如何根据其条形拟合 x 轴标签? [英] How can I fit x-axis labels according with its bar?

查看:40
本文介绍了如何根据其条形拟合 x 轴标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ios-chart 库,并且我有一个 CombinedBarChart,默认情况下我对其进行了缩放

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)

我希望每个 x 轴标签都位于每个条形上方,但我无法使其正常工作.

I would like that each x-axis label will stay above each bar but I cannot make it work properly.

这是我的例子:

如您所见,x 轴标签与它们的条形不对应.

As you can see, x-axis labels does not correspond with their bars respectively.

如何使每个 x 轴标签都位于其条形上方?

How can I make that each x-axis label will be above of its bar?

提前致谢!

推荐答案

通过将其添加到我的组合图表中,我无法重现该问题:

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:

  1. 确保

combinedBarChart.xAxis.granularity = 1

2.将图表向左移动一点.

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]))
    }         

  1. 通过减少每个屏幕上显示的条形数量,您可以在条形之间创造更多空间,这可能会解决问题:

  1. 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)

  • 您可能还想将所有月份名称更改为 3 位数名称,例如 Jan、Feb、Mar ……以查看是否可以解决问题.如果是这样,并且您不想使用 3 位数字名称,您可以在月份名称的末尾添加空格,使它们都等长.如一月"、二月"、三月"、八月"、九月"、十月"、十二月".

  • 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 ".

    这篇关于如何根据其条形拟合 x 轴标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆