Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to get a custom legend #710

Closed
wzio opened this issue Jan 26, 2016 · 4 comments
Closed

how to get a custom legend #710

wzio opened this issue Jan 26, 2016 · 4 comments

Comments

@wzio
Copy link

wzio commented Jan 26, 2016

I subclass the ChartLegendRenderer , but how to use it. I notice that the legendRenderer is readonly

/// \returns  the Legend object of the chart. This method can be used to get an instance of the legend in order to customize the automatically generated Legend.
@property (nonatomic, readonly, strong) ChartLegend * __nonnull legend;

/// \returns  the renderer object responsible for rendering / drawing the Legend.
@property (nonatomic, readonly, strong) ChartLegendRenderer * __null_unspecified legendRenderer;
@liuxuan30
Copy link
Member

@danielgindi is this another class you want to make public?
@stardust139 the bottom line is, you could subclass a chart view, and pass your legend renderer in initialize()

@wzio
Copy link
Author

wzio commented Jan 26, 2016

yeah, I found that . but a little precious to this

@vojto
Copy link

vojto commented Mar 24, 2017

_legendRenderer is set to internal, so you can't replace it from a subclass...

Here's a KVC solution for replacing the legend with custom legend:

public class CustomCombinedChartView: CombinedChartView {
    override public func initialize() {
        super.initialize()
        
        let customLegend = CustomLegendRenderer(viewPortHandler: viewPortHandler, legend: self.legend)
        self.setValue(customLegend, forKey: "_legendRenderer")
    }
}

@wzio
Copy link
Author

wzio commented Feb 28, 2018

_legendRenderer is not a @objc property in Swift 4.0, so KVC is not work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants