.noDataText 未在图表内更新。 Swift 2
.noDataText not updating within Chart. Swift 2
我正在使用图表库 (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”未按预期更新。
任何帮助将不胜感激:)
调用candleChartView.setNeedsDisplay()
将重绘图表并更新文本
- 在 setChart 函数中,最后调用:
chartView.notifyDataSetChanged()
- 调用 setChart 函数后立即调用:
chartView.legend.resetCustom()
我正在使用图表库 (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”未按预期更新。
任何帮助将不胜感激:)
调用candleChartView.setNeedsDisplay()
将重绘图表并更新文本
- 在 setChart 函数中,最后调用:
chartView.notifyDataSetChanged()
- 调用 setChart 函数后立即调用:
chartView.legend.resetCustom()