Javascript 保险丝坏了

Javascript 保险丝坏了,javascript,php,mysql,Javascript,Php,Mysql,我对整个开发领域都是新手。你能帮我找出下面的错误吗。我将FusionCharts用于一个学校项目,发现很难填充图表。我已经根据提供的教程创建了这些文件,但是包含了MYSQL元素来检索数据。档案如下: HTML <!DOCTYPE html> <html> <head> <title>Fusion Charts Column 2D Sample</title> </head> <body

我对整个开发领域都是新手。你能帮我找出下面的错误吗。我将FusionCharts用于一个学校项目,发现很难填充图表。我已经根据提供的教程创建了这些文件,但是包含了MYSQL元素来检索数据。档案如下:

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/app1.js"></script>
</body>
</html>

融合图列2D示例
FusionCharts将在此处渲染
PHP

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

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

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

//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 month, actuallikes, projected, profit FROM avp");

//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['lable'] = $row['month'];
    $jsonArrayItem['value'] = $row['actuallikes'];
    $jsonArrayItem['value1'] = $row['projected'];
    $jsonArrayItem['value2'] = $row['profit'];  
    //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);
?>

JavaScript

var lables = [], values = [], value1s = [], value2s = [];
function getusers() {

    $.ajax({
            type: 'GET',
            async: false,
            url: "http://localhost/avp/chart_data.php",
            data: {},
            dataType: "json",
            success: function(result){
                if(result){
                    for(var i = 0 ; i < result.length; i++){
                        lables.push(result[i].lable);
                        values.push(result[i].value);
                        value1s.push(result[i].value1);
                        value2s.push(result[i].value2);
                    }
                }
            },
            error: function(errmsg) {
                alert("Ajax??????????!"+ errmsg);
            }
        });
    return lables, values, value1s, value2s;
    }

    getusers();

 salesAnlysisChart = new FusionCharts({
    type: 'mscombi2d',
    renderAt: 'chart-container',
    width: '600',
    height: '300',
    dataFormat: 'json',
    dataSource: {
      "chart": {
        "caption": "Harry's SuperMart",
        "subCaption": "Sales analysis of last year",
        "xAxisname": "Month",
        "yAxisName": "Amount (In USD)",
        "numberPrefix": "$",
        "showBorder": "0",
        "showValues": "0",
        "paletteColors": "#0075c2,#1aaf5d,#f2c500",
        "bgColor": "#ffffff",
        "showCanvasBorder": "0",
        "canvasBgColor": "#ffffff",
        "captionFontSize": "14",
        "subcaptionFontSize": "14",
        "subcaptionFontBold": "0",
        "divlineColor": "#999999",
        "divLineIsDashed": "1",
        "divLineDashLen": "1",
        "divLineGapLen": "1",
        "showAlternateHGridColor": "0",
        "usePlotGradientColor": "0",
        "toolTipColor": "#ffffff",
        "toolTipBorderThickness": "0",
        "toolTipBgColor": "#000000",
        "toolTipBgAlpha": "80",
        "toolTipBorderRadius": "2",
        "toolTipPadding": "5",
        "legendBgColor": "#ffffff",
        "legendBorderAlpha": '0',
        "legendShadow": '0',
        "legendItemFontSize": '10',
        "legendItemFontColor": '#666666'
      },
      "categories": [{
        "category": lables
      }],
      "dataset": [{
        "seriesName": "Actual Revenue",
        "showValues": "1",
        "data": values
      }, {
        "seriesName": "Projected Revenue",
        "renderAs": "line",
        "data": value1s
      }, {
        "seriesName": "Profit",
        "renderAs": "area",
        "data": value2s
      }]
    }
  });
    salesAnlysisChart.render(); }
});
});
var标签=[]、值=[]、值1s=[]、值2s=[];
函数getusers(){
$.ajax({
键入:“GET”,
async:false,
url:“http://localhost/avp/chart_data.php",
数据:{},
数据类型:“json”,
成功:功能(结果){
如果(结果){
对于(变量i=0;i
希望有人能帮我找出错误。如果我做了傻事,我会道歉


干杯

您为呈现图表而创建的JSON结构不正确,例如,“类别”应该有一个对象数组作为值,但您正在向其传递一个值数组,数据集中的数据键也是如此。您需要修改代码,或者也可以使用my。

是否收到错误消息?否。图表不会打印/显示它。请尝试在AJAX请求的成功回调(即for循环之后)中移动图表实例化(即salesAnlysisChart=new FusionCharts({…
)。