2016-11-02 4 views
2

저는 프로그래밍이 쉽고 빠르며 2 줄짜리 차트를 만들려고합니다. 그리고 차트 상단에 내가 가진 문자열 배열을 열거합니다 (필자의 경우 DD-MM). 난 그냥 한 줄과 같이 그릴 관리 :문자열로 xAxis를 사용하여 2 개의 LineChart를 그리는 방법

let testArrayTemp = [22.43, 14.86,20.63, 17.08,23.68,14.12,11.09,13.89, 15.0, 9.86, 7.71,10.0,11.94, 8.68, 8.91,6.81, 9.03,8.89, 9.7, 9.26, 9.43,10.22, 9.04,8.04, 7.56,10.44, 7.22, 13.67,9.44, 7.67, 5.99] 
    let testArrayFeel = [20.43, 13.86,10.63, 15.08,22.68,11.12,10.09,15.89, 13.0, 6.86, 5.71,11.0,10.94, 7.68, 6.91,5.81, 3.03,5.89, 7.7, 8.26, 8.43, 11.22, 6.04,7.04, 6.56,11.44, 6.22, 12.67,10.44, 5.67, 4.99] 
    let testDayArray = ["Oct 2, 2016", "Oct 3, 2016", "Oct 4, 2016", "Oct 5, 2016", "Oct 6, 2016", "Oct 7, 2016", "Oct 8, 2016", "Oct 9, 2016", "Oct 10, 2016", "Oct 11, 2016", "Oct 12, 2016", "Oct 13, 2016", "Oct 14, 2016", "Oct 15, 2016", "Oct 16, 2016", "Oct 17, 2016", "Oct 18, 2016", "Oct 19, 2016", "Oct 20, 2016", "Oct 21, 2016", "Oct 22, 2016", "Oct 23, 2016", "Oct 24, 2016", "Oct 25, 2016", "Oct 26, 2016", "Oct 27, 2016", "Oct 28, 2016", "Oct 29, 2016", "Oct 30, 2016", "Oct 31, 2016", "Nov 1, 2016"] 
    setChart(dataPoints: testDayArray, valuesTempChart: testArrayTemp, valuesFeelChart: testArrayFeel) 
} 

//MARK:- Set Chart 
func setChart(dataPoints: [String], valuesTempChart: [Double], valuesFeelChart: [Double]) 
{ 
    var tempEntries: [ChartDataEntry] = [] 

    for i in 0..<dataPoints.count 
    { 
     let dataEntry = ChartDataEntry(x: Double(i), y: valuesTempChart[i]) 
     tempEntries.append(dataEntry) 
    } 

    let lineChartDataSetTemp = LineChartDataSet(values: tempEntries, label: "Temperature") 
    lineChartDataSetTemp.setColor(UIColor.red) 
    // lineChartDataSetTemp.mode = .cubicBezier 
    lineChartDataSetTemp.drawCirclesEnabled = true 
    lineChartDataSetTemp.lineWidth = 2.0 
    lineChartDataSetTemp.circleRadius = 5.0 
    lineChartDataSetTemp.highlightColor = UIColor.green 
    lineChartDataSetTemp.drawHorizontalHighlightIndicatorEnabled = true 

    var dataSets = [IChartDataSet]() 
    dataSets.append(lineChartDataSetTemp) 
    let lineChartDataTemp = LineChartData(dataSets: dataSets) 
    lineChart.data = lineChartDataTemp 
    lineChart.animate(xAxisDuration: 2.0, yAxisDuration: 2.0) 

    lineChart.noDataText = "There is no provided data from the server. Please check out later!" 
} 

하지만 같은 외모 : 나는 (일에) 상단에있는 문자열 배열을 표시 할하고 필요한 Graph

하나 더 추가 선. 제발, 또는 어쩌면 SWIFT 3 자습서에 대한 링크를 다른 버전이 아니라, 그들은 많은 변화를 일으켰고, 신속한 2 자습서에서 아무것도 작동하지,하지만 autocorrection 더 악화 않습니다. 당신이해야 할 것은이 과정을 반복이다 (그러나 달의 대신에 2 개 라인과 일에)

enter image description here

어떤 제안

답변

2

주셔서 감사합니다 : 나는 이런 식으로 뭔가를보고 싶습니다 느낌 데이터. 아래 코드를 참조하십시오.

func setChart(dataPoints: [String], valuesTempChart: [Double],valuesFeelChart: [Double]) 
{ 
var tempEntries: [ChartDataEntry] = [] 
var feelEntries: [ChartDataEntry] = [] 

for i in 0..<dataPoints.count 
{ 
    let dataEntryOne = ChartDataEntry(x: Double(i), y: valuesTempChart[i]) 
    let dataEntryTwo = ChartDataEntry(x: Double(i), y: valuesFeelChart[i]) 
    tempEntries.append(dataEntryOne) 
    feelEntries.append(dataEntryTwo) 
} 

let lineChartDataSetTemp = LineChartDataSet(values: tempEntries, label: "Temperature") 
let lineChartDataSetFeels = LineChartDataSet(values: feelEntries, label: "Feels") 

var dataSets = [IChartDataSet]() 
dataSets.append(lineChartDataSetTemp) 
dataSets.append(lineChartDataSetFeels) 
let lineChartD = LineChartData(dataSets: dataSets) 
lineChart.data = lineChartD 
lineChart.animate(xAxisDuration: 2.0, yAxisDuration: 2.0) 

lineChart.noDataText = "There is no provided data from the server. Please check out later!" 

}이 도움이

희망!