score:0
edited to change the data join to be be appropriate.
i think the issue has to do with variable data
. so, i added data
as an argument to the function and specified separate names for different data sets. when i specify different data names, i'm able to update the chart:
var first_data = [{
id: 'p1',
points: [{
point: {
x: 100,
y: 10
}
}, {
point: {
x: 100,
y: 30
}
}]
},
{
id: 'p2',
points: [{
point: {
x: 30,
y: 100
}
}, {
point: {
x: 230,
y: 30
}
},
{
point: {
x: 50,
y: 200
}
},
{
point: {
x: 50,
y: 300
}
},
]
}
];
var svg = d3.select("svg");
var line = d3.line()
.x((d) => d.point.x)
.y((d) => d.point.y);
function updategraph(data) {
console.log('dataset contains', data.length, 'item(s)')
var allgroup = svg.selectall(".pathgroup")
.data(data, function(d) { return d; });
var g = allgroup.enter()
.append("g")
.attr("class", "pathgroup")
allgroup.exit().remove()
g.append("path")
.attr("class", "line")
.attr("stroke", "red")
.attr("stroke-width", "1px")
.transition()
.duration(500)
.attr("d", function(d) {
console.log("update path");
return line(d.points)
});
g.selectall("path")
.transition()
.duration(500)
.attr("d", function(d) {
return line(d.points)
});
g.selectall("circle")
.data(d => d.points)
.enter()
.append("circle")
.attr("r", 4)
.attr("fill", "teal")
.attr("cx", function(d) {
return d.point.x
})
.attr("cy", function(d) {
return d.point.y
})
.exit().remove()
}
updategraph(first_data)
document.getelementbyid('update').onclick = function(e) {
var update_data = [{
id: 'p1',
points: [{
point: {
x: 20,
y: 10
}
}, {
point: {
x: 100,
y: 30
}
}]
},
{
id: 'p2',
points: [{
point: {
x: 30,
y: 100
}
}, {
point: {
x: 230,
y: 30
}
},
{
point: {
x: 50,
y: 300
}
},
]
}
];
updategraph(update_data)
}
$('#cb1').click(function() {
if ($(this).is(':checked')) {
var click_data = [{
id: 'p1',
points: [{
point: {
x: 10,
y: 10
}
}, {
point: {
x: 100,
y: 30
}
}]
},
{
id: 'p2',
points: [{
point: {
x: 30,
y: 100
}
}, {
point: {
x: 230,
y: 30
}
},
{
point: {
x: 50,
y: 200
}
},
{
point: {
x: 50,
y: 300
}
},
]
}
];
} else {
var click_data = [{
id: 'p1',
points: [{
point: {
x: 10,
y: 10
}
}, {
point: {
x: 100,
y: 30
}
}]
}];
}
updategraph(click_data)
});
Source: stackoverflow.com
Related Query
- d3 multiline update path and transition path does not work with nested data
- d3.on("mouseover") event does not work with nested SVG elements
- Node Transition does not occur with D3.js V4 and Angular
- Transition and opacity does not work well together
- Data Join with Custom Key does not work as expected
- I want to remove the commas from the X axis with d3, but tickFormat does not work and instead, throws an error
- document.getElementById() does not work with puppeteer finding and id on a <path> element on SVG
- Combining Parent and Nested Data with d3.js
- Brushing on ordinal data does not work
- D3: "SVG4601: SVG Path data has incorrect format and could not be completely parsed."
- Date and time transition from data with line
- How to animate transition over grouped, nested json coordinate data with D3.js?
- With D3, how can I set attribute ("fill", "none") of axis path and line, but not text (without editing stylesheet)
- Update with DOM children and data propagation
- Not understanding d3 v4 new general update pattern in nested data
- d3 line and area charts not updating with new data array
- Transition duration does not work on page refresh
- Interactive update does not work in heatmap
- Why does this title graphic not update with World
- Load and display data with condition, but the condition is not met
- Multiline chart x-axis ticks not aligned with data points
- d3 js transition over the array of rectangles does not work
- D3 Object Constancy not working with key function. Enter and Update contain all elements every time
- D3 line chart does not show tool tip and data points properly
- Integrating AngularJS and DagreD3 - AngularJS directive does not update on model change.
- How can I scale my map to fit my svg size with d3 and geojson path data
- Understanding D3 enter, update and exit selections with nested content
- order a capped chart with fake group does not work in dc.js
- D3 bar chart does not dynamically update y-axis and x-axis properly
- D3.js defs and url() does not work
More Query from same tag
- parentNode in d3 svg
- How to make separate force layout render loop?
- Mapping with D3: Feature clipping error in my spinning globe
- Zoomable Sunburst with % Share labeled
- Remove or clear previously drawn dimple chart
- Mapping a relative path import to the right `@types` in Typescript
- D3 - Positioning tooltip on SVG element not working
- d3.js: Help understanding parameters to callback functions
- patternTransform in svg not working for entire pattern
- d3 pie chart underlapping not overlapping
- D3.js svg element traversal
- Geo heat map(google) with large data
- How to make the coordinates of cell variable even if it is in quotes?
- D3 - Binding CSV Data to Array
- d3.js graph to plot binary data
- How to get coordinates(cx, cy) of circles after d3 force collision?
- Moving appended path in a div (d3.js)
- Create anchor tag within unordered list elements with d3js?
- Improving sequences sunburst by adding zooming
- How to update d3 table?
- Gradient along links in D3 Sankey diagram
- Datejs and d3.js conflict with transition
- D3 Zooming not working
- Compilation errors when drawing a piechart using d3.js and TypeScript
- Multiple C3.js charts automatically hidden, except the last one
- is there a way to convert svg <line> to svg <path> in illustrator?
- d3 flickering Text on setInterval when update data from csv
- d3js stacked bar chart not updating
- Visualising Neo4j graph in a web page
- reusable Bar chart showing bars one over another which have same names