🏠 back to Observable

Import a chart into another chart?


#1

I’ve been studying this example of how to embed a D3 chart in a tooltip of another D3 chart.

Given that Observable allows to you import a chart from another notebook. (e.g.
import {chart as histogram} with {histogram_data as data} from "@mbostock/d3-histogram"), is it possible to use import to embed one chart into another, rather than writing the D3 for both all in one cell?


#2

Hey Bob,

Yep, when you import a chart like in that example - {chart as histogram}, you can also embed it in another graphic if you’d like.

In that example, histogram is an HTML node - an SVG element that is the chart. So you can append it inside of another visualization if you want, instead of making it the main value of a cell.

Here’s an admitted contrived example of showing a chart inside of itself with an import: https://beta.observablehq.com/d/912a3450b2f78000