Using HighchartsPHP library in CakePHP

前端 未结 1 1567
忘掉有多难
忘掉有多难 2021-01-28 05:33

I am trying to use ghunti\'s HighchartsPHP wrapper in CakePHP so I can use it in my project.

In the demo it says to edit the config.php and include the scri

相关标签:
1条回答
  • 2021-01-28 06:17

    Your controller should be like this:

    <?php
    App::import('Vendor', 'HighchartsPHP/Highchart');
    
    class ChartsController extends AppController {
    
        public function index() {        
    
            $chart = new Highchart();
    
            $chart->chart = array(
                'renderTo' => 'container', // div ID
                'type' => 'line'
            );
    
            $chart->series[0]->name = 'Tokyo';
            $chart->series[0]->data = array(7.0, 6.9, 9.5);
    
            $this->set( compact( 'chart' ) );
        }
    
    }
    

    and index.ctp:

    <?php $chart->printScripts(); ?>
    
    <script type="text/javascript">
        <?php echo $chart->render("chart");?>
    </script>
    
    0 讨论(0)
提交回复
热议问题