我正在使用图表库(danielgindi /图表)。
我有一个显示“日”,“周”,“月”和“年”选项的部分。根据选择的内容,将在图表上显示。
我有以下代码:
var highestValue : Double = 0.0
@IBAction func segmentChanged(sender: AnyObject) {
switch durationSegment.selectedSegmentIndex
{
case 0:
segmentSelected = "Day"
highestValue = 8.0
case 1:
segmentSelected = "Week"
highestValue = 10.0
case 2:
segmentSelected = "Month"
highestValue = 12.0
case 3:
segmentSelected = "Year"
highestValue = 14.0
default:
break;
}
print("segment selected = \(segmentSelected)")
displayDurationLabel(segmentSelected, providedStartDate : NSDate())
}
func setChart(xValues: [String], valuesCandleChart: [Double], durationToBeDisplayed: String) {
chartView.descriptionText = ""
print("within setChart, durationToBeDisplayed = \(durationToBeDisplayed)")
chartView.noDataText = "No spends logged for \(durationToBeDisplayed)"
chartView.leftAxis.customAxisMax = highestValue
}
最初调用ViewController时,它使用segmentSelected =“Month”,但是当我更改细分时,图表会显示正确的消息,例如“Day”,打印显示正确的输出,但是“.noDataText”未按预期更新。
任何帮助,将不胜感激 :)
最佳答案
调用candleChartView.setNeedsDisplay()
将重绘图表并更新文本