Line Chart

Overview

A line chart is a chart that shows information as a series of data points connected by straight line segments.

The line chart is very common in many fields. As a rule, it is used to emphasize trends in data over equal time intervals, such as months, quarters, fiscal years, and so on.

This article explains how to create a basic Line chart as well as configure settings that are specific to the type. You can also see the table below to get a brief overview of the Line chart's characteristics:

ModulesCore + Basic Cartesian / Base
API
Classanychart.core.cartesian.series.Line
DATA
Data Fieldsx, value
Multiple SeriesYES
OPTIONS
StackedN/A
VerticalVertical Line
3DN/A
Error BarsLine Chart with Error Bars
SUPPORTED CHART PLOTS
PolarPolar Line, Polyline
RadarRadar Line
ScatterScatter Line
StockStock Line
RELATED TYPES
Spline
Step Line
Jump Line
Line Sparkline
Polyline
SEE ALSO
Chartopedia: Line Chart
General Settings

Modules

The Line chart requires adding the Core and Basic Cartesian modules:

<script src="https://cdn.anychart.com/releases/8.13.0/js/anychart-core.min.js"></script>
<script src="https://cdn.anychart.com/releases/8.13.0/js/anychart-cartesian.min.js"></script>

Alternatively, you can use the Base module, which includes, among other things, the two modules mentioned above:

<script src="https://cdn.anychart.com/releases/8.13.0/js/anychart-base.min.js"></script>

Learn more: Modules.

Quick Start

To create a Line chart, use the anychart.line() chart constructor. If you pass the data to this chart constructor, it creates a line series.

To create a Line series explicitly, call the line() method.

The following sample demonstrates how a basic Line chart is created:

// create data
var data = [
  ["January", 10000],
  ["February", 12000],
  ["March", 18000],
  ["April", 11000],
  ["May", 9000]
];
    
// create a chart
chart = anychart.line();

// create a line series and set the data
var series = chart.line(data);

// set the container id
chart.container("container");

// initiate drawing the chart
chart.draw();

Playground

General Settings

In AnyChart there are many settings that are configured in the same way for all chart types, including the Line chart (for example, legend and interactivity settings).

Read the overview of general settings: General Settings.

Special Settings

Appearance

The appearance settings of a Line chart can be configured in three states: normal, hover, and selected. Use the normal(), hovered(), and selected() methods.

Combine them with the stroke() method. Also, you can use some other methods from anychart.core.StateSettings.

In the sample below, there are two Line series with appearance settings configured:

// create the first series
var series1 = chart.line(seriesData_1);

// configure the visual settings of the first series
series1.normal().stroke("#00cc99", 1, "10 5", "round");
series1.hovered().stroke("#00cc99", 2, "10 5", "round");
series1.selected().stroke("#00cc99", 4, "10 5", "round");

// create the second series
var series2 = chart.line(seriesData_2);

// configure the visual settings of the second series
series2.normal().stroke("#0066cc");
series2.hovered().stroke("#0066cc", 2);
series2.selected().stroke("#0066cc", 4);

Playground

Labels

Labels are text or image elements that can be placed anywhere on any chart (you can enable them on a whole series or in a single point). For text labels, font settings and text formatters are available.

Tooltips

A Tooltip is a text box displayed when a point on a chart is hovered over. There is a number of visual and other settings available: for example, you can edit the text by using font settings and text formatters, change the style of background, adjust the position of a tooltip, and so on.

Scales

When Line chart is used with the ordinal scale and you wish to remove the gaps to the right and left of the line you need to change the ordinal scale mode to 'continuous':

chart.xScale().mode('continuous');

Playground

Vertical Line

Most types of series in AnyChart can be drawn both in horizontal and vertical orientation: Vertical Charts.

Here is information about creating Vertical Line series: