2016-07-21 16 views
1

JSON形式からjqplotでグラフを作成しようとしています。Json to jqplot chart

file.txtなどは含まれています。私は、私が得たこのコードを実行すると

<script class="code" type="text/javascript"> 
$(document).ready(function(){ 
    // Our ajax data renderer which here retrieves a text file. 
    // it could contact any source and pull data, however. 
    // The options argument isn't used in this renderer. 
    var ajaxDataRenderer = function(url, plot, options) { 
    var ret = null; 
    $.ajax({ 
     // have to use synchronous here, else the function 
     // will return before the data is fetched 
     async: false, 
     url: url, 
     dataType:"json", 
     success: function(data) { 
     ret = data; 
     }, error:function (xhr, ajaxOptions, thrownError){ 
     alert(xhr.responseText);} 
    }); 
    return ret; 
    }; 

    // The url for our json data 
    var jsonurl = "file.txt"; 

    // passing in the url string as the jqPlot data argument is a handy 
    // shortcut for our renderer. You could also have used the 
    // "dataRendererOptions" option to pass in the url. 
    var plot2 = $.jqplot('chart2', jsonurl,{ 
    title: "AJAX JSON Data Renderer", 
    dataRenderer: ajaxDataRenderer, 
    dataRendererOptions: { 
     unusedOptionalUrl: jsonurl 
    } 

    }); 
}); 
</script> 

はそのような空のチャート: enter image description here

サンザシは、私はこの問題を解決することができjqplotで

[[["2008-09-30 4:00PM",15],["2008-10-30 4:00PM",8],["2008-11-30 4:00PM",17],["2008-12-30 4:00PM",10]]] 

?軸x = dateとy = valueをどのように定義するのか?

答えて

0

データがプロットに「到着」していないようです。

私はあなたがLinux \ UNIXベースのサーバであると仮定しています。"file.txt""./file.txt"correctly accessを現在のフォルダのファイルに変更してください。

x-axisを日付レンダラーでレンダリングする場合は、this postを参照してください。