OGeek|极客世界-中国程序员成长平台

标题: ios - 如何为图表的图例添加背景颜色 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:41
标题: ios - 如何为图表的图例添加背景颜色

我正在使用 library在我的应用程序中构建一个很棒的图表。一切正常,但今天我遇到了问题。我想在图表的图例下方添加简单的背景颜色。

我的传奇是这样的:

enter image description here

我想实现这样的目标:

enter image description here

我目前对图表图例部分的实现:

private func prepareLegend() {
    lineChart.legend.drawInside = true
    lineChart.legend.horizontalAlignment = .right
    lineChart.legend.verticalAlignment = .top
    lineChart.legend.orientation = .vertical
    lineChart.legend.formSize = 14.0
    lineChart.legend.yEntrySpace = 6.0
    lineChart.legend.font = UIFont.pmd_robotoRegular(ofSize: 12.0)
    lineChart.legend.textColor = UIColor.pmd_darkGrey

    let upperLegend = LegendEntry()
    upperLegend.label = "Upper Thershold"
    upperLegend.form = .square
    upperLegend.formColor = UIColor.pmd_red

    let lowerLegend = LegendEntry()
    lowerLegend.label = "Lower Thershold"
    lowerLegend.form = .square
    lowerLegend.formColor = UIColor.pmd_red

    lineChart.legend.extraEntries = [upperLegend, lowerLegend]
}

这里有人熟悉这个库并可以帮助我吗?



Best Answer-推荐答案


您可以轻松地在图例类中添加属性 rect 并用颜色填充它。并覆盖 renderLegend(context: CGContext) 您可以在该矩形中填充背景颜色。

关于ios - 如何为图表的图例添加背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44022304/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4