scottharwell / GoogleCharts

CakePHP Plugin for Google Charts Javascript API
26 stars 30 forks source link

$this->GoogleChart->createJsChart($chart) returns null #1

Closed henryturk closed 12 years ago

henryturk commented 12 years ago

After setup and loading the GoogleChart helper return a null value in the view.

henryturk commented 12 years ago

Controller setup for mock data:


        $chart = new GoogleChart();

        $chart->type('LineChart');
        $chart->columns(array(
            'event_date' => array(
                'type' => 'string',
                'label' => 'Date'
            ),
            'sum' => array(
                'type' => 'currency',
                'label' => 'Total'
            )
        ));

        $date = date('m/d/Y',strtotime('-3 weeks'));
        for($i = 0; $i < 16; $i++){
            $chart->addRow(array(
                'event_date' => $date,
                'sum' => '$1,578.25'
            ));
            $date = date('m/d/Y',strtotime($date . '+1 day'));
        }

        $this->set(compact('chart'));       
scottharwell commented 12 years ago

The helper function doesn't return a value; it would always be void. The helper does echo a scriptBlock that has 'inline' => false. In your layout, do you have echo $this->fetch('js');? If you don't see any JS output at all, then you probably don't have that statement in your layout.

Also, in order to help troubleshoot, please provide the version of CakePHP that you are on.

henryturk commented 12 years ago

Understood, I've got fetch('script') instead of fetch('js'). Running 2.2.1 currently.

Maybe a suggesttion for GoogleChartHelper::createJsChart() would be to allow the user to specify which scriptBlock they want the generated JS to be sent to. And change the default from 'js' to 'script' as that is how it is written in the book and documented in the API for the most basic scriptBlock functionality.

Will update everything and report back.

scottharwell commented 12 years ago

I agree about the script placement...I'll add with time or if you have the time to do it, then please send a pull request.

That said, fetch('script'); is right, not fetch('js');. That was an error on my part. However, if you don't see any output...then something is up with your JS output in general. Even if the chart object was null, you would get back some code into your view from the charthelper.

henryturk commented 12 years ago

Will do, I'll fork and develop on this with you. No ETA on anything though.

The JS was user error. Your script blocks were showing up before my jQuery includes. All is fixed and working well.