score:1
Accepted answer
The error I get with your code is:
Uncaught TypeError: Cannot read property 'NaN' of undefined
You have a typo in your code. You are passing in d.lat
/d.lon
; but the code expects d.lat
/d.lng
. Either change the code to use d.lon
or change the object to contain d.lng
. (your code is inconsistent, it uses d.lng
in the heatmap, and d.lon
in the d3 code.
updated code snippet (using d.lng
and removing the d3 markers as they hide the heatmap):
var csvData = "lat,lng,temp1,temp2\n41.87148,-87.67644,6.68,39.8\n41.880497,-87.745268,4.75,7.6\n41.910922,-87.649518,7.39,36.5\n41.866786,-87.666306,6.5,39\n41.751142,-87.71299,5.46,14.2\n41.786756,-87.664343,5.33,34.1\n41.808594,-87.665048,6.15,27.8\n41.666078,-87.539374,3.79,32\n41.823527,-87.641054,5.12,31.6\n41.946373,-87.727382,6.73,35.2\n41.751142,-87.71299,5.02,37.5\n41.764122,-87.72242,4.5,34\n41.903632,-87.648093,5.3,30.6\n41.713867,-87.536509,4.68,31.3\n41.800846,-87.703739,4.99,32.7\n41.918733,-87.668257,5.24,34\n41.83107,-87.617298,5.8,8.4\n41.92617,-87.631533,5.31,33.5\n41.794477,-87.615957,4.9,33.3\n41.906481,-87.671373,5.28,18.4\n41.741148,-87.54045,,\n41.891964,-87.611603,,\n41.858136, -87.616055,,\n41.857797,-87.685806,,\n41.881172,-87.686359,,\n41.954626,-87.645247,,"
var colorScale = d3.scale.linear().range(['blue', 'yellow']);
var tooltip = d3.select("#map").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
// Create the Google Map…
var map = new google.maps.Map(d3.select("#map").node(), {
zoom: 10,
center: new google.maps.LatLng(41.83379085476929, -87.73212559320208),
mapTypeId: google.maps.MapTypeId.TERRAIN
});
data = d3.csv.parse(csvData)
var heatmapData = [];
data.forEach(function(d) {
heatmapData.push(new google.maps.LatLng(d.lat, d.lng));
});
var heatmap = new google.maps.visualization.HeatmapLayer({
data: heatmapData,
map: map
});
var max = d3.max(data, function(d) {
return d.temp1;
});
var min = d3.min(data, function(d) {
return d.temp1;
});
if (max > 0 && min > 0) {
min = -max;
}
if (max < 0 && min < 0) {
max = -min;
}
colorScale.domain([min, max]);
var overlay = new google.maps.OverlayView();
// Add the container when the overlay is added to the map.
overlay.onAdd = function() {
var layer = d3.select(this.getPanes().overlayMouseTarget).append("div")
.attr("class", "nodes");
overlay.draw = function() {
/* var projection = this.getProjection(),
padding = 10;
var marker = layer.selectAll("svg")
.data(data)
.each(transform)
.enter().append("svg")
.each(transform)
.attr("class", "marker")
.on("mouseover", function(d) {
tooltip.transition()
.duration(200)
.style("opacity", 1);
tooltip.html(d.node_id)
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY) + "px");
})
.on("mouseout", function(d) {
tooltip.transition()
.duration(500)
.style("opacity", 0);
});
marker.append("circle")
.attr("r", 7)
.attr("cx", padding)
.attr("cy", padding)
.style("fill", function(d) {
if (d.temp1) {
return colorScale(d.temp1);
} else
return "none";
});
marker.append("text")
.attr("x", padding + 7)
.attr("y", padding)
.attr("dy", ".31em")
.text(function(d) {
return d.temp1;
});
*/
function transform(d) {
d = new google.maps.LatLng(d.lat, d.lng);
d = projection.fromLatLngToDivPixel(d);
return d3.select(this)
.style("left", (d.x - padding) + "px")
.style("top", (d.y - padding) + "px");
}
};
};
overlay.setMap(map);
html,
body,
#map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.nodes,
.nodes svg {
position: absolute;
}
.nodes svg {
width: 60px;
height: 20px;
padding-right: 100px;
font: 10px sans-serif;
}
.nodes circle {
stroke: black;
stroke-width: 1px;
}
.tooltip {
position: absolute;
text-align: center;
min-width: 200;
width: auto;
min-height: 25;
height: auto;
padding: 2px;
font: 10px sans-serif;
background: rgba(0, 0, 0, 0.8);
color: #fff;
border: 0px;
border-radius: 8px;
pointer-events: none;
}
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.3.10/d3.min.js"></script>
<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js?libraries=visualization"></script>
Source: stackoverflow.com
Related Query
- Using Googlemaps HeatmapLayer with in D3
- Using D3.js with Angular 2
- How to draw line with arrow using d3.js
- Using arrow functions with d3
- How do I resolve "[ERR_REQUIRE_ESM]: Must use import to load ES Module" when using D3.js 7.0.0 with Next.js 11.0.1?
- Using d3.js with Apache Zeppelin
- Using D3 transition method with data for scatter plot
- Graph with auto layout using d3 (a tree with multiple parent nodes)
- Using D3 with Elm
- Using d3-3d with pan & zoom while retaining rotation
- Make simple bar chart using C3 with separate columns on the x axis
- D3 fill shape with image using pattern
- D3 using classed() to add and remove class with checkbox
- How can I show a graph using d3 force layout with initial positions set and no movement at all?
- Using D3 with a multi-dimensional array/object
- Using AngularJS / AngularUI with d3.js and DOM effects
- Using server-sent events with cubism.js graphs
- How to show a tooltip with value when mouseover a svg line graph using d3.js?
- Using Handlebar with D3.js
- Line chart using ordinal x-axis with d3.js and nvd3.js
- Using dc.js on the clientside with crossfilter on the server
- D3 V4 Transition on entering elements using General Update Pattern with merge
- d3.js: Nested Selection with update using `join`
- Data for sunburst charts with d3.hierarchy using D3js v4
- Using D3 to fill an svg with a background image
- Using d3.js is there a way to zero align two Y Axes with positive and negative values
- Using large JSON files with d3.js causes massive performance hits/crashes
- Using D3 requests (json) over SSL with path url gives Mixed Content error?
- Using d3-zoom to interact with WebGL
- Using Bootstrap Tooltip with SVG Object - Not Displaying Despite specifying Container
More Query from same tag
- Why does d3 axis class name change axis format?
- C3 bar chart - Custom X-axis label
- Display days of the week as ticks in d3
- d3 equivalent for Ruby on Rails?
- D3.js nodes not appearing on page load
- Using CSV for data
- D3 scatter plot not showing
- Draw multiple circles using d3.js in a 3x3 format
- Scope issue between jQuery request and d3.js
- Remove Double-Click Zoom D3
- When integrate elasticsearch with d3.js, "Uncaught TypeError: Cannot read property 'Client' of undefined" I get this error
- d3js bar chart issue when used with jquery mobile
- Why do I get clicks when I load, but not when I click?
- I am trying to get NVD3 to work with data from an ajax request
- d3.js click event show/hide html element
- Update graph on click
- How to refer to a D3 parent element's class?
- dynamically update d3js linegraph with JSON data
- How would I graph a line based on a degree measure in D3.js?
- d3.js. Spinning globe with bars
- D3 - Vertical axis is not displaying correctly
- d3 stock value line graph: can't draw the line
- d3.js and dimple.js two identical elements
- Simple CSV parsing in Javascript
- How to allow layout.pack() size to be free form in d3?
- D3 Multi Series Line chart not working with correct xAxis values
- Render a d3 pie chart in angular with angular-nvd3
- Alternating tick padding in d3.js
- How to update the axis scale on change events in cubism/d3
- Javascript closure property manipulation