KoolReport's Forum

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

Trying to replicate Months v Years Cube Report inside Dashboard without much success #2713

Open Wayland Games opened this topic on on Jun 8, 2022 - 2 comments

Wayland Games commented on Jun 8, 2022

Trying to create a report that compares monthly sales by years using an area chart as you have done with SalesMonthsYears.php example.

I've tried replicating that but that doesn't work inside the dashboard.

I've tried passing the data to a dashboard areachart which renders a chart but not with year as the series.

Are there any examples anywhere that show a dashboard areachart with months in the X-Axis, Total in the Y-Axis and Year in the series or any multi series line or area charts within a dashboard context?

Any help gratefully received. Thanks in advance.

Sebastian Morales commented on Jun 9, 2022

In your Dashboard's chart widget class, just add a Cube process in function dataSource() like this:

    protected function dataSource()
        ...
        return 
            ...
            ->process(
                \koolreport\cube\processes\Cube::process([
                    "column" => "year",
                    "row" => "month",
                    "sum" => "sales",
                ])
                ->pipe(...)
            )
            ; 

You should also set the fields (i.e columns) method:

use \koolreport\dashboard\fields\Text;
use \koolreport\dashboard\fields\Number;
...
    protected function fields()
    {
        return [
            Text::create("month"),
            Number::create("2020"), // assuming year value 2020 exists
            Number::create("2021"),
            Number::create("2022"),
        ];
    }
Wayland Games commented on Jun 9, 2022

Thank you Sebastian!

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