【发布时间】:2016-10-30 09:48:05
【问题描述】:
我正在使用散点图在 x 轴上绘制线条和自定义标签。我希望一些线完全从 y 轴开始,一些线从自定义标签位置开始。PFA 图像。
控制线应该从 y 轴开始,应该一直到“Sat”,数据线应该从“Sun”开始,应该画到“Sat”。 任何人都可以帮助我如何实现这一目标
编辑 1:- 正如 Eric 所建议的,我尝试为控制线和数据线使用 2 条记录,对于 Plot x,我返回 x 轴的刻度位置数组,对于 plot y,我返回图形的 y 值。通过这样做,控制线是正确的,但数据线总是从零开始。 PFA附图
这是我正在编写的用于在 x 轴上创建标签的代码
if(self.axisArray.count == 7) {
tickLocation = [1, 2, 3, 4, 5, 6, 7]
}
else {
tickLocation = [1, 2, 3, 4, 5, 6, 7, 8]
}
var xLocations = [NSNumber]()
var labelLocation: Int = -1
for number in tickLocation {
labelLocation += 1
let newLabel = CPTAxisLabel.init(text: axisArray[labelLocation] as? String, textStyle: axisLabelStyle)
newLabel.tickLocation = number as! NSNumber
newLabel.offset = x.labelOffset + x.majorTickLength
xLocations.append(NSNumber(value: number as! Double))
customLabel.append(newLabel)
}
x.labelingPolicy = CPTAxisLabelingPolicy.none
x.axisLabels = Set(customLabel)
x.majorTickLocations = Set(xLocations)
下面的数据源是代码
func numberOfRecords(for plot: CPTPlot) -> UInt
{
if(plot.identifier as! String == BloodGlucoseGraphView.kUpperControlLineIdentifier) {
return UInt(2)
}
else if(plot.identifier as! String == BloodGlucoseGraphView.kLowerControlLineIdentifier) {
return UInt(2)
}
else if(plot.identifier as! String == BloodGlucoseGraphView.kFirstGraphIdentfifier) {
return UInt(self.beforeMealData.count)
}
else if(plot.identifier as! String == BloodGlucoseGraphView.kSecondGraphIdentfifier) {
return UInt(self.afterMealData.count)
}
else {
return UInt(0)
}
}
func number(for plot: CPTPlot, field: UInt, record: UInt) -> Any?
{
let plotField = CPTScatterPlotField(rawValue: Int(field))
if(plot.identifier as! String == BloodGlucoseGraphView.kUpperControlLineIdentifier) {
if(plotField == .X) {
return Int(record)
}
else if(plotField == .Y) {
return 6
}
}
else if(plot.identifier as! String == BloodGlucoseGraphView.kLowerControlLineIdentifier) {
if(plotField == .X) {
return Int(record)
}
else if(plotField == .Y) {
return 5.2
}
}
if(plot.identifier as! String == BloodGlucoseGraphView.kFirstGraphIdentfifier) {
if(plotField == .X) {
return self.tickLocation[Int(record)] as! NSNumber
}
else if(plotField == .Y) {
return self.afterMealData[Int(record)]
}
}
else if(plot.identifier as! String == BloodGlucoseGraphView.kSecondGraphIdentfifier) {
if(plotField == .X) {
return self.tickLocation[Int(record)] as! NSNumber
}
else if(plotField == .Y) {
return self.beforeMealData[Int(record)]
}
}
return nil
}
但是数据线也是从零开始,而不是从“太阳”开始。 @Eric 你能在这方面帮助我吗
【问题讨论】: