Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Chart

An interactive charting widget powered by Chart.js.

Import

from manywidgets import Chart

Example

import numpy as np
from manywidgets import Chart

x = np.linspace(0, 10, 200)
chart = Chart(title="A sine wave", x_label="x", y_label="y", height=320)
chart.add_series(x=x, y=np.sin(x), name="sin")
chart.add_series(x=x, y=np.cos(x), name="cos")
chart

API

Traits

TraitTypeDefaultDescription
chart_typeUnicode'line'Default series type (line, scatter, bar, …).
series_dataListThe chart series (use add_series/update_series/clear_series).
chart_optionsDictExtra Chart.js options, deep-merged into the defaults.
widthInt800Width in pixels.
heightInt400Height in pixels.
titleUnicode''Chart title.
x_labelUnicode''X-axis title.
y_labelUnicode''Y-axis title.
animation_enabledBoolTrueAnimate chart updates.
tooltips_enabledBoolTrueShow hover tooltips.
legend_enabledBoolTrueShow the legend.
clicked_pointDictWritten from JS on click: {series, index, x, y, label}.
hover_pointDictWritten from JS on hover: {series, index, x, y, label}.
widget_idUnicode''Stable unique id used for cross-widget linking (auto-assigned).

Methods

MethodDescription
add_series(x=, y=, data=, series_type=, name=, color=, **opts)Append a series ([[x, y], …] or separate x/y; numpy ok).
update_series(index, x=, y=, data=)Replace a series’ data.
clear_series()Remove all series.
set_options(**options)Merge extra Chart.js options.

Linking

Link like any widget (see the linking guide):

from ipywidgets import jsdlink
from manywidgets import Chart, Dropdown

chart = Chart()
kind = Dropdown(options=["line", "bar", "scatter"], value="line")
jsdlink((kind, "value"), (chart, "chart_type"))