KoolReport's Forum

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

Convert Drill Down example to SQL Server #3126

Closed Alan Sawyer opened this topic on on Aug 27, 2023 - 1 comments

Alan Sawyer commented on Aug 27, 2023

I want to convert the Drill Down example to SQL Server. I'm taking baby steps, so I have recreated the payments table in sql server. amount is a money field, and paymentdate is a date field. I did have to change the query a bit, but this is what I have.

        "name"=>"saleDrillDown",
        "title"=>"Sales Report",
        "levels"=>array(
            array(
                "title"=>"All Years",
                "content"=>function($params,$scope)
                {
                    ColumnChart::create(array(
                        "dataSource"=>(
                            $this->src("cloudpractice")->query("
                                SELECT YEAR(paymentDate) as year,sum(amount) as sale_amount 
                                FROM payments
                                GROUP BY year(paymentdate)
                        		order by year(paymentdate)
                            ")
                        ),
                        "columns"=>array(
                            "year"=>array(
                                "type"=>"string",
                                "label"=>"Year",
                            ),
                            "sale_amount"=>array(
                                "label"=>"Sale Amount",
                                "prefix"=>"$",
                            )
                        ),
                        "clientEvents"=>array(
                            "itemSelect"=>"function(params){
                                saleDrillDown.next({year:params.selectedRow[0]});
                            }",
                        )
                    ));
                }
            )

When I execute it I get this error:

Data column(s) for axis #0 cannot be of type string

Can someone tell me what I'm doing wrong?

Thanks Alan

Alan Sawyer commented on Aug 27, 2023

I added type = number to the sale_amount and it worked. Not sure why the example didn't need it, but that part now 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
None yet

DrillDown