简体   繁体   English

如何在d3.js中绘制直线(水平和垂直)

[英]How to draw straight line in d3.js (horizontally and vertically)

I have doubts in drawing the line graph concept. 我对绘制线图概念有疑问。 Can anybody explain these coordinates? 任何人都可以解释这些坐标吗?

x1=5,x2=10,y1=10,y2=30

Please explain each attribute and what it represents. 请解释每个属性及其代表的含义。 Also, please give me an idea about drawing a straight line vertically and also horizontally (like a cross-hair). 另外,请给我一个关于垂直和水平画直线(如十字线)的想法。

I am total newbie to d3.js graphs, so please help me. 我是d3.js图表​​的全新手,所以请帮助我。 Any help would be appreciated. 任何帮助,将不胜感激。

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. x1:从屏幕左侧开始测量的第一行的x位置。
  • y1: The y position of the first end of the line as measured from the top of the screen. y1:从屏幕顶部开始测量的第一行的y位置。
  • x2: The x position of the second end of the line as measured from the left of the screen. x2:从屏幕左侧开始测量的第二行的x位置。
  • y2: The y position of the second end of the line as measured from the top of the screen. y2:从屏幕顶部开始测量的第二行的y位置。

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). 该线从点100,50延伸到300,150(x1,y1到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. 要绘制一条线,我们需要两个点,如果我们想要引用我们使用坐标的任何点,在图中,(x1,y1)是一条线的起点(x2,y2)是一条线的终点,这两点是相互联系的。

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 要在图形中绘制网格,请参阅此链接http://www.d3noob.org/2013/01/adding-grid-lines-to-d3js-graph.html如果您不理解,请询问.Okay

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM