Appearance
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
| Name | Default | Description | Type |
|---|---|---|---|
| data | [] | The dataset | Array |
| scale | scaleLinear | Scale type for the y-axis | String |
| color | [] | Color for each line | Array |
| defaultColor | #9CA3AF | Default line color | String |
| highlightColor | #374151 | Color of the highlight | String |
| highlightStrokeWidth | 2 | Width of the stroke for highlighted lines | Number |
| verticalLineColor | #cbd5e1 | Color of the vertical line | String |
| strokeWidth | 2 | Line thickness | Number |
| verticalLineStrokeWidth | 1 | Width of the vertical line | Number |
| dotRadius | 4 | Radius of the dots | Number |
| curve | curveLinear | Curve style for the line | String |
| showLastPoint | true | Always shows the last data point | Boolean |
| showXAxis | true | Shows the x-axis | Boolean |
| xAxisStyle | false | Changes the x-axis style | Boolean |
| showYAxis | true | Shows the y-axis | Boolean |
| yAxisStyle | false | Changes the y-axis style | Boolean |
| datasetStrokeDasharray | ["1", "5,5"] | Use dashes for some lines in the dataset | Array |
| hoverNum | null | Index of hovered data point | [Number, null] |
| margin | { top: 0, right: 0, bottom: 15, left: 40 } | Margin around the chart | Object |
| padding | { top: 0, right: 0, bottom: 0, left: 0 } | Padding of the chart | Object |
| range | null | Range of the chart | Array |
| referenceDot | null | Index of reference dot on the line | Number |
| refDotRadius | 4 | Radius of reference dot on the line | Number |
| refDotColor | #E5E7EB | Color of reference dot on the line | String |
| zeroLine | false | Show horizontal axis line at y value 0 | Boolean |
| textColor | #9CA3AF | Color of text | String |
| labels | null | Labels to show | Array |
| showVerticalLineAtStart | false | Show vertical line at the start | Boolean |
| showOnlyMainDot | false | Show only the main dot | Boolean |
| highlighted | null | Index of highlighted data point | Number |
| duration | 250 | Duration of the animation in ms | Number |
| forceZero | false | Force the y-axis to start from zero | Boolean |
| defaultRaisedIndex | null | Index of the default raised line | Number |
| yAxisUnit | "" | Unit for y-axis labels | String |
| showHoverLine | true | Show hover line | Boolean |
| highlightedIndexes | [] | Indexes of highlighted data points | Array |
| showYGrid | false | Show the grid | Boolean |
| showDataDots | false | Show a dot on each data point | Boolean |
| useTooltips | false | Show a label when hovering data point | Boolean |
Events
| Event | Argument | Description |
|---|---|---|
@hover | { target, data } | Emitted when line is hovered |
Dependencies
- d3