[英]heatmap.js - plotting multiple data points from .csv
我正在嘗試使用heatmap.js繪制x1,y1坐標,我使用d3.csv()方法從.csv文件中讀取值。 我嘗試使用https://www.patrick-wied.at/static/heatmapjs/中的示例,僅繪制了一個點,但是.csv文件中有七個點。 下面是代碼。
enter code here
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script src="heatmap.js"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script type="text/javascript">
function point()
{
alert("alert");
var points = [];
var heatmap = h337.create({
container: domElement
});
d3.csv("files/trial5.csv", function(error,data) {
data.forEach(function(d) {
d.x1 = +d.x1;
d.y1 = +d.y1;
console.log("data : " +data + " " + error);
heatmap.setData({
max: 5,
data:[{ x: d.x1, y: d.y1, value: 5}]
});
console.log("x:" + d.x1, "y:" + d.y1);
})
});
}
</script>
</head>
<body>
<div id="domElement" style="width: 1000px; height: 1000px; border: solid;"></div>
<input type="button" value="Click" id="clickButton" onclick="point()"/>
</body>
</html>
將heatmap.setData
移到forEach
之外:
data.forEach(function(d) {
d.x1 = +d.x1;
d.y1 = +d.y1;
});
heatmap.setData({
max: maxValue,//your max here
min: minValue,//your min here
data: data//your data array
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.