[英]Why is my line not drawing to the canvas?
As a follow up to This question , I am having a problem drawing to the actual canvas. 作为此问题的后续,我在绘制实际画布时遇到问题。 If I echo each JSON object item to the console, it returns the values associated with the item and I'm not getting any errors so I know, based on my previous question that I am successfully reading the JSON file. 如果我将每个JSON对象项目回显到控制台,它将返回与该项目相关联的值,并且我没有收到任何错误,因此基于我之前的问题,我知道我已成功读取JSON文件。 So, why is nothing being drawn to the canvas? 那么,为什么什么都没画在画布上呢?
JS JS
$(document).ready(function(){
var canvas = document.getElementById("schematic_holder");
var ctx = canvas.getContext("2d");
$.ajax({
type: "GET",
dataType: "json",
url: "js/app/json/nst.json",
success: function(result){
var x1 = result[0].line.x1;
var y1 = result[0].line.y1;
var x2 = result[0].line.x2;
var y2 = result[0].line.x2;
var width = result[0].line.width;
var stroke = result[0].line.stroke;
console.log(x2);
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.lineWidth = width;
ctx.strokeStyle = stroke;
ctx.stroke();
},
complete: function(){
console.log("Complete!");
}
})
})
JSON JSON格式
[{
"line": {
"width": 3,
"stroke": "#000000",
"x1": 640.386,
"y1": 258.163,
"x2": 816.364,
"y2": 258.163
}
}]
I created a simple text case and it seems like you're doing nothing wrong 我创建了一个简单的文本案例,看来您没有做错任何事情
http://jsfiddle.net/zoak2dm5/ http://jsfiddle.net/zoak2dm5/
canvas.width = canvas.height = 1000;
I'm guessing your canvas is too small or is just not visible. 我猜您的画布太小或看不到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.