ios - 如何用字符串绘制 2 个带 x 轴的折线图
<p><p>我是编程新手,我正在尝试用 2 条线制作图表。并在图表顶部枚举我拥有的字符串数组(在我的情况下为 DD-MM)。我设法只画了一条线:</p>
<pre><code> let testArrayTemp =
let testArrayFeel =
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: , valuesTempChart: , valuesFeelChart: )
{
var tempEntries: = []
for i in 0..<dataPoints.count
{
let dataEntry = ChartDataEntry(x: Double(i), y: valuesTempChart)
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 = ()
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!"
}
</code></pre>
<p>但它看起来像这样:<a href="/image/LkSn0.png" rel="noreferrer noopener nofollow"><img src="/image/LkSn0.png" alt="Graph"/></a> </p>
<p>我需要做什么才能在顶部显示字符串数组(带有天数)并再添加一行。请任何想法,或者可能是指向 SWIFT 3 中的教程而不是其他版本的链接,因为他们进行了很多更改,并且 swift 2 教程中没有任何内容可以正常工作,但是自动更正做得更糟。
我希望它看起来像这样:(但用 2 行和几天而不是几个月)</p>
<p> <a href="/image/O0fUS.png" rel="noreferrer noopener nofollow"><img src="/image/O0fUS.png" alt="enter image description here"/></a> </p>
<p>感谢您的任何建议</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您需要对感觉数据重复该过程。引用下面的代码。</p>
<pre><code>func setChart(dataPoints: , valuesTempChart: ,valuesFeelChart: )
{
var tempEntries: = []
var feelEntries: = []
for i in 0..<dataPoints.count
{
let dataEntryOne = ChartDataEntry(x: Double(i), y: valuesTempChart)
let dataEntryTwo = ChartDataEntry(x: Double(i), y: valuesFeelChart)
tempEntries.append(dataEntryOne)
feelEntries.append(dataEntryTwo)
}
let lineChartDataSetTemp = LineChartDataSet(values: tempEntries, label: "Temperature")
let lineChartDataSetFeels = LineChartDataSet(values: feelEntries, label: "Feels")
var dataSets = ()
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!"
</code></pre>
<p>}</p>
<p>希望这会有所帮助!</p></p>
<p style="font-size: 20px;">关于ios - 如何用字符串绘制 2 个带 x 轴的折线图,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/40383318/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/40383318/
</a>
</p>
页:
[1]