-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
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.
`
public class SimpleBarChart : BarChartView
{
public SimpleBarChart() { }
public SimpleBarChart(IntPtr handle) : base(handle) { }
public void Configure()
{
// Custom XAxisRenderer not working
XAxisRenderer = new SimpleXAxisRenderer(
ViewPortHandler,
XAxis,
GetTransformerForAxis(AxisDependency.Left));
// Custom chart renderer not working
Renderer = new SimpleBarChartRenderer(this, ChartAnimator, ViewPortHandler);
var points = new BarChartDataEntry[]
{
new BarChartDataEntry(0, 1),
new BarChartDataEntry(1, 2),
new BarChartDataEntry(2, 4),
};
var dataset = new BarChartDataSet(points, "series 1");
var barData = new BarChartData();
barData.AddDataSet(dataset);
Data = barData;
}
}
public class SimpleXAxisRenderer : ChartXAxisRenderer
{
public SimpleXAxisRenderer(ChartViewPortHandler viewportHandler, ChartXAxis xAxis, ChartTransformer transformer)
: base(viewportHandler, xAxis, transformer)
{
}
public override void ComputeAxisValuesWithMin(double min, double max)
{
// place breakpoint here: never gets called
Trace.Log();
base.ComputeAxisValuesWithMin(min, max);
}
}
public class SimpleBarChartRenderer : BarChartRenderer
{
public SimpleBarChartRenderer(IBarChartDataProvider dataProvider, ChartAnimator animator, ChartViewPortHandler viewportHandler)
: base(dataProvider, animator, viewportHandler)
{
}
public override void DrawDataWithContext(CGContext context)
{
// place breakpoint here: never gets called
Trace.Log();
base.DrawDataWithContext(context);
}
public override void DrawExtrasWithContext(CGContext context)
{
// place breakpoint here: never gets called
Trace.Log();
base.DrawExtrasWithContext(context);
}
}
`
Metadata
Metadata
Assignees
Labels
No labels