当前位置: 代码迷 >> JavaScript >> 找不到PHP参考功能
  详细解决方案

找不到PHP参考功能

热度:76   发布时间:2023-06-03 17:54:31.0

我目前正在使用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;

但是萤火虫显示我的错误正在从另一个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>

谢谢。

好吧,您已经给我们提供了一些代码供您参考; 而且似乎您包含在<HEAD>fusioncharts.js (您也包含在帖子中)根本不包含FusionCharts类,因此您必须包含其他JavaScript文件。 查看他们的文档,您还需要包括这样的库:

<script type="text/javascript" src="FusionCharts/FusionCharts.js"></script>

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

  相关解决方案