问题描述
我尝试过
class XAxisRendererWithTicks: XAxisRenderer {
override func drawLabel(context: CGContext,formattedLabel: String,x: CGFloat,y: CGFloat,attributes: [NSAttributedString.Key: Any],constrainedToSize: CGSize,anchor: CGPoint,angleradians: CGFloat) {
super.drawLabel(context: context,formattedLabel: formattedLabel,x: x,y: y,attributes: attributes,constrainedToSize: constrainedToSize,anchor: anchor,angleradians: angleradians)
context.beginPath()
context.move(to: CGPoint(x: x,y: y))
context.addLine(to: CGPoint(x: x,y: self.viewPortHandler.contentBottom))
context.strokePath()
}}
和
let customXAxisRenderer = XAxisRendererWithTicks(viewPortHandler: lineChartView.viewPortHandler,xAxis: lineChartView.xAxis,transformer: lineChartView.getTransformer(forAxis: .left))
lineChartView.xAxisRenderer = customXAxisRenderer
谢谢
解决方法
我以此解决了我的问题
override func drawLabel(context: CGContext,formattedLabel: String,x: CGFloat,y: CGFloat,attributes: [NSAttributedString.Key: Any],constrainedToSize: CGSize,anchor: CGPoint,angleRadians: CGFloat) {
super.drawLabel(context: context,formattedLabel: formattedLabel,x: x,y: y,attributes: attributes,constrainedToSize: constrainedToSize,anchor: anchor,angleRadians: angleRadians)
if(formattedLabel == ""){
return
}
context.beginPath()
context.move(to: CGPoint(x: x,y: y))
context.addLine(to: CGPoint(x: x,y: self.viewPortHandler.contentBottom))
context.strokePath()
}