score:5
You are using xScale
and yScale
when setting up your axes. Apart from being used internally for generating ticks and tick labels these scales will provide easy means of conversion between your SVG's coordinates (the scale's range) and the coordinates used by your grid (the scale's domain), i.e. the values of your data.
To draw the line, you need to apply the scales to the data values as well:
svg.append('line')
.style('stroke', 'black')
.attr('x1', xScale(5))
.attr('y1', yScale(5))
.attr('x2', xScale(20))
.attr('y2', yScale(20));
score:-1
I solved it this way:
svg.append('line')
.style('stroke', 'black')
.attr('x1', function (d) { return x(5))
.attr('y1', function (d) { return y(5))
.attr('x2', function (d) { return x(20))
.attr('y2', function (d) { return y(20));
score:0
Something's wrong in the way you're calculating vertical axis coordinates,
check this :
svg.append('line')
.style('stroke', 'black')
.attr('x1', 5)
.attr('y1', height -5 )
.attr('x2', 20)
.attr('y2', height - 20);
Source: stackoverflow.com
Related Query
- draw a straight line between 2 coordinates in d3
- How to draw straight line in d3.js (horizontally and vertically)
- How to draw a line / link between two points on a D3 map based on latitude / longitude?
- Draw line between two points in JavaScript?
- How to draw line automatically by reading coordinates from file?
- Draw line between rectangle from border to border
- D3 js - is it possible to draw straight lines between tree nodes?
- How to draw a line dynamically between two circles
- d3: Calculate midpoint of line between two nodes, draw line extending at 90 degree angle from it to a new node
- Is it possible to draw an equation based straight line in D3?
- Draw a line between points
- Draw curve line between nodes bugs in d3.js
- how to draw a line between two axes with a data? (d3.js)
- How can I draw a line between rotate and non-rotate rectangle?
- Multiple straight line between two node in d3.js
- How to draw line with arrow using d3.js
- D3 - Difference between basis and linear interpolation in SVG line
- Draw a vertical line representing the current date in d3 gantt chart
- D3.js: draw simple, updatable line graph?
- How to draw a *simple* line segment with d3.js?
- How to draw logarithmic line charts with nvd3
- Draw curve between two points using diagonal function in d3 js
- Draw the line use the same y values, plots line at the bottom
- How to draw lines between circles?
- draw a line from one circle to another in d3.js
- SVG: adding shadow filter makes straight line invisible
- how do you draw linear line in scatter plot with d3.js
- Draw D3 Simple Line chart With an Array
- D3 force layout: Straight line instead of curve for links (but only for some links)
- How to use linkRadial to draw a link between two points?
More Query from same tag
- Unable to load json file in html using d3.js
- Custom context menu in d3 and svg
- Using google fonts with d3.js and SVG
- How to freeze and unfreeze hover line on click in D3
- QlikView with D3
- How do I send javascript parameters to DOM elements in from HTML table cells?
- multi-ring pie chart using d3js
- How to increase separation between several nodes in D3.js and color them?
- D3: How do you highlight a range of dates on D3 a line chart?
- Javascript: How to find max N timestamps in time interval from timestamp array
- how to use .scale and .translate with d3.js?
- d3.scale.linear() returns NaN
- zoomable d3 line chart has disappearing data
- can you set .mouseZoomable(true) and .brush(true) for ordinal dc.js barChart?
- d3 bars needs to move from bottom to up
- D3 Zoomable Circle Packing in IE11 is expanding beyond the SVG boundary
- Tooltip always displaying the same value
- Handling Mouse Events in Overlapping SVG Layers
- Adding a label to a path with D3
- How to tune horizontal node position in d3 sankey.js?
- How to create a common area between elements in d3.js?
- d3.js Changing gridlines and blocks to be evenly spaced
- How can I toggle the value of an svg text element with D3.js when user clicks the text?
- D3: Stacked bar chart exit().remove() not removing bars
- D3 V4 multi-line chart with Angular-cli
- The bar in the d3 graph is going out of range and i am not able to select it using a brush
- Importing d3.js in angular 2 project not working
- D3 Pie chart not showing legend
- d3 js expandable and collapsable tree structure
- typescript: Attr() function of d3 objects not accepting object / function