KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Data column(s) for axis #0 cannot be of type string for data after the Cube process #2762

Open Eugene opened this topic on on Jul 25, 2022 - 8 comments

Eugene commented on Jul 25, 2022

Hi,

I get the error message in the subj.

I have found this recommendation in one of the forum's posts: "Please try to change the metadata of the all columns except for the first one to ["type" => "number"]. The first one should have ["type" => "string"]."

But how to do it for the result of the cube process?

Sebastian Morales commented on Jul 25, 2022

Print out a datastore's meta and data in your report view to see its column names and order:

//MyReport.view.php
print_r($this->dataStore("cubeResult")->meta()["columns"]); // print column meta
print_r($this->dataStore("cubeResult")->data()[0]); // print first data row

Then you know which column to set "type" => "string" to act as label and which ones to set "type" => "number" to act as numeric data using ColumnMeta process:

//MyReport.php
->pipe(new Cube(...))
->pipe(new \koolreport\processes\ColumnMeta(array(
    <column_1> => array(
        "type" => "string"
    ),
    <column_2> => array(
        "type" => "number"
    ),
    ...
)))
Eugene commented on Jul 25, 2022

Hm.... but the names depend on the data and are different all time so I don't know names when I code

Sebastian Morales commented on Jul 25, 2022

The Cube process should automatically set its resulting columns' type correctly. Would you pls post the your chart create code that results in that error?

Eugene commented on Jul 25, 2022
$this->src('DB')
            ->query($query4)
            ->params($q_params)
            ->pipe(new Cube(array(
                'row' => 'date',
                'column' => 'server',
                'sum' => 'averageInvoicePerGuest'
            )))
            ->pipe(new Sort(array(
                'date' => 'asc'
            )))
            ->pipe(new DateTimeFormat(array(
                'date' => array(
                    'from' => 'Y-m-d H:i:s',
                    'to' => 'd/m/Y',
                )
            )))
            ->pipe(new ColumnMeta(array(
                '{{all}}' => array(
                    'label' => 'Total',
                ),
            )))
            ->pipe($this->dataStore('averageInvoicePerGuestByWaiterGraph'));

view file

<?php
        LineChart::create(array(
            'title' => 'Average invoice by waiter',
            'dataSource' =>  $this->dataStore('averageInvoicePerGuestByWaiterGraph'),
            'columns' => array(
                'date',
                'averageInvoicePerGuest' => array(
                    'label' => 'Average Invoice Amount',
                    'type' => 'number',
                ))
        ));
        ?>

Eugene commented on Jul 25, 2022

I think my mistake is that I used the wrong column name but it is a problem My result data is

So I need to plot a graph with data from all columns except the total. And as I said before the names of columns are unknown

Eugene commented on Jul 26, 2022

Finally, I did like this

$columnsArray = array('date');
        foreach ($this->dataStore('averageInvoicePerGuestByWaiterGraph')->meta()['columns'] as $key => $value) {
            if ($key != 'date' and $key != '{{all}}') {
                $columnsArray[$key] = array(
                    'label' => $key,
                    'type' => 'number'
                );
            }
        }
LineChart::create(array(
            'title' => 'Average invoice by waiter',
            'dataSource' => $this->dataStore('averageInvoicePerGuestByWaiterGraph'),
            'columns' => $columnsArray,
        ));

But it looks a bit ugly. Is there any better solution?

Sebastian Morales commented on Jul 26, 2022

You can always remove column "{{all}}" after Cube process and doesn't set "columns" for your chart as the first column after Cube is always the label one:

            // MyReport.php
            ->pipe(new Cube(array(
                ...
            )))
            ->pipe(new \koolreport\processes\RemoveColumn(array(
                "{{all}}"
            )))

            // MyReport.view.php
            LineChart::create(array(
                'title' => 'Average invoice by waiter',
                'dataSource' => $this->dataStore('averageInvoicePerGuestByWaiterGraph')
                //
            ));

Let us know how this works. Tks,

Eugene commented on Jul 26, 2022

Thanks it works

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

None