2

I am working with library to build a great charts in my app. Everything works good but today I encountered a problem. I want to add simply background color below chart`s legend.

My legend looks like this:

enter image description here

I want to achieve something like this:

enter image description here

My current implementation of chart`s legend part:

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]
}

Anybody here is familiar with this library and can help me?

Tj3n
  • 9,837
  • 2
  • 24
  • 35
Kamil Harasimowicz
  • 4,684
  • 5
  • 32
  • 58

1 Answers1

0

you can easily add a property rect in legend class and fill it with color. And override renderLegend(context: CGContext) where you can fill the background color in that rect.

Wingzero
  • 9,644
  • 10
  • 39
  • 80
  • How to set custom `Legend` class to `LineChartView` instance? I can't see `renderLegend(context: CGContext)` method in `Legend` class but I found it in `LegendRenderer`. I don't know still how to count properly rect. Could you paste example code or expand your answer? – Kamil Harasimowicz Jun 07 '17 at 09:14
  • @wingzero can you help me out in how to achieve adding legend background – chetan panchal Feb 27 '19 at 06:41