【发布时间】:2020-06-08 19:50:34
【问题描述】:
我正在尝试了解如何运行一些代码。我想用 JSON 文件中的数据绘制圆圈。我不太确定该怎么做。我想我搞砸了没有连接文件,或者我的 JSON 文件设置不正确......我的最终目标是制作一个连接的散点图,所以,现在,我只关注圆圈。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<svg id="s" xmlns="http://www.w3.org/2000/svg" />
<script type="text/javascript">
function makeSVG(tag, attrs) {
var el = document.createElementNS('http://www.w3.org/2000/svg', tag);
for (var k in attrs)
el.setAttribute(k, attrs[k]);
return el;
}
var data;
$.getJSON("https://raw.githubusercontent.com/Nataliemcg18/Data/master/temp.json", function(data) {
draw(data);
});
var circle = makeSVG('circle', {
cx: 100,
cy: 50,
r: 40,
stroke: 'black',
'stroke-width': 2,
fill: 'red'
});
var data
document.getElementById('s').appendChild(circle);
</script>
<svg width="1000" height="1000">
<line x1="200" y1="100" x2="200" y2="600" height="1000" width="1000" style="stroke:black;stroke-width:2" />
<line x1="200" y1="600" x2="900" y2="600" height="1000" width="1000" style="stroke:black;stroke-width:2" /> <!-- bottom line -->
[
{"Month": 0, "Temperature": 32},
{"Month": 1, "Temperature": 43},
{"Month": 2, "Temperature": 52},
{"Month": 3, "Temperature": 60},
{"Month": 4, "Temperature": 70},
{"Month": 5, "Temperature": 80},
{"Month": 6, "Temperature": 90},
{"Month": 7, "Temperature": 80},
{"Month": 8, "Temperature": 65},
{"Month": 9, "Temperature": 45},
{"Month": 10, "Temperature": 33},
{"Month": 11, "Temperature": 24}
]
【问题讨论】:
-
圆图正在工作。但是如果不查看您的 JSON 是什么样子,我们就无法真正帮助您处理 JSON。但是,您缺少
draw()功能。
标签: javascript html json svg