Coreplot传说中的标题,国家标签,并在该行下迅速

问题描述:

如何显示这样的coreplot图例?Coreplot传说中的标题,国家标签,并在该行下迅速

国家标志,根据该线(图中的相似)

enter image description here FUNC configureLegend()国名{ 后卫让图形= hostView.hostedGraph其他{}回报

let legend = CPTLegend(graph: graph) 
    graph.legend = legend 
    graph.legendAnchor = .topLeft 
    graph.legendDisplacement = CGPoint(x: 50.0, y: -2.0) 
    legend.fill = CPTFill(color: CPTColor.clear()) 
    legend.swatchSize = CGSize(width: 10.0, height: 10.0) 
    legend.numberOfRows = 1 
    legend.entryPaddingBottom = 12 
    let titleStyle = CPTMutableTextStyle() 
    titleStyle.color = CPTColor.black() 
    titleStyle.fontSize = 6.0 
    titleStyle.fontName = Font.NissanPro_Bold 
    legend.textStyle = titleStyle 
    legend.delegate = self 
} 
public func legend(_ legend: CPTLegend, shouldDrawSwatchAt idx: UInt, for plot: CPTPlot, in rect: CGRect, in context: CGContext) -> Bool{ 
    return false 
} 

如果您可以使用表情符号绘制标志,做到这一点。在标题文本中插入换行符(\n)以将文本放置在标志下。

如果您需要为标志使用自定义图形,请使用图例delegate并实施-legend:shouldDrawSwatchAtIndex:forPlot:inRect:inContext:委托方法。将标志绘制到样例矩形内的给定图形上下文中,并返回NO以告诉图例您已处理所需的绘图。

将文本放在图形下方,放大样本大小并将两者都绘制到样本矩形中。

+0

感谢您的回复Eric。但是,上述实现做了什么。该线条向下移动(而不是中心),而不是在标志和文字下 – Marios

+0

您不必使用图例。使用Core Plot边框图层(标志图形可以是其中一个图层的“填充”)和文本图层来构建您想要的视图。将此图层层次结构作为注释附加到图形上。 –