-
Notifications
You must be signed in to change notification settings - Fork 20
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
Custom renderers are not working #56
Comments
I am having a similar issue: public class YAxisRenderer : ChartYAxisRenderer
{
public YAxisRenderer(ChartViewPortHandler viewPortHandler, ChartYAxis yAxis, ChartTransformer transformer) : base(viewPortHandler, yAxis, transformer) { }
public override void RenderLimitLinesWithContext(CGContext context)
{
// breakpoint not getting hit
base.RenderLimitLinesWithContext(context);
// tons of custom line rendering here
}
} Any help on this would be greatly appreciated. |
Unfortunately, there is no good solution here. The issue is with how interop works between Swift and C#: For Objective-C and Java, this all works as you would expect. We have it working well on Android. The problem is when you override a Swift method that starts off as a Swift method. ie. You can override any UIView method (eg Draw in a ChartView) but you cannot override any of the methods of the Renderers as the base methods start off in Swift. The Renderer property in the Chart is a Swift object so you have to derive from the Swift class to be able to set the property. If the property was defined as an interface type (eg ValueFormatters) then you can just implement the interface, set the property and have all the code in C#. This works fine. But for Renderers, you need to derive from the Renderer, add a C# method to do all the drawing you need and then call that method from your Draw method that you override in the Chart. You also need to use the enable property of that feature (in your case limit lines) so the base implementation does not also draw limit limes. |
When I create a custom renderer and set the chart property to use the custom renderer, the overridden methods in the custom renderer are not being called. The result just looks like the default renderer is still being used and its not calling into the overridden methods. This is the case for the XAxisRenderer, YAxisRenderer (lazy vars) and the chart renderer (normal var). I can subclass the chartview and override its methods and that works, both when the chartview is created in code or using interface builder. I've attached a sample project with these issues. Is there an easy fix or workaround, or is something else needed to make the assignment work? This works well in Xamarin.Android.
ioscharts_overrides.zip
`
`
The text was updated successfully, but these errors were encountered: