2017-01-12 8 views
0

以下のコードセットは、fusionchart javascriptライブラリを使用してチャートを生成するために使用されます。 これはPHPスクリプトJSライブラリを使用したチャートの生成

<?php 
//address of the server where db is installed 
$servername = "localhost"; 

//username to connect to the db 
//the default value is root 
$username = "chart"; 

//password to connect to the db 
//this is the value you would have specified during installation of WAMP stack 
$password = "L12345d"; 

//name of the db under which the table is created 
$dbName = "test"; 

//establishing the connection to the db. 
$conn = new mysqli($servername, $username, $password, $dbName); 

//checking if there were any error during the last connection attempt 
if ($conn->connect_error) { 
    die("Connection failed: " . $conn->connect_error); 
} 

//the SQL query to be executed 
$query = "SELECT * FROM top_odi_wicket_takers"; 

//storing the result of the executed query 
$result = $conn->query($query); 

//initialize the array to store the processed data 
$jsonArray = array(); 

//check if there is any data returned by the SQL Query 
if ($result->num_rows > 0) { 
    //Converting the results into an associative array 
    while($row = $result->fetch_assoc()) { 
    $jsonArrayItem = array(); 
    $jsonArrayItem['label'] = $row['player']; 
    $jsonArrayItem['value'] = $row['wickets']; 
    //append the above created object into the main array. 
    array_push($jsonArray, $jsonArrayItem); 
    } 
} 

//Closing the connection to DB 
$conn->close(); 

//set the response content type as JSON 
header('Content-type: application/json'); 
//output the return value of json encode using the echo function. 
echo json_encode($jsonArray); 
?> 

これはfollwoingコードは、私はそれがチャートを生成する必要があり、その後チュートリアルによるHTMLコード

<!DOCTYPE html> 
<html> 
<head> 
    <title>Fusion Charts Column 2D Sample</title> 
</head> 
<body> 
    <div id="chart-container">FusionCharts will render here</div> 
    <script src="js/jquery-2.1.4.js"></script> 
    <script src="js/fusioncharts.js"></script> 
    <script src="js/fusioncharts.charts.js"></script> 
    <script src="js/themes/fusioncharts.theme.zune.js"></script> 
    <script src="js/app.js"></script> 
</body> 
</html> 

を与えるJSONスクリプト

$(function() { 
    $.ajax({ 

     url: 'http://localhost/GP/Charts/chart_data.php', 
     type: 'GET', 
     success: function(data) { 
      chartData = data; 
      var chartProperties = { 
       "caption": "Top 10 wicket takes ODI Cricket in 2015", 
       "xAxisName": "Player", 
       "yAxisName": "Wickets Taken", 
       "rotatevalues": "1", 
       "theme": "zune" 
      }; 

      apiChart = new FusionCharts({ 
       type: 'column2d', 
       renderAt: 'chart-container', 
       width: '550', 
       height: '350', 
       dataFormat: 'json', 
       dataSource: { 
        "chart": chartProperties, 
        "data": chartData 
       } 
      }); 
      apiChart.render(); 
     } 
    }); 
}); 

ありますhtmlコードが実行されると!しかし、チャートアペラを実行していないときに、 というテキストのみが表示されます。「FusionChartsはここにレンダリングされます」が表示されます。私は、彼らがDOMの前にロードするように、uはheadタグ内のすべてのスクリプトファイルを保つべきだと思いhttp://www.fusioncharts.com/dev/using-with-server-side-languages/tutorials/php-mysql-charts.html

答えて

0
require('http://localhost/GP/Charts/chart_data.php'') 

require('http://localhost/GP/Charts/chart_data.php') 
+0

申し訳ありませんが、チュートリアルによれば、URLは 'http://localhost/GP/Charts/chart_data.php'ですが、まだ動作していません! –

+0

ブラウザでhttp://localhost/GP/Charts/chart_data.phpページに行くとどうなりますか? –

+0

「フュージョンチャートはここにレンダリングされます」というテキストが上部に表示されます –

0

をする必要がありますexacltyこのチュートリアルに続く(DIV)、それをloads..give a try

+0

そのいずれかが動作していない –

+0

httpコールがいくつかのデータを返すことは確かですか?応答をコンソールで調べて、このようにして、それがバックエンドの問題かフロントエンドかを知ることができます –

+0

データがありません! 「FusionChartsはここにレンダリングされます」というテキストのみが表示されます –

1

jqueryを正しくインストールしていないと思います。 hereをクリックしてjqueryをダウンロードし、上記のjsフォルダの下にコピーします。

関連する問題