也许这是一个简单的问题,但我想知道如何在X轴下绘制垂直线,以及在iOS-图表中的X Axis中绘制上标签。(见图,如红线)

更新:我使用的库是这个https://github.com/danielgindi/ios-charts
发布于 2016-02-17 04:17:57
您可以,但您必须重写一些方法,例如,查看x轴渲染器中的drawGridLine()和drawLabels()。
drawGridLine为您提供了关于如何在ios图表中绘制网格线的详细信息,了解它对于编写您自己的自定义非常有帮助。
发布于 2019-04-15 17:42:32
通过重写drawLabel,我成功地绘制了x轴以下的刻度。此函数将标签绘制在x轴以下,因此可以在那里绘制其他东西。例如,我们想要的滴答!
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: self.chartView.viewPortHandler, xAxis: xAxis, transformer: self.chartView.getTransformer(forAxis: .left))
self.chartView.xAxisRenderer = customXAxisRenderer图片:请不要介意颜色,但我认为你明白我的意思。;)

希望这能有所帮助!
发布于 2016-02-17 06:54:17
设置主要的勾点位置和小的勾点位置的轴线,你想要得到的线条,如红色。请尝试使用下面为图形的x轴编写的示例代码.
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x = axisSet.xAxis; //Get the axis of the graph
// x and y axis line color
CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle];
axisLineStyle.lineWidth = 2.0f;
axisLineStyle.lineColor = [CPTColor whiteColor]; //Set color whatever you want
//Text Style for axis title
CPTMutableTextStyle *axisTextStyle = [[CPTMutableTextStyle alloc] init];
axisTextStyle.color = [CPTColor whiteColor]; //Set color whatever you want
// Line color
CPTMutableLineStyle *tickLineStyle = [CPTMutableLineStyle lineStyle];
tickLineStyle.lineColor = [CPTColor whiteColor]; //Set color whatever you want
tickLineStyle.lineWidth = 2.0f;
x.title = @"Title for the axis";
x.titleOffset = 50.0f;
x.axisLineStyle = axisLineStyle; //axis line style
x.titleTextStyle = axisTextStyle; //axis title text style
x.majorTickLineStyle = axisLineStyle; //Major axis tick style which you wanted
x.minorTickLineStyle = axisLineStyle; //Minor axis tick style
x.labelTextStyle = axisTextStyle; //axis label text style
x.labelingPolicy = CPTAxisLabelingPolicyNone; //axis labeling policy
x.tickDirection = CPTSignNegative; //This will set the red lines below the x-axis as displayed in screenshot you have attached.有一个快乐的编码..!
https://stackoverflow.com/questions/35442768
复制相似问题