菜鸟教程小白 发表于 2022-12-11 19:41:25

ios - 如何为图表的图例添加背景颜色


                                            <p><p>我正在使用 <a href="https://github.com/danielgindi/Charts" rel="noreferrer noopener nofollow">library</a>在我的应用程序中构建一个很棒的图表。一切正常,但今天我遇到了问题。我想在图表的图例下方添加简单的背景颜色。</p>

<p>我的传奇是这样的:</p>

<p> <a href="/image/QM2IY.png" rel="noreferrer noopener nofollow"><img src="/image/QM2IY.png" alt="enter image description here"/></a> </p>

<p>我想实现这样的目标:</p>

<p> <a href="/image/cWDjO.png" rel="noreferrer noopener nofollow"><img src="/image/cWDjO.png" alt="enter image description here"/></a> </p>

<p>我目前对图表图例部分的实现:</p>

<pre><code>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 = &#34;Upper Thershold&#34;
    upperLegend.form = .square
    upperLegend.formColor = UIColor.pmd_red

    let lowerLegend = LegendEntry()
    lowerLegend.label = &#34;Lower Thershold&#34;
    lowerLegend.form = .square
    lowerLegend.formColor = UIColor.pmd_red

    lineChart.legend.extraEntries =
}
</code></pre>

<p>这里有人熟悉这个库并可以帮助我吗?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您可以轻松地在图例类中添加属性 rect 并用颜色填充它。并覆盖 <code>renderLegend(context: CGContext)</code> 您可以在该矩形中填充背景颜色。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何为图表的图例添加背景颜色,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/44022304/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/44022304/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何为图表的图例添加背景颜色