heatmap.js - 绘制.csv中的多个数据点

时间:2016-11-02 02:55:03

标签: javascript d3.js data-visualization heatmap d3heatmap

我正在尝试使用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>

1 个答案:

答案 0 :(得分:0)

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
});