【问题标题】:Multi Series 2d column chart from MySQL in FusionChartsFusionCharts 中来自 MySQL 的多系列 2d 柱形图
【发布时间】:2017-05-08 00:02:47
【问题描述】:

我正在尝试使用 MySQL 数据创建一个 2D 图表,该图表将显示两个数据范围。对于以前和当前的结果。我必须使用两个查询

  1. "SELECT name, points FROM results GROUP BY name";

  2. "SELECT name, pointsold FROM results GROUP BY name";

如何在代码中结合?

<?php

        // Form the SQL query that returns the top 10 most populous countries
        $strQuery = "SELECT name, points FROM results GROUP BY name";

        // Execute the query, or else return the error message.
        $result = $dbhandle->query($strQuery) 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" => "Rozkład punktacji",
              "paletteColors" => "#0075c2",
              "bgColor" => "#ffffff",
              "borderAlpha"=> "20",
              "canvasBorderAlpha"=> "0",
              "usePlotGradientColor"=> "0",
              "plotBorderAlpha"=> "0",
              "showXAxisLine"=> "1",
              "xAxisLineColor" => "#999999",
              "showValues" => "1",
              "divlineColor" => "#999999",
              "divLineIsDashed" => "1",
              "showAlternateHGridColor" => "0"
            )
            );

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

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

            /*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-2", "json", $jsonEncodedData);

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

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

    ?>   

【问题讨论】:

    标签: php mysql charts fusioncharts


    【解决方案1】:

    您可以从$result变量中的SQL查询中获取数据,然后根据FusionCharts格式为多系列图表创建空数组,然后将值推送到其中。

    你可以check this example for the same

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多