Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 更改生成的图表的维度_Javascript_Php_Mysql_Charts_Alignment - Fatal编程技术网

Javascript 更改生成的图表的维度

Javascript 更改生成的图表的维度,javascript,php,mysql,charts,alignment,Javascript,Php,Mysql,Charts,Alignment,以下代码用于使用fusioncharts javascript库生成条形图!尽管图表看起来太小,并且与屏幕左上角对齐!如何增加高度并将图形与屏幕中心对齐 <?php require_once("includes/db.php"); require("src/fusioncharts.php"); ?> <!-- You need to include the following JS file to render the chart. When you make y

以下代码用于使用fusioncharts javascript库生成条形图!尽管图表看起来太小,并且与屏幕左上角对齐!如何增加高度并将图形与屏幕中心对齐

<?php

require_once("includes/db.php");

require("src/fusioncharts.php");


?>


<!-- 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 type="text/javascript" src="http://static.fusioncharts.com/code/latest/fusioncharts.js"></script>

<?php

    // Form the SQL query that returns the top 10 most populous countries
    $sql = "Select count(Email) as Number,Date from reportorder GROUP BY date";

    // Execute the query, or else return the error message.
    $result =mysqli_query($db,$sql);

    // If the query returns a valid response, prepare the JSON string
    if ($result) {
        // The `$arrData` array holds the chart attributes and data
        $arrData = array(
            "chart" => array(
              "caption" => "Online orders on daily basis",
              "paletteColors" => "#0075c2",
              "bgColor" => "#ffffff",
              "borderAlpha"=> "50",
              "canvasBorderAlpha"=> "0",
              "usePlotGradientColor"=> "0",
              "plotBorderAlpha"=> "10",
              "showXAxisLine"=> "1",
               "xAxisName"=> "Date",
              "xAxisLineColor" => "#999999",
              "showValues" => "0",
              "divlineColor" => "#999999",
              "divLineIsDashed" => "1",
              "showAlternateHGridColor" => "0",
               "yAxisName"=> "Number of online orders"
            )
        );

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

// Push the data into the array
        while($row = mysqli_fetch_array($result)) {
        array_push($arrData["data"], array(
            "label" => $row["Date"],
            "value" => $row["Number"]
            )
        );
        }

        /*JSON Encode the data to retrieve the string containing the JSON representation of the data in the array. */

        $jsonEncodedData = json_encode($arrData);

/*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();

        // Close the database connection
        $db->close();
    }

?>

您的代码看起来很好,对于对齐,使用css,对于图表呈现的div

  <?php

    include("fusioncharts.php");
    $hostdb = "localhost";  // MySQl host
    $userdb = "root";  // MySQL username
    $passdb = "";  // MySQL password
    $namedb = "mscombi2d";  // MySQL database name
    $dbhandle = new mysqli($hostdb, $userdb, $passdb, $namedb);
    if ($dbhandle->connect_error) {
      exit("There was an error with your connection: ".$dbhandle->connect_error);
    }


    ?>

    <html>
       <head>
        <title>FusionCharts XT - Column 2D Chart - Data from a database</title>


        <!-- 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 type="text/javascript" src="http://static.fusioncharts.com/code/latest/fusioncharts.js"></script>
        <style type="text/css">
          #chart-1{
            width: 100%;
            text-align: center;
          }
        </style>
      </head>

      <body>
        <?php

        // Form the SQL query that returns the top 10 most populous countries
        $sql = "SELECT DISTINCT category, value1 FROM mscombi2ddata";

        // Execute the query, or else return the error message.
        $result = $dbhandle->query($sql) or exit("Error code ({$dbhandle->errno}): {$dbhandle->error}");

        // If the query returns a valid response, prepare the JSON string
        if ($result) {
            // The `$arrData` array holds the chart attributes and data
            $arrData = array(
                "chart" => array(
                  "caption" => "Online orders on daily basis",
                  "paletteColors" => "#0075c2",
                  "bgColor" => "#ffffff",
                  "borderAlpha"=> "50",
                  "canvasBorderAlpha"=> "0",
                  "usePlotGradientColor"=> "0",
                  "plotBorderAlpha"=> "10",
                  "showXAxisLine"=> "1",
                   "xAxisName"=> "Date",
                  "xAxisLineColor" => "#999999",
                  "showValues" => "0",
                  "divlineColor" => "#999999",
                  "divLineIsDashed" => "1",
                  "showAlternateHGridColor" => "0",
                   "yAxisName"=> "Number of online orders"
                )
            );

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

      // Push the data into the array
          while($row = mysqli_fetch_array($result)) {
          array_push($arrData["data"], array(
              "label" => $row["category"],
              "value" => $row["value1"]
              )
          );
          }

          /*JSON Encode the data to retrieve the string containing the JSON representation of the data in the array. */

          $jsonEncodedData = json_encode($arrData);

      /*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();

          // Close the database connection
          $dbhandle->close();
        }

      ?>

        <div id="chart-1">Fusion Charts will render here</div>

       </body>

    </html>

FusionCharts XT-柱2D图表-来自数据库的数据
#图1{
宽度:100%;
文本对齐:居中;
}
融合图将在这里呈现

生成图表后,能否提供html代码?如果您不知道如何获取代码,请使用chrome并按F12获取html。