找不到PHP参考功能

时间:2015-07-26 09:12:39

标签: javascript php jquery

我目前正在使用php,html显示图表。我一直在使用一个已经证明有效的库fusionCharts.php。但是,现在,我从以下行获得了错误>

<?php

class FusionCharts {

    private $constructorOptions = [];
    private $constructorTemplate = <<<EOD
    <script type="text/javascript">
        FusionCharts.ready(function () {
            new FusionCharts(__constructorOptions__);
        });
    </script>
EOD;
    private $renderTemplate = <<<EOD
    <script type='text/javascript'>
        FusionCharts.ready(function () {
            FusionCharts("__chartId__").render();
        });
    </script>
EOD;

但是firebug显示我的错误是从另一个php函数graph.php显示的。我从第16行得到了错误。

<link  rel="stylesheet" type="text/css" href="css/style.css" />

<!-- You need to include the following JS file to render the chart.
When you make your own charts, make sure that the path to this JS file is correct.
Else, you will get JavaScript errors. -->

<script src="js/fusioncharts.js"></script>
</head>

<body>

错误被抛出:

 ReferenceError: FusionCharts is not defined
 FusionCharts.ready(function () {  graph.php (line 16, col 12)
 ReferenceError: FusionCharts is not defined
 FusionCharts.ready(function () {

我正在添加以下所有文件:

fusioncharts.js

function fusioncharts_clickbar(){
  var chartargs = '';
  var chartid = arguments[0];
  for (i=0; i<arguments.length; i++) {
     chartargs = chartargs + arguments[i] + '/';
  }
  $.get(Drupal.settings.basePath +"/fusioncharts/data/"+ chartargs ,
    function(data){
       updateChartXML(chartid, data);
  }
); 
}

fusioncharts.php

<?php

class FusionCharts {

    private $constructorOptions = [];
    private $constructorTemplate = <<<EOD
    <script type="text/javascript">
        FusionCharts.ready(function () {
            new FusionCharts(__constructorOptions__);
        });
    </script>
    EOD;
    private $renderTemplate = <<<EOD
    <script type='text/javascript'>
        FusionCharts.ready(function () {
            FusionCharts("__chartId__").render();
        });
    </script>
    EOD;

    // constructor
    function __construct($type, $id, $width = 400, $height = 300, $renderAt, $dataFormat, $dataSource) {
        isset($type) ? $this->constructorOptions['type'] = $type : '';
        isset($id) ? $this->constructorOptions['id'] = $id : 'php-fc-'.time();
        isset($width) ? $this->constructorOptions['width'] = $width : '';
        isset($height) ? $this->constructorOptions['height'] = $height : '';
        isset($renderAt) ? $this->constructorOptions['renderAt'] = $renderAt : '';
        isset($dataFormat) ? $this->constructorOptions['dataFormat'] = $dataFormat : '';
        isset($dataSource) ? $this->constructorOptions['dataSource'] = $dataSource : '';

        $tempArray = [];
        foreach($this->constructorOptions as $key => $value) {
            if ($key === 'dataSource') {
                $tempArray['dataSource'] = '__dataSource__';
            } else {
                $tempArray[$key] = $value;
            }
        }

        $jsonEncodedOptions = json_encode($tempArray);

        if ($dataFormat === 'json') {
            $jsonEncodedOptions = preg_replace('/\"__dataSource__\"/', $this->constructorOptions['dataSource'], $jsonEncodedOptions);
        } elseif ($dataFormat === 'xml') { 
            $jsonEncodedOptions = preg_replace('/\"__dataSource__\"/', '\'__dataSource__\'', $jsonEncodedOptions);
            $jsonEncodedOptions = preg_replace('/__dataSource__/', $this->constructorOptions['dataSource'], $jsonEncodedOptions);
        } elseif ($dataFormat === 'xmlurl') {
            $jsonEncodedOptions = preg_replace('/__dataSource__/', $this->constructorOptions['dataSource'], $jsonEncodedOptions);
        } elseif ($dataFormat === 'jsonurl') {
            $jsonEncodedOptions = preg_replace('/__dataSource__/', $this->constructorOptions['dataSource'], $jsonEncodedOptions);
        }
        $newChartHTML = preg_replace('/__constructorOptions__/', $jsonEncodedOptions, $this->constructorTemplate);

        echo $newChartHTML;

    }

    // render the chart created
    // It prints a script and calls the FusionCharts javascript render method of created chart
    function render() {
       $renderHTML = preg_replace('/__chartId__/', $this->constructorOptions['id'], $this->renderTemplate);
       echo $renderHTML;

    }

}
?>

graph.php

   <?php
   require ("fusioncharts.php");
   error_reporting(E_ERROR);

   header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
   header("Cache-Control: no-cache");
   header("Pragma: no-cache");
   $con=mysql_connect("localhost","root", "");
   mysql_select_db("oligolilatest",$con);
   ?>
   <html>
   <head>
  <title>Comparison of data with other</title>
    <p> fdsfdsfds fsd f dsf sdf ds f</p>
  <link  rel="stylesheet" type="text/css" href="css/style.css" />

   <!-- You need to include the following JS file to render the chart.
When you make your own charts, make sure that the path to this JS file is correct.
    Else, you will get JavaScript errors. -->

    <script src="js/fusioncharts.js"></script>
    </head>

    <body>
    <?php

    $query = "SELECT UserID,FirstName FROM customerregistration ";
    $result = mysql_query($query);
    //echo "here1";
    // If the query returns a valid response, prepare the JSON string
    if ($result) {
        // The `$arrData` array holds the chart attributes and data
          // echo "here11";
        $arrData = array(
            "chart" => array(
              "caption" => "Number of User and Customer in the website",
              "paletteColors" => "#0075c2",
              "bgColor" => "#ffffff",
              "borderAlpha"=> "20",
              "canvasBorderAlpha"=> "0",
              "usePlotGradientColor"=> "0",
              "plotBorderAlpha"=> "10",
              "showXAxisLine"=> "1",
              "xAxisLineColor" => "#999999",
              "showValues" => "0",
              "divlineColor" => "#999999",
              "divLineIsDashed" => "1",
              "showAlternateHGridColor" => "0"
            )
        );

        $arrData["data"] = array();


// Push the data into the array
        while($row = mysql_fetch_assoc($result)) {
        array_push($arrData["data"], array(
            "label" => $row["FirstName"],
            "value" => $row["UserID"],

            )
        );
        }

        /*JSON Encode the data to retrieve the string containing the JSON representation of the data in the array. */
          // echo "here3";
        $jsonEncodedData = json_encode($arrData);
        echo $jsonEncodedData;

     /*Create an object for the column chart using the FusionCharts PHP class constructor. Syntax for the constructor is ` FusionCharts("type of chart", "unique chart id", width of the chart, height of the chart, "div id to render the chart", "data format", "data source")`. Because we are using JSON data to render the chart, the data format will be `json`. The variable `$jsonEncodeData` holds all the JSON data for the chart, and will be passed as the value for the data source parameter of the constructor.*/

        $columnChart = new FusionCharts("column2D", "myFirstChart" , 600, 300, "chart-1", "json", $jsonEncodedData);

        // Render the chart
        $columnChart->render();

     }

     ?>
     <div id="chart-1"><!-- Fusion Charts will render here-->
     </div> </body></html>

谢谢。

1 个答案:

答案 0 :(得分:0)

嗯,你给了我们一些代码来犁过去;并且您public function beforeRender (\Cake\Event\Event $event) { \Cake\I18n\Time::setToStringFormat('dd/MM/YYYY HH:mm:ss'); return parent::beforeRender () ; } 中包含的fusioncharts.js(您也包含在帖子中)似乎不包含FusionCharts类,因此必须包含其他javascript文件。查看他们的文档,您还需要包含这样的库:

<HEAD>

您是否已将此库已包含在其他工作页面中?