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")
chartAPI¶
Traits¶
| Trait | Type | Default | Description |
|---|---|---|---|
chart_type | Unicode | 'line' | Default series type (line, scatter, bar, …). |
series_data | List | — | The chart series (use add_series/update_series/clear_series). |
chart_options | Dict | — | Extra Chart.js options, deep-merged into the defaults. |
width | Int | 800 | Width in pixels. |
height | Int | 400 | Height in pixels. |
title | Unicode | '' | Chart title. |
x_label | Unicode | '' | X-axis title. |
y_label | Unicode | '' | Y-axis title. |
animation_enabled | Bool | True | Animate chart updates. |
tooltips_enabled | Bool | True | Show hover tooltips. |
legend_enabled | Bool | True | Show the legend. |
clicked_point | Dict | — | Written from JS on click: {series, index, x, y, label}. |
hover_point | Dict | — | Written from JS on hover: {series, index, x, y, label}. |
widget_id | Unicode | '' | Stable unique id used for cross-widget linking (auto-assigned). |
Methods¶
| Method | Description |
|---|---|
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"))