嗨,我想在每个这样的标签上方添加一行
我尝试过
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
这可以使短线,但是如何删除没有标签的短线呢?
谢谢
答案 0 :(得分:0)
我以此解决了我的问题
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()
}