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

API

Traits

TraitTypeDefaultDescription
chart_typeUnicode'line'Default series type (line, scatter, bar, …).
series_dataList—The chart series (use add_series/update_series/clear_series).
chart_optionsDict—Extra 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_pointDict—Written from JS on click: {series, index, x, y, label}.
hover_pointDict—Written 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"))