2016-08-16 11 views
0

"value": "11413425.62"の代わりに、データベースphpMyAdminからデータを取得するコードを変更するにはどうすればよいですか?データベースからのゲージチャートの値

はここ..

<script type="text/javascript" src="http://static.fusioncharts.com/code/latest/themes/fusioncharts.theme.fint.js?cacheBust=56"></script> 
<script type="text/javascript"> 
    FusionCharts.ready(function(){ 
    var fusioncharts = new FusionCharts({ 
    type: 'angulargauge', 
    renderAt: 'Profit10%', 
    width: '350', 
    height: '250', 
    dataFormat: 'json', 
    dataSource: { 
     "chart": { 
      "caption": "Total Profit", 
      "subcaption": "After add value", 
      "lowerLimit": "0", 
      "upperLimit": "10000000", 
      "showValue": "1", 
      "valueBelowPivot": "1", 
      "theme": "fint" 
     }, 
     "colorRange": { 
      "color": [{ 
       "minValue": "0", 
       "maxValue": "50000", 
       "code": "#e44a00" 
      }, { 
       "minValue": "50000", 
       "maxValue": "75000", 
       "code": "#f8bd19" 
      }, { 
       "minValue": "75000", 
       "maxValue": "100000", 
       "code": "#6baa01" 
      }] 
     }, 
     "dials": { 
      "dial": [{ 
       "value": "11413425.62" 
      }] 
     } 
    } 
} 
); 
    fusioncharts.render(); 
}); 
</script> 

を私の完全なコードだとデータは、このコードで「dataCountryGrossMargin.phpを」このファイルを使用して抽出されていました。

<?php 
error_reporting(E_ALL^E_DEPRECATED); 
//connect to the server 
$connect= mysql_connect("127.0.0.1","root",""); 
//$conn = new mysqli($servername, $username, $password); 
if(!$connect) 
{ 
die('Could not connect: '.mysql_error($connect)); 
} 
//connect to the database 
mysql_select_db("fyp",$connect); 
$result = mysql_query("SELECT Country, COGS FROM `table 3`"); 
$rows = array(); 
while($r = mysql_fetch_array($result)) { 
    $row[0] = $r[0]; 
    $row[1] = $r[1]; 
    array_push($rows,$row); 
} 
print json_encode($rows, JSON_NUMERIC_CHECK); 
mysql_close($connect); 
?> 

ありがとう!

答えて

0

あなたはFusioncharts websiteで提供される例と同様のアプローチを使用することができます:私はチャートを使用してデータを抽出して表示するために管理

<?php 

/* Include the `fusioncharts.php` file that contains functions to embed the charts. */ 

    include("includes/fusioncharts.php"); 

/* The following 4 code lines contain the database connection information. Alternatively, you can move these code lines to a separate file and include the file here. You can also modify this code based on your database connection. */ 

    $hostdb = "localhost"; // MySQl host 
    $userdb = "root"; // MySQL username 
    $passdb = ""; // MySQL password 
    $namedb = "fusioncharts_phpsample"; // MySQL database name 

    // Establish a connection to the database 
    $dbhandle = new mysqli($hostdb, $userdb, $passdb, $namedb); 

    /*Render an error message, to avoid abrupt failure, if the database connection parameters are incorrect */ 
    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> 
    <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="fusioncharts/fusioncharts.js"></script> 
    </head> 

    <body> 
    <?php 

     // Form the SQL query that returns the top 10 most populous countries 
     $strQuery = "SELECT Name, Population FROM Country ORDER BY Population DESC LIMIT 10"; 

     // 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" => "Top 10 Most Populous Countries", 
        "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 = mysqli_fetch_array($result)) { 
      array_push($arrData["data"], array(
       "label" => $row["Name"], 
       "value" => $row["Population"] 
       ) 
      ); 
      } 

      /*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> 
+0

2dcolumnを。私はデータを抽出することができません:( –

+0

結果をレンダリングするためにPHPライブラリを含めるのと同じアプローチを使用しましたか? '(include/"fusioncharts.php"); ' – user919426

関連する問題