问题描述
如何这样显示核心图例?
How to display the coreplot legend like this?
国家标志,该行下的国家名称(如图所示)
country flag,country name under that line(resembled in the graph)
func configureLegend(){
保护图= hostView.hostedGraph其他{返回}
func configureLegend() { guard let graph = hostView.hostedGraph else { return }
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
)以将文本放置在标志下。
If you can draw the flags using emoji, do that. Insert a newline (\n
) character in the title text to position the text under the flag.
如果您需要为标志使用自定义图形,使用图例 delegate
并实现委托方法。将标记绘制到色板矩形内的给定图形上下文中,并返回 NO
来告诉图例您已经完成了所需的绘制。
If you need to use custom graphics for the flags, use a legend delegate
and implement the -legend:shouldDrawSwatchAtIndex:forPlot:inRect:inContext:
delegate method. Draw the flag into the given graphics context inside the swatch rectangle and return NO
to tell the legend that you took care of the required drawing.
要将文本放在图形下,请放大色板大小,然后将两者都绘制到色板矩形中。
To put the text under the graphic, enlarge the swatch size and draw both into the swatch rectangle.
这篇关于Coreplot图例,带标题,国家/地区标签,并在该行下迅速的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!