如何缩小 CPTXYGraph 和 CPTGraphHostingView 之间的差距?
How to reduce gap between CPTXYGraph and CPTGraphHostingView?
我在图形 CPTXYGraph 中创建了一个散点图,然后将此图形传递给 CPTGraphHostingView,代码如下:
func makeGraphHostingView() -> CPTGraphHostingView {
let hostingView = CPTGraphHostingView()
let graph = CPTXYGraph()
graph.axisSet!.isHidden = true
graph.plotAreaFrame!.paddingTop = 0.0
graph.plotAreaFrame!.paddingRight = 0.0
graph.plotAreaFrame!.paddingBottom = 0.0
graph.plotAreaFrame!.paddingLeft = 0.0
hostingView.hostedGraph = graph
let lineStyle = CPTMutableLineStyle()
lineStyle.lineColor = CPTColor.white()
lineStyle.lineWidth = 3.0
let xAxisMin = 0.0
let xAxisMax = 100.0
let yAxisMin = 0.0
let yAxisMax = 100.0
let plotSpace = graph.defaultPlotSpace as! CPTXYPlotSpace
plotSpace.xRange = CPTPlotRange(locationDecimal: Decimal(xAxisMin), lengthDecimal: Decimal(xAxisMax - xAxisMin))
plotSpace.yRange = CPTPlotRange(locationDecimal: Decimal(yAxisMin), lengthDecimal: Decimal(yAxisMax - yAxisMin))
let plot = CPTScatterPlot()
plot.dataSource = self
plot.dataLineStyle = lineStyle
let areaFillColor = UIColor.white.withAlphaComponent(0.05)
let fill = CPTFill(color: CPTColor(cgColor: areaFillColor.cgColor))
plot.areaFill = fill
plot.areaBaseValue = NSNumber(0.0)
graph.add(plot)
return hostingView
}
hostingView 固定到 superview 的前导、尾随、顶部和底部锚点,常数为 0.0(观看图片 1):
我希望将图形调整到与 hostingView 相同的范围,但我不知道该怎么做,图形填充在这里对我没有任何帮助。有什么想法吗?
您需要将 graph
上的填充设置为。
graph.paddingTop = 0.0
graph.paddingRight = 0.0
graph.paddingBottom = 0.0
graph.paddingLeft = 0.0
我在图形 CPTXYGraph 中创建了一个散点图,然后将此图形传递给 CPTGraphHostingView,代码如下:
func makeGraphHostingView() -> CPTGraphHostingView {
let hostingView = CPTGraphHostingView()
let graph = CPTXYGraph()
graph.axisSet!.isHidden = true
graph.plotAreaFrame!.paddingTop = 0.0
graph.plotAreaFrame!.paddingRight = 0.0
graph.plotAreaFrame!.paddingBottom = 0.0
graph.plotAreaFrame!.paddingLeft = 0.0
hostingView.hostedGraph = graph
let lineStyle = CPTMutableLineStyle()
lineStyle.lineColor = CPTColor.white()
lineStyle.lineWidth = 3.0
let xAxisMin = 0.0
let xAxisMax = 100.0
let yAxisMin = 0.0
let yAxisMax = 100.0
let plotSpace = graph.defaultPlotSpace as! CPTXYPlotSpace
plotSpace.xRange = CPTPlotRange(locationDecimal: Decimal(xAxisMin), lengthDecimal: Decimal(xAxisMax - xAxisMin))
plotSpace.yRange = CPTPlotRange(locationDecimal: Decimal(yAxisMin), lengthDecimal: Decimal(yAxisMax - yAxisMin))
let plot = CPTScatterPlot()
plot.dataSource = self
plot.dataLineStyle = lineStyle
let areaFillColor = UIColor.white.withAlphaComponent(0.05)
let fill = CPTFill(color: CPTColor(cgColor: areaFillColor.cgColor))
plot.areaFill = fill
plot.areaBaseValue = NSNumber(0.0)
graph.add(plot)
return hostingView
}
hostingView 固定到 superview 的前导、尾随、顶部和底部锚点,常数为 0.0(观看图片 1):
我希望将图形调整到与 hostingView 相同的范围,但我不知道该怎么做,图形填充在这里对我没有任何帮助。有什么想法吗?
您需要将 graph
上的填充设置为。
graph.paddingTop = 0.0
graph.paddingRight = 0.0
graph.paddingBottom = 0.0
graph.paddingLeft = 0.0