这可能很简单,但我还不习惯Iphone编程和Swift。我只使用过Android。我想在我的应用程序中使用iosChart。我按照this教程创建了一个测试条形图。
问题是图表不适合屏幕,但是扩展到模拟器中的显示之外。在故事板中可能有一些容易修复的东西,但我没有找到任何东西。
以下是它的样子:
x轴应延伸至12月,但不可见。
以下是代码:
import UIKit
import Charts
class DetailedScoreController: UIViewController {
var results : Results
var months: [String]!
// MARK: Initialization
@IBOutlet weak var detailedChart: BarChartView!
required init?(coder aDecoder: NSCoder) {
self.results = Results()!
super.init(coder: aDecoder)
}
override func viewDidLoad() {
super.viewDidLoad()
print("DetailedResultController Created!");
self.results.printResult()
self.results.printDetailedResults()
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
let unitsSold = [20.0, 4.0, 6.0, 3.0, 12.0, 16.0, 4.0, 18.0, 2.0, 4.0, 5.0, 4.0]
setChart(months, values: unitsSold)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: Set up barchart
func setChart(dataPoints: [String], values: [Double]) {
var dataEntries: [BarChartDataEntry] = []
for i in 0..<dataPoints.count {
let dataEntry = BarChartDataEntry(value: values[i], xIndex: i)
dataEntries.append(dataEntry)
}
let chartDataSet = BarChartDataSet(yVals: dataEntries, label: "Units Sold")
let chartData = BarChartData(xVals: months, dataSet: chartDataSet)
detailedChart.data = chartData
}
}
以下是故事板的外观,标记为条形图:
对我来说,整个图表看起来应该在显示屏上。