gpt4 book ai didi

ios - 使用 SwiftCharts 框架时图形 View 超出范围

转载 作者:行者123 更新时间:2023-11-28 06:05:00 26 4
gpt4 key购买 nike

所以我正在使用 SwiftCharts Framework 并尝试创建一个 BarChart,但是图表不在 View 中。

我创建了一个名为 view2 的 UIView,然后实现了以下代码。

func createChart(){
let chartConfig = BarsChartConfig(
valsAxisConfig: ChartAxisConfig(from: 0, to: 8, by: 2)
)

let frame = view2.frame


let chart = BarsChart(
frame: frame,
chartConfig: chartConfig,
xTitle: "X axis",
yTitle: "Y axis",
bars: [
("A", 2),
("B", 4.5),
("C", 3),
("D", 5.4),
("E", 6.8),
("F", 0.5)
],
color: UIColor.red,
barWidth: 20
)

self.chart = chart
view2.addSubview(chart.view)
self.view.addSubview(view2)
}

并获得如下所示的输出图。 enter image description here

该图应显示在第一个托盘 View 中,但由于某种原因它会显示在下方。有人能帮助我吗。

最佳答案

不是获取框架,而是获取 view2 的边界作为图表框架

代替这一行

let frame = view2.frame

使用下面的行

let frame = view2.bounds

希望对你有帮助

关于ios - 使用 SwiftCharts 框架时图形 View 超出范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48493852/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com