Skip to content

Drawing Lines

Defining Lines

Lines can either be defined by a slope and a y-intercept, or by two points.

To draw a line using slope and y-intercept, use the slope and y-intercept props:

-5-4-3-2-1012345543210-1-2-3-4-5
Code
vue
<template>
  <Graph>
    <Line :slope="-2" :y-intercept="2" />
  </Graph>
</template>

To draw a line segment using two points, use the from and to props:

-5-4-3-2-1012345543210-1-2-3-4-5
Code
vue
<template>
  <Graph>
    <Line :from="[-2, -4]" :to="[3, 3]" />
  </Graph>
</template>

INFO

When defining lines, you should either use the slope and y-intercept props, or the from and to props. Using both will prefer from and to.

Props

NameTypeDefaultDescription
fromPossibleVector2[0,0]The starting point of the line.
toPossibleVector2noneThe ending point of the line.
slopenumbernoneThe slope of the line.
y-interceptnumbernoneThe y-intercept of the line.
line-widthnumber1.75The width of the line.
colorstring#000The color of the line.
dashedbooleanfalseWhether the line should be dashed.
labelstringnoneThe label of the line.

Examples

Basic Line with Slope and Y-Intercept

-5-4-3-2-1012345543210-1-2-3-4-5
Code
vue
<template>
  <Graph>
    <Line :slope="-2" :y-intercept="2" />
  </Graph>
</template>

Line Segment Between Two Points

-5-4-3-2-1012345543210-1-2-3-4-5
Code
vue
<template>
  <Graph>
    <Line :from="[-2, -4]" :to="[3, 3]" />
  </Graph>
</template>

Line with a Label

-5-4-3-2-1012345543210-1-2-3-4-5y = -2x+2
Code
vue
<template>
  <Graph>
    <Line :slope="-2" :y-intercept="2" label="y = -2x+2" />
  </Graph>
</template>

Complex Example

-5-4-3-2-1012345543210-1-2-3-4-5(-∞,1)[1,∞)
Code
vue
<template>
  <Graph>
    <Line
      :from="[-5, -1.5]"
      :to="[0.9, -1.5]"
      label="(-∞,1)"
      label-size="normal"
      dashed
    />
    <Line :from="[1, 1]" :to="[5, 5]" label="[1,∞)" label-size="normal" />
    <Point :position="[1, -1.5]" :filled="false" />
    <Point :position="[1, 1]" />
  </Graph>
</template>