Я пытаюсь создать свою серию данных, необходимую для диаграммы CanvasJs, динамически и до сих пор не имел радости. так или иначе мой код не работает. Я получаю следующее сообщение об ошибке:Looping через JSON возвращен для создания моей диаграммы
SyntaxError: missing : after property id for(var i=0; i<dataPoints.length; i++){
Это мой JSON данные
[
{
"t": "t3",
"y": 6.8,
"x": "2004-07-05"
},
{
"t": "t4",
"y": 29,
"x": "2004-07-05"
},
{
"t": "tsh",
"y": 0.01,
"x": "2004-07-05"
},
{
"t": "thyroglobulin level",
"y": 0.5,
"x": "2004-07-05"
},
{
"t": "t3",
"y": 5.2,
"x": "2005-06-15"
},
{
"t": "t4",
"y": 30,
"x": "2005-06-15"
},
{
"t": "tsh",
"y": 0.02,
"x": "2005-06-15"
},
{
"t": "thyroglobulin level",
"y": 0.5,
"x": "2005-06-15"
}
]
Вот мой код для извлечения JSON и создания моей серии
$(document).ready(function(){
$("#find").click(function(e){
e.preventDefault();
$.ajax({
// the URL for the request
url: "bloodTest.php",
// the data to send (will be converted to a query string)
data: {pnhsno: "1001001002"},
// 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){
var dataPoints = json.map(function (p) {
p.x = new Date(p.x);
return p;
});
$("#chart").CanvasJSChart({ //Pass chart options
title:{text:"Blood Test Results"},
axisX:{valueFormatString:"DD-MM-YYYY",labelAngle:-45},
data: [{
type: "line", //change it to column, spline, line, pie, etc
for(var i=0; i<dataPoints.length; i++){
if(dataPoints[i].t =="t3"){
dataPoints:[
{X:dataPoints.x, y:dataPoints.y}]
}
}
]
});
}
}
});
});
});
-1. Какая у вас ошибка? Что случилось с результатами? – Markasoftware
SyntaxError: missing: after property id \t для (var i = 0; i
Nurettin
ok, пожалуйста, отредактируйте вопрос, чтобы отразить это – Markasoftware