I'm trying to set the range of my NSDateTimeAxis
in ShinobiChart, but something goes wrong, my code looks like this:
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")
}
}
I know the dates I use exist on my xAxis, but it still won't let me change the range. What is the correct way to do this?
Any suggestions would be appreciated.
EDIT:
I've also tried it this way, but it gives me the error saying:
Cannot assign to the result of this expression.
The xAxis is not declared using let
so this remains a mystery to me.
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