KoolReport's Forum

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

Drill Down Reports - Data column(s) for axis #0 cannot be of type string× #3480

Open Ravin Wijesinghe opened this topic on on Apr 22 - 6 comments

Ravin Wijesinghe commented on Apr 22

Dear Support

I am getting the error - Data column(s) for axis #0 cannot be of type string× for the following code where data is drawn from a MSSQL DB. Tried many things for many days, but could not figure out the issue. Your advice will be highly appreciated.

Thanks

<?php

                DrillDown::create(array(
                    "name"=>"saleDrillDown",
                    "title"=>"Services Sales Breakdown",
                    "levels"=>array(
                        array(
                            "title"=>"Total Sales",
                            "content"=>function($params,$scope)
                            {
                                ColumnChart::create(array(
                                    "dataSource"=> $this->src('sqlserver')
	                                ->query("SELECT YEAR(paymentDate) as Year, SUM(paymentAmount) as [Total Revenue] FROM appointments GROUP BY YEAR(paymentDate)"),
                                    "columns"=>array(
                                        "Year"=>array(
                                            "type"=>"string",
                                            "label"=>"Year",
                                        ),
                                        "[Total Revenue]"=>array(
                                            "label"=>"Total Revenue",
                                            "prefix"=>"$",
                                        )
                                    ),
                                        "clientEvents"=>array(
                                            "itemSelect"=>"function(params){
                                                saleDrillDown.next({year:params.selectedRow[0]});
                                            }",
                                        )

                                ));
                            }
                        ),
                        array(
                            "title"=>function($params,$scope)
                            {
                                return "Year ".$params["Year"];
                            },
                                "content"=>function($params,$scope)
                            {
                                ColumnChart::create(array(
                                "dataSource"=> $this->src('sqlserver')
                                ->query("SELECT MONTH(paymentDate) as Month, SUM(paymentAmount) as [Total Revenue] FROM appointments WHERE YEAR(paymentDate)=:year GROUP BY MONTH(paymentDate)") 
                                ->params(array(":year"=>$params["Year"])),
                                    "columns"=>array(
                                        "Month"=>array(
                                            "type"=>"string",
                                            "formatValue"=>function($value)
                                            {
                                                return date('M', mktime(0, 0, 0, $value, 10));
                                            }
                                        ),
                                        "[Total Revenue]"=>array(
                                             "label"=>"Sale Amount",
                                            "prefix"=>"$",
                                        )
                                    ),
                                        "clientEvents"=>array(
                                            "itemSelect"=>"function(params){
                                                saleDrillDown.next({month:params.selectedRow[0]});
                                            }",
                                        )
                                ));
                            }        
                        ),
                        array(
                            "title"=>function($params,$scope)
                            {
                                return date('F', mktime(0, 0, 0, $params["Month"], 10));
                            },
                            "content"=>function($params,$scope)
                            {
                                ColumnChart::create(array(
                                "dataSource"=> $this->src("sqlserver")                   
                                ->query("SELECT DAY(paymentDate) as Day, SUM(paymentAmount) as [Total Revenue] FROM appointments WHERE YEAR(paymentDate)=:year AND MONTH(paymentDate)=:month GROUP BY MONTH(paymentDate)")
                                ->params(array(":year"=>$params["Year"], ":month"=>$params["Month"])),
                                    "columns"=>array(
                                        "day"=>array(
                                            "formatValue"=>function($value,$row){
                                                return date("F jS, Y",strtotime($row["paymentDate"]));
                                            },
                                        ),
                                        "[Total Revenue]"=>array(
                                            "label"=>"Sale Amount",
                                            "prefix"=>"$",
                                        )
                                    )
                                ));
                            }                
                        )
                    ),
                ));
                ?>
Sebastian Morales commented on Apr 28

Pls try to add "type" => "string" to the last chart like this:

                                        "day"=>array(
                                            "type" => "string", // add this line
                                            "formatValue"=>function($value,$row){
                                                return date("F jS, Y",strtotime($row["paymentDate"]));
                                            },
                                        ),
Ravin Wijesinghe commented on Apr 28

Thanks, Sebastian for the reply. However, even after adding "type" => "string", I still get the error Data column(s) for axis #0 cannot be of type string×

Sebastian Morales commented 5 days ago

Would you pls tell us which chart package you used and what is the chart package version (which could be found in the package's composer.json file)?

Ravin Wijesinghe commented 5 days ago

The Drill Down Package version I am using is 3.8.1

Sebastian Morales commented 4 days ago

Ah, I meant to ask which package your ColumnChart belongs to, like is it KoolReport core's google chart or chartjs or apexcharts package, etc?

Ravin Wijesinghe commented 1 day ago

Ah ok :). The ChartJS version is 3.3.1

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

DrillDown