是否可以使用CanvasJs Graph绘制日期(xAxis)和名称(yAxis)

时间:2014-11-23 22:11:18

标签: jquery json canvasjs

我无法让CanvasJs在x轴上绘制诊断日期,并在y轴上绘制癌症类型的名称。我有我的JSON数据回来并正在工作。任何人都可以请你告诉我我做得不对。

这是我的JSON数据

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

这是My 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
});
});
});

0 个答案:

没有答案