score:5
Accepted answer
You can do this, as shown in e.g. this example, by using a symbol generator and path
elements instead of SVG elements for specific shapes. The code to add shapes becomes
var node = svg.selectAll(".node")
.data(data.nodes)
.enter().append("path")
.attr("class", "node")
.attr("d", d3.svg.symbol()
.type(function(d) { return d3.svg.symbolTypes[d.s]; }))
.style("fill", function(d) { return color(d.group); })
.call(force.drag);
Then you also need to change your tick
handler to change the transform
attribute of the path
elements:
node.attr("transform", function(d) {
return "translate(" + d.x + "," + d.y + ")";
});
Complete jsfiddle here.
Source: stackoverflow.com
Related Query
- How do i add two different shapes to D3 forced directed graph based on shape field value?
- How to add a dynamic legend to a D3 force directed graph in Apex?
- how to add mouse events to force directed graph using the d3 canvas renderer?
- How do I add a click event to a directed graph using dagre d3.js(javascript library)?
- How to show many links separate by value in D3.js forced directed graph
- Another D3 add text to Forced Directed Graph
- Filtering nodes and links of a forced directed graph based on a button click
- d3 js line graph takes two different data formats. how do I differentiate those two?
- How can I add text to edges in a force directed graph d3?
- How to style nodes in d3 directed graph based on groups using reactjs
- How to add text to a force directed graph in D3.js
- How to add different shape marker in d3?
- Add text label to d3 node in Force directed Graph and resize on hover
- How to add a click event on nvd3.js graph
- Add text/label onto links in D3 force directed graph
- How to draw a line / link between two points on a D3 map based on latitude / longitude?
- D3 force directed graph, different shape according to data and value given?
- d3.js: How to add labels to scatter points on graph
- How to add a title for a NVD3.js graph
- How do I control the bounce entry of a Force Directed Graph in D3?
- How to add label to edges in d3 graph
- how to stop movement of force directed graph on force.start
- How to calculate in-degree, out-degree and weigted degree for force directed graph (d3.js)?
- How to create SVG elements of different types based on data?
- how do i add a zoom in and zoom out button in a graph on d3
- How to add custom colors in D3 nodes of a graph
- in d3.geo MultiPoint how can I provide different shapes for different poins?
- How to add a line graph to a scatterplot using d3?
- d3.js - How can I expand force directed graph horizontally?
- How to draw area/fill between two curved lines of different lengths (different x values) in d3
More Query from same tag
- rotate points from csv on d3 orthogonal projection
- Delete a node from a list in D3 and reset layout
- On hover effect on a SVG group
- Selecting all elements in one group of a categorical variable
- unable to create an automatic filling array without writing it manually
- Changing SVG elements using d3
- Linking two elements on mouseover and dual tooltips
- D3.js .each() with function that passes data
- "TypeError: undefined is not an object" when using .attr() to add data attribute
- How to update projection after copying a d3, svg map
- d3: Smoothly animate a hand drawn line?
- How to rotate all text by x degree on x-axis in Javascript
- DC.js making chart container or div wider to show legend properly
- Create data visualizations using Express and get data from a PostgreSQL database
- Text On each bar of a stacked bar chart d3.js
- Sort first array based on second array issue
- Accessing nested JSON structure in D3
- Stuck with D3.js – using multi-dimensional array to populate select dropdowns
- D3v4 - on("end") called before transition.duration is over
- d3 custom order bar series with two categories
- In D3 Sankey, how can I load the from objects or arrays instead of either json or csv files?
- Edges for Collapsible tree D3
- (Javascript with D3) Data from CSV file only being used once and returning undefined or NaN second time
- Import the parallel-coordinates library(d3.js) to jsfiddle
- How to import list-like data into d3?
- D3 overlapping labels in partition chart
- D3.js produces valid SVG but shows nothing
- Using d3 to elegantly perform different actions based on index
- TopoJSON - adding properties to a topoJSON file
- D3 Bar chart - Remove labels with zero value