A line is a simple line between two points and is described by four required attributes.
- x1: The x position of the first end of the line as measured from the left of the screen.
- y1: The y position of the first end of the line as measured from the top of the screen.
- x2: The x position of the second end of the line as measured from the left of the screen.
- y2: The y position of the second end of the line as measured from the top of the screen.
The following is an example of the code section required to draw a line;
holder.append("line") // attach a line .style("stroke", "black") // colour the line .attr("x1", 100) // x position of the first end of the line .attr("y1", 50) // y position of the first end of the line .attr("x2", 300) // x position of the second end of the line .attr("y2", 150); // y position of the second end of the line
This will produce a line as follows;
The line extends from the point 100,50 to 300,150 (x1,y1 to x2,y2).
You can see it in more context here.
This doesn't cover the cross-hair example, but once you understand the part above it should be clearer.
To draw a line we need TWO points, in a graph if we want to refer any point we use co-ordinates, (x1,y1) is the start point of a line (x2,y2) is the end point of a line, these two points are connected.
To draw a grid in graph refer this link http://www.d3noob.org/2013/01/adding-grid-lines-to-d3js-graph.html If you are not understanding, then ask.Okay
- How to draw straight line in d3.js (horizontally and vertically)
- How do you find the last data point in d3 and draw a circle and a line on it?
- How to display D3 Color legend horizontally and not vertically
- How can I draw a line between rotate and non-rotate rectangle?
- How to draw line with arrow using d3.js
- How to draw a line / link between two points on a D3 map based on latitude / longitude?
- How to draw a *simple* line segment with d3.js?
- How to draw logarithmic line charts with nvd3
- how do you draw linear line in scatter plot with d3.js
- How to hide and show points on a line graph
- Draw a map with D3.js: How to get the right scale() and translate()?
- How to create Stacked Line Chart D3, Multiple Y Axis and common X Axis
- How to draw a dynamic line chart based on an infotable?
- d3: how to move a vertical line in horizontal direction and support 'pause' and 'continue' movement
- How to draw growth rate line in dc.js barChart?
- how to draw nvd3 simple barchart with x and y axis in angularjs
- How to draw an ellipse from degree and coordinates
- How to draw D3 Map with United States, Canada, Mexico and Puerto Rico
- How can I draw compass shape in d3.js and colour each triangle differently?
- How to draw a rectangle with d3.js based on 2 diametrical points and no length or height values?
- D3- How do I draw dots on a multi line graph? (Iterate through array)
- How to draw line charts with complex data structures in d3
- How to position svg circles on a line and curve it?
- draw a straight line between 2 coordinates in d3
- How can I draw a pipe and make it interactive
- How to draw line automatically by reading coordinates from file?
- How can I make straight line instead of curve line in d3 force layout?
- How to plot a straight line in d3.js by user interaction
- How can I make a dynamic line between 2 elements not knowing their positions in x and y?
More Query from same tag
- Creating axis with custom (range) values
- How to solve duplicate label in zoom
- Is it possible to edit an svg:image styles in the browser? (using D3)
- D3: Stacked Bar Chart not parsing data correctly
- d3 gauge chart with labels and percentages?
- Let's make a map Topojson doesn't appear - no error msgs but nothing happens
- call(this.dragger) is not working, d3.drag()
- How to show c3.js No data but with legend for empty column?
- Angular D3 bar chart animation
- D3 force simulation graph, edges fail to render for larger datasets
- Displaying D3.js Chart with Django Backend
- d3 zoom - how to set initial transform
- Visualizing Array as value of a Crossfilter dimension
- Resize graph plotted in d3.js graph
- trying to get first child elements in d3.js at first load time
- D3.js Get Histogram / Bar column width
- how to get the type of a scale in D3?
- How to create elements depending on data in D3?
- making d3.js compatible with ie
- Why is initial drag position incorrect when using a scale?
- Trying to understand how log scale in d3.js works
- Using D3.js, How can I detect when a point on an animating line is reached?
- Zoom/pan in D3 with mouse anywhere in window
- d3 transition overlap causing odd behaviour
- D3 text for axis not showing
- Locale for axis nvd3.js
- Vary font size in tick labels of time axis
- D3.js how to extract Y domain value from data array with multiple Y axis columns
- D3.js category color scale not working properly