score:8
I've created a new demo here.
This is what it looks like:
The first change I made was just to create the circle right before the tick
function is declared:
g.append("circle")
.attr('class', 'last-circle')
.style("fill", "red")
.attr("r", 10)
.attr("cy", 0)
.attr("cx", 0);
Then, in the tick
function, right below where you recompute the new axes-domains, I created a new variable that holds only the data that will be displayed in the current frame. It filters the data by everything that has a smaller x
value than the maximum value in the timeWindow
:
var newdata = data.filter(function(d) {
return d.x < timeWindow[1];
});
Then I changed the part where you redraw the line to use the newdata
value so that the line won't be drawn outside of the graph's boundaries/domain:
g.select('.line')
.attr('d', line(newdata))
Then lastly, I got the last value from the newdata
and updated the position of the circle to be at the y and x value of the last value in the graph:
var last = newdata[newdata.length - 1]
g.select('.last-circle')
.transition()
.duration(0)
.attr("cy", y(last.y))
.attr("cx", x(last.x));
Source: stackoverflow.com
Related Query
- How to set circle at the right end of the last bar / item using D3
- How do I set the X values for a singled stacked horizontal bar chart using d3.js?
- How to set the last option from a drop-down list as selected using D3.js
- Using d3, how can I create a histogram or bar plot where the last bar is the count of all values greater than some number?
- How to place the bars of a bar chart in the right positions of the xAxis using d3.js?
- d3 make a individual bar Chart of week and Hours between and set the Item in the right Position
- How to place text on the circle when using D3.js force layout?
- How do I set custom ticks along the Xaxis in D3? or name the bars in a bar chart?
- svg: How to set a circle on the calculated line?
- how to get the coordinates of the center of a circle using d3.js
- How do you find the last data point in d3 and draw a circle and a line on it?
- How can i set the tick text of x-axis between bar in a bar chart in c3.js or d3.js?
- How do I set the right date from an external JSON file?
- How to set my variable so D3 data update finds the right object property?
- Wrong item "clicked" when using the "click" event on a SVG circle using D3
- How to set pattern origin at the top left point of each bar of a barchart in d3.js?
- How to place text inside each bar of the chart using d3
- d3js - Stacked Bar Chart in Horizontal Axis - How do I set x so the bars are seperated?
- How do I set a different range for line chart embedded in a bar chart using d3.js
- D3js horizontal bar chart: how to add numbers from data at the end of every bar?
- Draw the progress path from right to left in semi circle donut chart using d3js
- How to prevent the last tick from rendering? Using 'recharts' library
- How do I change the position of a circle svg element using the transform attribute?
- While creating a bar graph using d3 how to associate the bar height with the numbers on the scale?
- D3. How do I use a function to set more then one attribute using the .attr method
- D3 bar chart - last bar overhangs the end of the X axis
- how do I set up a grouping query on the server side. I want set up the query so I can use it for a pie chart in front end, using d3js
- How to control the space between the start of a bar and the axis in a bar-chart constructed using d3?
- In multiline chart, at the end of each line i want a small circle and the value of the end point using d3.js
- How can I set max value(range) for y-axis and bar width of a bar chart using nvd3.js
More Query from same tag
- Getting "Error, too late " for D3 transition
- How to create a stacked bar chart using dc.js?
- How can I simulate gravity correctly in a bounded area?
- Can someone explain this Javascript pattern found in D3s Pie Layout?
- NVD3 Chart responsive issue
- sdn4.0 set resultDataContents graph
- Set position of polygons and paths in d3
- Typescript type against '{}'
- How to save D3 v4 chart as a picture
- d3 - sunburst partition. Different sizes for each node
- How to set the width of td as float number
- Transitions in D3 Axis
- Link inside the node to expand it
- How to rotate text labels in a D3 x-axis?
- How to integrate D3@4.2.2 with Angular@2.0.0-rc5 and angular-cli@webpack
- D3.js how to get multiple scales for data array?
- nvd3 multibar chart: toggle default values to show
- Creating Map Custom Visual in Power BI
- Gradient to <td> cell acording to percentage??Percentage is calculated by some array values
- Converting an array to an object of nested objects for a tree diagram in Javascript
- Javascript looping through elements and adding to table
- Setting default selection of a dropdown menu with D3
- Iterating through a function call
- With D3, how can I set attribute ("fill", "none") of axis path and line, but not text (without editing stylesheet)
- D3.js can't load json file
- Linear scale inconsistency between x/y and width/height
- D3.js use hardcode json to implement treemap wrong(Just COPY the demo code and it failed)
- How to create a graph like StackOverflow reputation graph using d3.js?
- NVD3 / D3.js making xAxis string from date format
- jQuery c3 chart show block instead of line