Use this file to discover all available pages before exploring further.
E2B also allows you to create interactive charts with custom styling.E2B automatically detects charts when executing Python code with runCode() in JavaScript or run_code() in Python. The Python code must include Matplotlib charts.When a chart is detected, E2B sends the data of the chart back to the client. You can access the chart in the execution.results array where each item is a Result object with the chart property.
Try out AI Data Analyst - a Next.js app that uses E2B to create interactive charts.
Here’s a simple example of bar chart:
import { Sandbox, BarChart } from '@e2b/code-interpreter'const code = `import matplotlib.pyplot as plt# Prepare dataauthors = ['Author A', 'Author B', 'Author C', 'Author D']sales = [100, 200, 300, 400]# Create and customize the bar chartplt.figure(figsize=(10, 6))plt.bar(authors, sales, label='Books Sold', color='blue')plt.xlabel('Authors')plt.ylabel('Number of Books Sold')plt.title('Book Sales by Authors')# Display the chartplt.tight_layout()plt.show()`const sandbox = await Sandbox.create()const result = await sandbox.runCode(code)const chart = result.results[0].chart as BarChartconsole.log('Type:', chart.type)console.log('Title:', chart.title)console.log('X Label:', chart.x_label)console.log('Y Label:', chart.y_label)console.log('X Unit:', chart.x_unit)console.log('Y Unit:', chart.y_unit)console.log('Elements:', chart.elements)