KoolReport's Forum

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

Combine Value and Category Metric #2909

Open hung nguyen opened this topic on on Dec 19, 2022 - 4 comments

hung nguyen commented on Dec 19, 2022

Hello,

Can we combine the 2 metrics Value and Category into one Widget?

I want to use the Range(This week, Last 7 days, Last 30 days, etc..) for Category. Is it possible?

Thank you!

KoolReport commented on Dec 20, 2022

Currently the Category does not have range selector. One of solution is you use both Value metric and Category and on the change of range in Value metric, the category metric is also update to show data within that range. How is about that?

hung nguyen commented on Dec 20, 2022

Thanks for your reply. Yes it looks promise, but how do I make the Category update the data based on the Range Selector?

KoolReport commented on Dec 20, 2022

In the Value metric you use the actionSelect() to trigger the update of Category metric, and in the Category metric, you get the range of Value metric to query data. Something like this:

class MyValueMetric extends Metric
{
    ...
    protected function actionSelect($request, $response)
    {
        //On the value select, you want to update the Category as well
        $this->sibling("MyCategory")->update();
    }
    ...
}

And here is what inside MyCategory

class MyCategory
{
    protected function dataSource()
    {
        $range = $this->sibling("MyValueMetric")->selectedRange();
        //You will get $range is array of start date and end date ['2021-01-01 00:00:00','2022-01-01 00:00:00']
        //You apply to your query:
        return AutoMaker::table("tableName")->whereBetween("dateColumnName",$range);
    }
}

Hope that helps.

hung nguyen commented on Dec 20, 2022

It works!! Just need to update a little:

$ranges = $this->sibling("MyValueMetric")->getRanges();
$range = $ranges[$this->sibling("MyValueMetric")->getSelectedRangeKey()];

Thank you!!

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
solved

Dashboard