Skip to content
On this page

Charts > Line chart ​

A line chart is a graphical representation of data, where points are connected by straight lines to display trends or variations in values over a continuous interval.

The Chart ​

Download example CSV
Copy HTML

Playground ​

Data

Number of lines
Index of reference dot position

Animation

Duration of animation in ms

Style

Color for each line
Pattern of dashes (stroke-dasharray) for each line (separate with dash)
Thickness of line
Easing curve (D3)
Show axis grid lines

Usage Example ​

vue
<template>
  <LineChart :key="key" :data="data" @hover="lineHover" :hover-num="hover" />
</template>

<script setup>
const hover = ref(null);
const lineHover = (e) => {
  if (e) hover.value = e.i;
  else hover.value = null;
};
</script>

Component API ​

The line chart is built with SVG and can show multiple lines. On hover you see a reference line and dot on the nearest data point.

Data ​

js
[
  [
    { name: "2008", value: 0 },
    { name: "2009", value: 30 },
    { name: "2010", value: 20 },
  ],
  ...
]

Props ​

NameDefaultDescriptionType
data[]The datasetArray
scalescaleLinearScale type for the y-axisString
color[]Color for each lineArray
defaultColor#9CA3AFDefault line colorString
highlightColor#374151Color of the highlightString
highlightStrokeWidth2Width of the stroke for highlighted linesNumber
verticalLineColor#cbd5e1Color of the vertical lineString
strokeWidth2Line thicknessNumber
verticalLineStrokeWidth1Width of the vertical lineNumber
dotRadius4Radius of the dotsNumber
curvecurveLinearCurve style for the lineString
showLastPointtrueAlways shows the last data pointBoolean
showXAxistrueShows the x-axisBoolean
xAxisStylefalseChanges the x-axis styleBoolean
showYAxistrueShows the y-axisBoolean
yAxisStylefalseChanges the y-axis styleBoolean
datasetStrokeDasharray["1", "5,5"]Use dashes for some lines in the datasetArray
hoverNumnullIndex of hovered data point[Number, null]
margin{ top: 0, right: 0, bottom: 15, left: 40 }Margin around the chartObject
padding{ top: 0, right: 0, bottom: 0, left: 0 }Padding of the chartObject
rangenullRange of the chartArray
referenceDotnullIndex of reference dot on the lineNumber
refDotRadius4Radius of reference dot on the lineNumber
refDotColor#E5E7EBColor of reference dot on the lineString
zeroLinefalseShow horizontal axis line at y value 0Boolean
textColor#9CA3AFColor of textString
labelsnullLabels to showArray
showVerticalLineAtStartfalseShow vertical line at the startBoolean
showOnlyMainDotfalseShow only the main dotBoolean
highlightednullIndex of highlighted data pointNumber
duration250Duration of the animation in msNumber
forceZerofalseForce the y-axis to start from zeroBoolean
defaultRaisedIndexnullIndex of the default raised lineNumber
yAxisUnit""Unit for y-axis labelsString
showHoverLinetrueShow hover lineBoolean
highlightedIndexes[]Indexes of highlighted data pointsArray
showYGridfalseShow the gridBoolean
showDataDotsfalseShow a dot on each data pointBoolean
useTooltipsfalseShow a label when hovering data pointBoolean

Events ​

EventArgumentDescription
@hover{ target, data }Emitted when line is hovered

Dependencies ​

  • d3