我正在使用图表库(danielgindi / Charts)。
我有一个显示日,周,月和年选项的细分。根据所选内容将显示在图表上。
我有以下代码:
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'未按预期更新。
任何帮助将不胜感激:)
答案 0 :(得分:2)
调用candleChartView.setNeedsDisplay()
将重绘图表并更新文本
答案 1 :(得分:1)
chartView.notifyDataSetChanged()
chartView.legend.resetCustom()