2016-07-25 42 views
1

我正在嘗試開發一個簡單的活動圖表。我的意圖是讓圖表中選定的特定欄顯示另一個視圖。主圖表的目的是作爲儀表板樣式,因此爲了深入發現或詳細信息,用戶可以選擇特定的欄來了解更多信息[應該會顯示特定的視圖控制器]。如何通過使用IOSChart的ChartValueSelected顯示另一個ViewController?

func chartValueSelected(chartView: ChartViewBase, entry: ChartDataEntry, dataSetIndex: Int, highlight: ChartHighlight) { 
    println("\(entry.value) in \(months[entry.xIndex])") 

    var storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 

    var vc: NewViewController = storyboard.instantiateViewControllerWithIdentifier("newView") as! NewViewController 

    self.presentViewController(vc, animated: true, completion: nil) 

}  

對於每個月都會有自己的看法,因爲我打算在該特定視圖中放置另一個圖表。據我所知,每個月都會有特定的功能命令;所以我想在函數內部使用IF ELSE,但我完全不知道如何開始。我還不確定是否還有另一種簡單的方法來實現這一點,因爲我還在學習。

我正在按照教程使用iOSCharts http://www.appcoda.com/ios-charts-api-tutorial/ 和自定義顯示視圖控制器從https://www.youtube.com/watch?v=0I4HX6NDDak

回答

0
func chartValueSelected(chartView: ChartViewBase, entry: ChartDataEntry, dataSetIndex: Int, highlight: ChartHighlight) { 
    print("\(entry.value) in \(months[entry.xIndex])") 

    let strSelectedMonth : String = months[entry.xIndex] as! String 

    if strSelectedMonth == "April" 
    { 
     print(strSelectedMonth) 

     // Now push another view controller and display bar chart for April month 
    }  
} 

不要忘記實現barChartView.delegate = selfChartViewDelegate

該解決方案是用於表示不同的視圖控制器和圖表迎合數據年,月,日,小時盡其用。

+0

非常感謝你的回答! :)現在我可以推動更具體的觀點。我只使用預定的數據集處理簡單的活動圖表。我將在未來使用動態數據集。 – Sturnment

+0

好,有一個快樂的編碼。 – Hasya

+0

什麼是swift3?數據集索引總是0 – Sofeda

相關問題