2016-07-21 2 views
1

을 jqplot합니다.JSON 내가 JSON 형식에서 jqplot로 차트를 만들려고 차트

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 = 날짜와 y = 값을 정의하는 방법을?

답변

0

그것은 음모에 "도착"하지 않는 데이터를 보인다.

당신이 Linux \ UNIX 기반 서버에 있다고 가정합니다. "file.txt""./file.txt"에서 correctly access으로 변경하십시오.

날짜 렌더러로 x-axis 렌더링를 들어, this post를 참조하십시오.

관련 문제