热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

iOS图表Swift条形图超出了视野-iOSChartsSwiftbargraphexceedsbeyondview

IhaveaproblemwiththeChartslibrary.TheproblemIamfacingisthatthebargraphisnotfit

I have a problem with the Charts library. The problem I am facing is that the bar graph is not "fit" within the borders of my view. The following image shows that, the both first and last bar are cut into half and label of the highest bar is also partially cut.

我的图表库有问题。我面临的问题是条形图在我的视图边界内“不适合”。下图显示,第一个和最后一个条都被切成两半,最高条的标签也被部分切割。

Bars and labels are cut along the graph borders

沿图形边界切割条形和标签

When I search online, I got the following thread https://github.com/danielgindi/Charts/issues/353 which seems to describe the exact same issue.

当我在网上搜索时,我得到了以下主题https://github.com/danielgindi/Charts/issues/353,这似乎描述了完全相同的问题。

I use a simple dataset with some random numbers at 6 indices. The data is added to the chart as follows:

我使用一个简单的数据集,其中包含6个索引的随机数。数据添加到图表中,如下所示:

let values: [Int] = [5, 8, 1, 2, 1, 2]
var dataEntries: [BarChartDataEntry]

for i in 0..

Hopefully someone can help me out. Thanks in advance!

希望有人可以帮助我。提前致谢!

4 个解决方案

#1


16  

There is a bug in the library with regards to calculating the xAxis minimum and maximum.

库中有一个关于计算xAxis最小值和最大值的错误。

You can manually set the xAxis minimum and maximum to prevent the first and last bars to be shown in half.

您可以手动设置xAxis的最小值和最大值,以防止第一个和最后一个柱显示为一半。

Add the below line of code, it should work perfectly fine.

添加下面的代码行,它应该可以正常工作。

yourBarChartView.xAxis.axisMinimum = -0.5;
yourBarChartView.xAxis.axisMaximum = Double(yourAxisDataList.count) - 0.5;

#2


5  

you can add the offset to Top and bottom view as below :

您可以将偏移量添加到顶视图和底视图,如下所示:

 barChartView.extraTopOffset = 40.0f;
 barChartView.extraBottomOffset = 10.0f;

#3


0  

If it is vertical Bar chart

如果是垂直条形图

barChartView.xAxis.spaceMin   = 5.0f;
barChartView.xAxis.spaceMax   = 5.0f;

if it is Horizantal bar chart

如果是Horizantal条形图

barChartView.leftAxis.spaceBottom = 0.0 

or barChartView.rightAxis.

或barChartView.rightAxis。

#4


0  

You can try, editting the value of xAxis of your bargraph with values between -0.99... to -0.5. Check this example:

您可以尝试使用介于-0.99 ...到-0.5之间的值编辑条形图的xAxis值。检查此示例:

enter image description here

With: yourBarChart.xAxis.axisMinimum = -0.5

使用:yourBarChart.xAxis.axisMinimum = -0.5

enter image description here

With: yourBarChart.xAxis.axisMinimum = -0.99

使用:yourBarChart.xAxis.axisMinimum = -0.99


推荐阅读
author-avatar
真理难辩_175
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有