在页面加载时出现500网络错误

时间:2014-01-21 21:31:07

标签: javascript json graph highcharts

我正在使用Highcharts生成一些图形,我正在使用一些JSON来填充这些图形,并且无处不在存在javascript错误。问题是我不知道它是什么,因为它是500网络错误(我认为)。

以下是我要更改的代码

function CreateGoldData(array_x_data, array_y_data)
{
    var game_length = <?php echo($gameData->GetGameTime());  ?>;
    var ret = [];
    var cumulative_gold = 0;

    var previous_time = 0;
    for (var i = 0; i < array_x_data.length; i++)
    {
        var delta_time = array_x_data[i];
        var time = previous_time + delta_time;
        previous_time = time;
        var gold = array_y_data[i];

        for (var a = ret.length; a <= time; a++)
        {
            // 2 gold per second
            cumulative_gold += 2;
            ret.push(cumulative_gold);
        }
        ret[time] += gold;
        cumulative_gold += gold;

        if (i == array_x_data.length - 1)
        {
            for (var a = ret.length; a <= game_length; a++)
            {
                // 2 gold per second
                cumulative_gold += 2;
                ret.push(cumulative_gold);
            }
        }
    }

    return ret;
}

function GetHellbourneGolds()
{
    var hellbourne_players = [];
    <?php


        $gold = $gameData->GetGoldGraph();
        for ($i = 0; $i < count($gold); $i++)
        {
            $json = json_decode($gold[$i]);
            // Json encoded gold for one player
            if ($json->team == 'hellbourne') {
                echo 'hellbourne_players.push(CreateGoldData([' . $json->time . '], ['. $json->gold .']));';
            }

        }

    ?>

    return hellbourne_players;
}

function GetHellbourneColors()
{
    var hellbourne_colors = [];
    hellbourne_colors.push('orange');
    hellbourne_colors.push('blue');
    hellbourne_colors.push('red');
    hellbourne_colors.push('brown');
    hellbourne_colors.push('white');
    return hellbourne_colors;
}
function GetLegionGolds()
{
    var final_gold = [];
    <?php
         $legion = array();
         $hellbourne = array();
         $combined = array_fill(0, count($gold), 0);

         $gold = $gameData->GetGoldGraph();
         for ($i = 0; $i < count($gold); $i++)
         {
             $json = json_decode($gold[$i]);
             // Json encoded gold for one player
             if ($json->team == 'hellbourne') {
                 $hellbourne = array_push($hellbourne, $json->gold);
             }

         }

         // loop down here with hellbourne gold and create another loop and subtract the rteuslts
         for ($i = 0; $i < count($gold); $i++) {

             $json = json_decode($gold[$i]);
             // Json encoded gold for one player
             if ($json->team == 'legion') {
                 $legion = array_push($legion, $json->gold);
             }

         }

         for ($i = 0; $i < count($gold); $i++) {

             // Legion is postiive, hellbourne is negative
             $combined[$i] = $legion - $hellbourne;

         }

         for ($i = 0; $i < count($combined); $i++) {

             $json = json_decode($gold[$i]);

             // Legion is postiive, hellbourne is negative
             echo 'final_gold.push(CreateGoldData(['.$json->time.'], ['.$combined[$i].']));';

         }

     ?>
    return final_gold;
}

function GetLegionColors()
{
    var legion_colors = [];
    legion_colors.push('orange');
    legion_colors.push('blue');
    legion_colors.push('red');
    legion_colors.push('brown');
    legion_colors.push('white');
    return legion_colors;
}
$(function()
{
    // Hellbourne and legion individual golds
    //var hellbourne_golds = GetHellbourneGolds();
    var legion_golds = GetLegionGolds();


    // Create team chart
    var team_chart_data = [];
    //PushTeamGoldData(team_chart_data, MergeTeamGoldData(hellbourne_golds), 'Hellbourne', '#1240AB');
    PushTeamGoldData(team_chart_data, MergeTeamGoldData(legion_golds), 'Legion', '#3914AF');
    var team_chart = CreateTeamGoldChart(team_chart_data, "container4");

    // Register team filters
    $("#legion_filter").click(function(){
        var chart = team_chart;
        if ($("#legion_filter_li").hasClass('selected'))
        {
            for (var i = 0; i < chart.series.length; i++)
            {
                if (chart.series[i].name == 'Legion')
                    chart.series[i].hide();
            }
            $("#legion_filter_li").removeClass('selected');
        }
        else
        {
            for (var i = 0; i < chart.series.length; i++)
            {
                if (chart.series[i].name == 'Legion')
                    chart.series[i].show();
            }
            $("#legion_filter_li").addClass('selected');
        }
        return false;
    });

    $("#hellbourne_filter").click(function(){
        var chart = team_chart;
        if ($("#hellbourne_filter_li").hasClass('selected'))
        {
            for (var i = 0; i < chart.series.length; i++)
            {
                if (chart.series[i].name == 'Hellbourne')
                    chart.series[i].hide();
            }
            $("#hellbourne_filter_li").removeClass('selected');
        }
        else
        {
            for (var i = 0; i < chart.series.length; i++)
            {
                if (chart.series[i].name == 'Hellbourne')
                    chart.series[i].show();
            }
            $("#hellbourne_filter_li").addClass('selected');
        }
        return false;
    });
});

我很想调试它,但是没有办法。我通过JSLint运行它,它很干净。我可能正在做一些蠢事。

0 个答案:

没有答案