graphEvolution + dynamic metrics based upon 'Custom variables'

Hi, I’m building a plugin for a client. They want to visualise how many visits are from coming from which office and the role they have. The roles are defined somewhere else and pushed to Piwik with the ‘Custom variables’ plugin. I have managed to collect the correct data but the Evolution graph is not displaying the correct metrics. It is still falling back to the defaults (Visits, Actions, Unique Visitors and Users). When printing the content of the DataTable the data I want to visualise is correct.

Piwik\DataTable Object
(
    [rows:protected] => Array
        (
            [0] => Piwik\DataTable\Row Object
                (
                    [maxVisitsSummed] => 0
                    [metadata:Piwik\DataTable\Row:private] => Array
                        (
                        )

                    [isSubtableLoaded:Piwik\DataTable\Row:private] => 
                    [subtableId] => 
                    [storage:ArrayObject:private] => Array
                        (
                            [nb_visits] => 464
                            [marketing] => 0
                        )

                )

            [1] => Piwik\DataTable\Row Object
                (
                    [maxVisitsSummed] => 0
                    [metadata:Piwik\DataTable\Row:private] => Array
                        (
                        )

                    [isSubtableLoaded:Piwik\DataTable\Row:private] => 
                    [subtableId] => 
                    [storage:ArrayObject:private] => Array
                        (
                            [nb_visits] => 464
                            [marketing] => 0
                        )

                )

        )

    [currentId:protected] => 3
    [depthLevel:protected] => 0
    [indexNotUpToDate:protected] => 1
    [rebuildIndexContinuously:protected] => 
    [tableSortedBy:protected] => 
    [queuedFilters:protected] => Array
        (
        )

    [disabledFilters:protected] => Array
        (
        )

    [rowsCountBeforeLimitFilter:protected] => 0
    [enableRecursiveSort:protected] => 
    [enableRecursiveFilters:protected] => 
    [rowsIndexByLabel:protected] => Array
        (
        )

    [summaryRow:protected] => 
    [metadata:Piwik\DataTable:private] => Array
        (
            [column_aggregation_ops] => Array
                (
                    [nb_visits] => skip
                    [marketing] => skip
                )

        )

    [maximumAllowedRows:protected] => 0
)

The above data dump shows the input. This image: shows the graph.

In my Report I override ‘configureView’:

public function configureView(ViewDataTable $view)
{
    if (!empty($this->dimension)) {
        $view->config->addTranslations(array('label' => $this->dimension->getName()));
    }

    $view->config->show_search = false;
    //$view->requestConfig->filter_sort_column = 'nb_visits';
    // $view->requestConfig->filter_limit = 10';

    $view->config->columns_to_display = $this->metrics;
}

What triggers the graph to use my Metrics?

I find the trick; set $view->config->columns_to_display inside the controller and the metrics are set.