我正在尝试NSDateTimeAxis
在 ShinobiChart 中设置我的范围,但是出了点问题,我的代码如下所示:
func segmentedControlTapped(sc:UISegmentedControl){
let toDateString:String = "2015-01-05"
let dateFormatter = NSDateFormatter()
dateFormatter.formatterBehavior = NSDateFormatterBehavior.Behavior10_4
dateFormatter.dateFormat = "yyyy-MM-dd"
dateFormatter.calendar = NSCalendar(calendarIdentifier: NSGregorianCalendar)
dateFormatter.timeZone = NSTimeZone(forSecondsFromGMT: 0)
let toDate = dateFormatter.dateFromString(toDateString)
switch (sc.selectedSegmentIndex){
case 0:
println("10 years")
let fromDateString:String = "2005-01-03"
let fromDate = dateFormatter.dateFromString(fromDateString)
self.xAxis.setRangeWithMinimum(fromDate, andMaximum: toDate)
case 1:
println("5 years")
let fromDate:String = "2010-01-05"
let d = dateFormatter.dateFromString(fromDate)
self.xAxis.setRangeWithMinimum(fromDate, andMaximum: toDate)
case 2:
println("3 years")
let fromDate:String = "2012-01-05"
let d = dateFormatter.dateFromString(fromDate)
self.xAxis.setRangeWithMinimum(fromDate, andMaximum: toDate)
case 3:
println("1 year")
let fromDate:String = "2014-01-05"
let d = dateFormatter.dateFromString(fromDate)
self.xAxis.setRangeWithMinimum(fromDate, andMaximum: toDate)
default:
println("something went terribly wrong")
}
}
我知道我使用的日期存在于我的 xAxis 上,但它仍然不允许我更改范围。这样做的正确方法是什么?
任何建议,将不胜感激。
编辑:
我也尝试过这种方式,但它给了我错误消息:
无法分配给此表达式的结果。
xAxis 没有被声明为使用let
,所以这对我来说仍然是一个谜。
case 0:
println("10 years")
let fromDateString:String = "2005-01-03"
let fromDate = dateFormatter.dateFromString(fromDateString)
var dateRange = SChartDateRange(dateMinimum: fromDate, andDateMaximum: toDate)
let range = SChartDateRange(dateMinimum: fromDate, andDateMaximum: toDate)
self.xAxis.axisRange.minimum = range.minimum
self.xAxis.axisRange.maximum = range.maximum