Skip to content

Custom renderers are not working #56

@shannonpahl

Description

@shannonpahl

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

`

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions