1

jquery jqplot プラグイン/拡張機能で使用される配列を作成しようとしています。

私の2つの異なるJSONオブジェクト/配列は構造が同一であることがわかりますが、「静的」なものだけが期待どおりに機能しています。stackoverflow で同様の質問を見たことがありますが、どれもうまくいきませんでした。

get_chart_votes のソースに空白が返されているかどうかを確認しましたが、何も見つかりませんでした。最新の CodeIgniter フレームワーク、jQuery および jqplot を使用します。

静的な $arr を使用すると、[Object object] を取得するように結果を警告できますが、$charArray で同じことをしようとすると、何も得られません。

静的な $arr が返されると、この json が出力されます

{"test":1,"test2":2,"test3":3}

$chartArray の mysql の結果が返されると、この json が出力されます

{"Yes":1,"No":2,"Maybe":6}

私の PHP コード ($chartArray エコーがコメント化されている)

function get_chart_votes()
{

    $arr = array('test' => 1, 'test2' => 2, 'test3' => 3);
    die(json_encode($arr));

    $chartArray = array();
    $post = $this->input->post();
    $id = $post['id'];

    $answers  = $this->get_answers($id)->result_array();
    $votes = $this->get_votes($id)->result_array();

    $count = 0;
    $answer = 1;
    foreach($answers[0] as $ans)
    {
        if($count > 1 && $ans != "")
        {
            $vote = $votes[$answer-1]['COUNT(vote)'];
            $chartArray[$ans] = intval($vote);
            $answer++;
        }
        $count++;
    }
    //echo(json_encode($chartArray));
}

クライアント側では、これを持っています。

var s1 = [];
var ticks = [];
$.getJSON(
"../votr/get_chart_votes",
{ id: "57"},
function(jsonData) 
{
    for (var key in jsonData) 
    {
      if (jsonData.hasOwnProperty(key)) 
      {
        s1.push(jsonData[key]);
        ticks.push(key);
      }
    }

    $.jqplot.config.enablePlugins = true;

    plot1 = $.jqplot('chart1', [s1], {
        // Only animate if we're not using excanvas (not in IE 7 or IE 8)..
        animate: !$.jqplot.use_excanvas,
        seriesDefaults:{
            renderer:$.jqplot.BarRenderer,
            pointLabels: { show: true }
        },
        axes: {
            xaxis: {
                renderer: $.jqplot.CategoryAxisRenderer,
                ticks: ticks
            }
        },
        highlighter: { show: true }
    });


    $('#chart1').bind('jqplotDataHighlight',
        function (ev, seriesIndex, pointIndex, data) {
            $('#info1').html(ticks[pointIndex] + " got " + s1[pointIndex]);
        }
    );

}
);
4

0 に答える 0