简体   繁体   中英

heatmap.js - plotting multiple data points from .csv

I am trying to plot x1,y1 co-ordinates using heatmap.js, I read the values from .csv file using d3.csv() method. I tried with example in https://www.patrick-wied.at/static/heatmapjs/ , Got only one point plotted, but there are seven points in the .csv file. Below is the code.

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>

Move heatmap.setData to outside your 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
}); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM