gpt4 book ai didi

ios - 如何使用核心图为图例设置不同的文本颜色

转载 作者:行者123 更新时间:2023-11-30 12:48:54 25 4
gpt4 key购买 nike

我正在使用核心图来绘制图表。我的问题是我想根据线条颜色设置图例文本颜色。我在一张图中有四个散点图,每个散点图都有不同的线条颜色。

在图例中,它将正确显示线条颜色,但我想根据每个散点图标题的线条颜色更改文本颜色。我为图例编写了以下代码。

newGraph.legend = CPTLegend(graph: newGraph)
newGraph.legend?.numberOfRows = UInt(2.0)
let dataSourceLabelStyle = CPTMutableTextStyle()
dataSourceLabelStyle.color = CPTColor.white()
newGraph.legend?.textStyle = dataSourceLabelStyle
newGraph.legend?.fill = CPTFill(color: CPTColor.init(componentRed: 50/244, green: 43/244, blue: 87/244, alpha: 1.0))
newGraph.legend?.cornerRadius = 5.0
newGraph.legendDisplacement = CGPoint.init(x: -50, y: 210)
let fadeInAnimation = CABasicAnimation(keyPath: "opacity")
fadeInAnimation.duration = 1.0
fadeInAnimation.isRemovedOnCompletion = false
fadeInAnimation.fillMode = kCAFillModeForwards
fadeInAnimation.toValue = 1.0
dataSourceLinePlot.add(fadeInAnimation, forKey: "animateOpacity")
self.scatterGraph = newGraph

从上面的代码可以看出,图例只能采用一种样式,即 newGraph.legend?.textStyle = dataSourceLabelStyle 因此图例中的所有文本都是白色的。

我想根据线条颜色更改图例文本颜色。

任何人都可以帮我解决这个问题吗?

最佳答案

对于包括散点图在内的大多数绘图类型,请将 attributedTitle 设置为具有所需颜色属性的 NSAttributedString。饼图和条形图具有数据源方法,可为每个数据索引提供属性图例标题。

关于ios - 如何使用核心图为图例设置不同的文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41256886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com