2

我无法让 CanvasJs 在 x 轴上绘制诊断日期,在 y 轴上绘制癌症类型的名称。我的 JSON 数据回来了,并且正在工作。谁能告诉我我做错了什么。

这是我的 JSON 数据

[
    {
        "y": "follicular",
        "x": "2004-01-06"
    },
    {
        "y": "papillary",
        "x": "2010-05-04"
    }
]

这是我的 JQUERY 函数

$(document).ready(function(){ 

    $("#find").click(function(e){
        e.preventDefault();
        $.ajax({
            // the URL for the request
            url: "getDiagnosis.php",
            // the data to send (will be converted to a query string)
            data: {pnhsno: $('#search').val()},
            // whether this is a POST or GET request
            type: "GET",
            // the type of data we expect back
            dataType : "json",
            // code to run if the request succeeds;
            // the response is passed to the function
            success: function(json){

                if(json.length !=0){
                    alert(json);
                    var dataPoints = json.map(function (p) {
                         p.x = new Date(p.x);
                         return p;
                    });

                    var dp1 = []; 

                    for(var i=0; i<dataPoints.length; i++){

                        dp1.push({x:dataPoints[i].x, y:dataPoints[i].y})}
                            $("#dchart").CanvasJSChart({ //Pass chart options
                                title:{text:"Patient Diagnosis "},
                                zoomEnabled: true,
                                panEnabled: true, 
                                axisY:{valueFormatString:"DD-MM-YYYY",labelAngle:-45},

                                data: [{
                                    color:"red",
                                    type: "line",
                                    legendText:"Diagnosis", 
                                    showInLegend:true,
                                    dataPoints:dp1

                                }]
                           }); 


                }//if

                else{ $("#radioiodine").html("No Data For Radioiodine Found");}
            }//json
});
});
});
4

0 回答 0