このコードで折れ線グラフを作成しようとしています。私は別のものを試して何時間も使っていたコードの大部分をレイアウトしました。クラスで :迅速な折れ線グラフ3
PendingViewController: UIViewController, ChartViewDelegate
アウトレット:
@IBOutlet weak var lineChartView: LineChartView!
ViewDidLoad:
let months = ["Jan" , "Feb", "Mar", "Apr", "May", "June", "July", "August", "Sept", "Oct", "Nov", "Dec"]
let dollars1 = [1453.0,2352,5431,1442,5451,6486,1173,5678,9234,1345,9411,2212]
self.lineChartView.delegate = self
// 2
self.lineChartView.descriptionText = "Tap node for details"
// 3
self.lineChartView.chartDescription?.textColor = UIColor.white
self.lineChartView.gridBackgroundColor = UIColor.darkGray
// 4
self.lineChartView.noDataText = "No data provided"
// 5
setChartData(months: months)
のFunc:
func setChartData(months : [String]) {
// 1 - creating an array of data entries
var yVals1 : [ChartDataEntry] = [ChartDataEntry]()
for i in 0 ..< months.count {
yVals1.append(ChartDataEntry(x: dollars1[i], y: Double(i)))
}
// 2 - create a data set with our array
let set1: LineChartDataSet = LineChartDataSet(values: yVals1, label: "First Set")
set1.axisDependency = .left // Line will correlate with left axis values
set1.setColor(UIColor.red.withAlphaComponent(0.5)) // our line's opacity is 50%
set1.setCircleColor(UIColor.red) // our circle will be dark red
set1.lineWidth = 2.0
set1.circleRadius = 6.0 // the radius of the node circle
set1.fillAlpha = 65/255.0
set1.fillColor = UIColor.red
set1.highlightColor = UIColor.white
set1.drawCircleHoleEnabled = true
//3 - create an array to store our LineChartDataSets
var dataSets : [LineChartDataSet] = [LineChartDataSet]()
dataSets.append(set1)
//4 - pass our months in for our x-axis label value along with our dataSets
let data: LineChartData = LineChartData(xVals: months, dataSets: dataSets)
data.setValueTextColor(UIColor.white)
//5 - finally set our data
self.lineChartView.data = data
}
このエラーを受けたイム:
Cannot invoke initializer for typel 'LineChartData' with an argument list of type '(xVals: [String], dataSets: [LineChartDataSet])'
は、
0123をありがとうございましたデニス
誰かが私を助けることはできますか? – Denis
ライブラリのリンクを追加できますか? –
ポッド 'チャート'?それはあなたが意味することですか? – Denis