通过cocoapods安装库https://github.com/AAChartModel/AAChartKit-Swift之后,我尝试运行存储库中提供的示例。
我遇到以下错误
Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
..在这些行上(在库中,我没有写过它们)
let path = Bundle.main.path(forResource: "AAChartView", ofType: "html", inDirectory: "AAJSFiles.bundle")
let urlStr = NSURL.fileURL(withPath: path!)
我不知道该如何解决...似乎在构建时资源文件夹没有复制到捆绑软件中。
这是我正在执行的代码:
let chart = AAChartView()
chart.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height)
self.view.addSubview(chart)
let model = AAChartModel.init()
.chartType(AAChartType.Column)//Can be any of the chart types listed under `AAChartType`.
.animationType(AAChartAnimationType.Bounce)
.title("TITLE")//The chart title
.subtitle("subtitle")//The chart subtitle
.dataLabelEnabled(false) //Enable or disable the data labels. Defaults to false
.tooltipValueSuffix("USD")//the value suffix of the chart tooltip
.categories(["Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"])
.colorsTheme(["#fe117c","#ffc069","#06caf4","#7dffc0"])
.series([
AASeriesElement()
.name("Tokyo")
.data([7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6])
.toDic()!,
AASeriesElement()
.name("New York")
.data([0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5])
.toDic()!,
AASeriesElement()
.name("Berlin")
.data([0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0])
.toDic()!,
AASeriesElement()
.name("London")
.data([3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8])
.toDic()!,])
chart.aa_drawChartWithChartModel(model)
答案 0 :(得分:2)
我通过以下方式解决了该问题:
这会将项目中的引用添加到包中,以便下次在您的命名空间中正确找到它。
答案 1 :(得分:1)