Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Line Chart

Signature

sp.build_line_chart(
    title: str,
    labels: list[str],
    values: list[float],
    *,
    color_hex: int = 0x6366F1,
    show_points: bool = True,
    width: int = 900,
    height: int = 480,
    x_label: str = "",
    y_label: str = "",
    gridlines: bool = False,
    sort_order: str = "none",
    hover_json: str = "",
    legend_position: str = "right",
    palette: list[int] | None = None,
    background: str | None = None,
    no_x_axis: bool = False,
    no_y_axis: bool = False,
) -> Chart

Aliases: sp.line, sp.line_chart


Description

Single-series line chart with optional data points.

For multiple series, use build_multiline_chart.


Parameters

ParameterTypeDefaultDescription
titlestrrequiredChart title
labelslist[str]requiredX-axis labels
valueslist[float]requiredY values
color_hexint0x6366F1Line color as hex int (indigo by default)
show_pointsboolTrueDraw circles at data points
gridlinesboolFalseHorizontal gridlines
sort_orderstr"none""asc", "desc", "none"
widthint900Width in pixels
heightint480Height in pixels

Returns

Chart


Examples

Time series

import seraplot as sp
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
          "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
revenue = [1200.0, 1350.0, 1100.0, 1600.0, 1800.0, 2100.0,
           1950.0, 2300.0, 2000.0, 2500.0, 2200.0, 2800.0]
logo = "https://raw.githubusercontent.com/feur25/seraplot-documentation/main/logo.png"
hover = sp.build_hover_json(months, images=[logo] * len(months))
chart = (
    sp.build_line_chart(
        "Annual Revenue",
        labels=months,
        values=revenue,
        x_label="Month",
        y_label="Revenue (€)",
        gridlines=True,
        color_hex=0x22d3ee,
        hover_json=hover,
    )
    .set_bg(None)
    .show_grid()
)
const sp = require('seraplot');
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
          "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
const revenue = [1200.0, 1350.0, 1100.0, 1600.0, 1800.0, 2100.0,
           1950.0, 2300.0, 2000.0, 2500.0, 2200.0, 2800.0]
const logo = "https://raw.githubusercontent.com/feur25/seraplot-documentation/main/logo.png"
const hover = sp.build_hover_json(months,
[logo])
const chart = (
    sp.build_line_chart("Annual Revenue",
months,
{
    values: revenue,
    x_label: "Month",
    y_label: "Revenue (€)",
    gridlines: true,
    color_hex: 0x22d3ee,
    hover_json: hover
})
    .set_bg(null)
    .show_grid()
)
import * as sp from 'seraplot';
const months: string[] = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
          "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
const revenue: number[] = [1200.0, 1350.0, 1100.0, 1600.0, 1800.0, 2100.0,
           1950.0, 2300.0, 2000.0, 2500.0, 2200.0, 2800.0]
const logo: string = "https://raw.githubusercontent.com/feur25/seraplot-documentation/main/logo.png"
const hover = sp.build_hover_json(months,
[logo])
const chart = (
    sp.build_line_chart("Annual Revenue",
months,
{
    values: revenue,
    x_label: "Month",
    y_label: "Revenue (€)",
    gridlines: true,
    color_hex: 0x22d3ee,
    hover_json: hover
})
    .set_bg(null)
    .show_grid()
)
▶ Live Preview

See also

  • Multi-linesp.build_multiline_chart() for multiple series
  • Area Chartsp.build_area_chart()

Signature

sp.build_line_chart(
    title: str,
    labels: list[str],
    values: list[float],
    *,
    color_hex: int = 0x6366F1,
    show_points: bool = True,
    width: int = 900,
    height: int = 480,
    x_label: str = "",
    y_label: str = "",
    gridlines: bool = False,
    sort_order: str = "none",
    hover_json: str = "",
    legend_position: str = "right",
    palette: list[int] | None = None,
    background: str | None = None,
    no_x_axis: bool = False,
    no_y_axis: bool = False,
) -> Chart

Aliases: sp.line, sp.line_chart


Description

Graphique en courbe simple avec points de données optionnels.

Pour plusieurs séries, utilisez build_multiline_chart.


Paramètres

ParamètreTypeDéfautDescription
titlestrrequisTitre du graphique
labelslist[str]requisÉtiquettes de l'axe X
valueslist[float]requisValeurs Y
color_hexint0x6366F1Couleur de la courbe (hex int)
show_pointsboolTrueDessiner des cercles aux points de données
gridlinesboolFalseLignes de grille horizontales
sort_orderstr"none""asc", "desc" ou "none"
widthint900Largeur en pixels
heightint480Hauteur en pixels

Retourne

Chart


Exemples

import seraplot as sp

mois = ["Jan", "Fév", "Mar", "Avr", "Mai", "Jun",
        "Jul", "Aoû", "Sep", "Oct", "Nov", "Déc"]
revenu = [1200.0, 1350.0, 1100.0, 1600.0, 1800.0, 2100.0,
          1950.0, 2300.0, 2000.0, 2500.0, 2200.0, 2800.0]

chart = (
    sp.build_line_chart(
        "Chiffre d'affaires annuel",
        labels=mois,
        values=revenu,
        x_label="Mois",
        y_label="Chiffre d'affaires (€)",
        gridlines=True,
        color_hex=0x22d3ee,
    )
    .set_bg(None)
)

Voir aussi