score:1
Accepted answer
You must draw each individual MultiPolygon
.
I have defined a little more interesting DEM samples.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/d3-hsv.v0.1.min.js"></script>
<script src="https://d3js.org/d3-contour.v1.min.js"></script>
<title>d3-contour-multipolygon</title>
</head>
<body>
<canvas id="canvas" width="200" height="200"></canvas>
<script>
values = [10,10,10,10,10,10,10,
20,20,20,20,20,20,20,
30,30,30,30,30,30,30,
40,40,40,40,40,40,40,
30,30,30,30,30,30,30,
20,20,20,20,20,20,20,
10,10,10,10,10,10,10];
values = [ 0, 0, 0, 0, 0, 0, 0,
0,20,25,29,21,22, 0,
0, 0,39,32,33,10, 0,
0,10,40,50,42,40, 0,
0, 0,31,39,34,24, 0,
0,12,22,31,26,23, 0,
0, 0, 0, 0, 0, 0, 0];
var n = 7,
m = 7,
canvas = document.querySelector("canvas"),
context = canvas.getContext("2d"),
// path = d3.geoPath().context(context);
contours = d3.contours().size([n, m]);
projection = d3.geoIdentity().scale(canvas.width / n),
path = d3.geoPath(projection, context);
function update(data) {
var cntrs = contours.thresholds(d3.range(0, 60, 10))(data);
cntrs.forEach(c => {
if (c.coordinates.length == 0) return;
context.beginPath();
// path(contours.thresholds(d3.range(0, 60, 10))(data));
path(c);
context.stroke();
});
}
update(values);
</script>
</body>
</html>
Source: stackoverflow.com
Related Query
- How do you draw d3-contour multipolygon output to canvas?
- how do you draw linear line in scatter plot with d3.js
- How can you draw a collection of lines and points based on categorical data in D3?
- How do you find the last data point in d3 and draw a circle and a line on it?
- how to draw contour around text image
- How do you add rotation logic for mobile devices upon dragging on a 3d globe with D3.js and html canvas
- how can i dynamically calculate and draw canvas border from user input
- How do you create a d3 line function that will draw 2 lines for x, y1, y2 data?
- How do you create a family tree in d3.js?
- How do you remove a handler using a d3.js selector
- How to draw straight line in d3.js (horizontally and vertically)
- How to use the D3 diagonal function to draw curved lines?
- How to draw line with arrow using d3.js
- How do you remove the background gridlines in nvd3.js?
- How to draw a line / link between two points on a D3 map based on latitude / longitude?
- How to draw a path smoothly from start point to end point in D3.js
- how do you set a fixed link distance with d3 v4
- How to draw gradient arc using d3.js?
- How do you make an SVG element mouse event bubble up through another element?
- How to draw a linear gradient circle by svg?
- How do you set periodic timers in d3.js?
- How to simulate mouse move in D3 so when you drag nodes, other nodes move automatically?
- How do you access an array of Objects using D3?
- How to draw a exponential function y=ab^x using d3.js axis functionality
- How do you add d3-selection-multi to d3?
- How to show and hides nodes when you move the mouse over a node in D3 Javascript
- How to draw a *simple* line segment with d3.js?
- How to draw logarithmic line charts with nvd3
- How to draw a simple Force-directed graph in D3 Javascript
- Very Simple D3: How to Draw an Arc?
More Query from same tag
- C3 JS - time series tick reverses the format
- d3.json works but $.getJson fails
- Custom tick size on axis (d3js)
- How to generate multiple SVG's in a Meteor.js #each wrapper
- Remove d3 axis transition on initialization
- SVG `<path>` Imprecision
- d3.js graph using value as a part of node label
- How to make sure billboard.js series have ended all transitions in onrendered?
- Getting a better performance on repeatedly method on d3
- How to pass JavaScript object to another function?
- dc.js - How do I add Totals to a dataTable?
- Draw USA map region wise using D3 and angular 6
- Error using D3 with typescript in Visual Studio Code
- Qlik Sense change measure used on graph
- How to update multiple pie charts in one page in D3?
- How to sum values of objects and push it in an array
- How to make D3 display xAxis correctly during daylight saving time change
- To integrate D3 Band zoom in D3 heatmap
- d3.path plots only first feature of feature collection
- Problems using D3.js locally
- How to rename fields to get into json hash
- How to remove the first tick in d3
- D3 Charts issue while plotting line charts with weekday in the x-axis
- d3 canvas brush / selection
- Plot a shape using X,Y points
- d3.rebind in D3 v4
- How to render object data in D3?
- Combined elasticY over multiple charts
- get path attribute value with SVG
- Customize tooltip of donut chart in dimple.js