Generating Multiple Chart Types from a Single Dataset
How DataStoryBot's Code Interpreter selects the right chart type — bar, line, scatter, heatmap — based on data shape and story angle, and how to influence the choice.
Generating Multiple Chart Types from a Single Dataset
The same dataset can tell different stories depending on how you visualize it. Revenue over time is a line chart. Revenue by region is a bar chart. Revenue vs. marketing spend is a scatter plot. Revenue by region and quarter is a heatmap.
Most visualization tools make you choose the chart type upfront. DataStoryBot's Code Interpreter chooses for you — and it usually makes the right call, because the chart type decision is driven by the data shape and the story angle, not a menu selection.
This article explains how chart type selection works, what each type communicates, and how to influence the choice when the default isn't what you want.
How Code Interpreter Chooses
When DataStoryBot generates charts as part of analysis, the Code Interpreter evaluates:
-
Data dimensionality. One numeric variable → histogram. Two numeric variables → scatter. One categorical + one numeric → bar. Time + numeric → line.
-
The story angle. A trend story gets line charts. A comparison story gets bar charts. A correlation story gets scatter plots. The story angle (shaped by your steering prompt) influences the chart choice.
-
Data density. 10 categories → bar chart. 200 categories → the chart would be unreadable, so Code Interpreter aggregates first. 50,000 rows of time series → it downsamples before plotting.
-
Variable count. When the story involves multiple metrics, Code Interpreter may produce a small-multiples layout or a dual-axis chart rather than cramming everything into one plot.
This all happens in generated Python code. The Code Interpreter writes matplotlib or seaborn code, reasons about what visualization best fits the data it just analyzed, and renders the charts.
The Chart Types
Line Charts: Trends Over Time
Generated when: A datetime column exists and the story is about change over time.
{
"title": "Monthly Revenue Shows 23% Quarter-Over-Quarter Growth",
"chartFileId": "file-chart001"
}
The chart shows revenue on the y-axis, time on the x-axis, often with a trend line overlaid. For multi-series comparisons (revenue by region over time), you'll get multiple lines with a legend.
Line charts excel at showing: trends, seasonality, inflection points, before/after comparisons on a timeline.
Bar Charts: Categorical Comparisons
Generated when: The story compares groups and the x-axis is categorical (regions, product names, segments).
Variations:
- Vertical bars — standard comparison
- Horizontal bars — when category names are long
- Grouped bars — comparing multiple metrics per category
- Stacked bars — showing composition within each category
Bar charts excel at showing: rankings, group comparisons, composition, category-level performance.
Scatter Plots: Relationships Between Variables
Generated when: The story is about correlation between two continuous variables.
The Code Interpreter often adds:
- A regression line showing the overall trend
- Color coding by a categorical variable (e.g., points colored by region)
- Annotations on notable outlier points
Scatter plots excel at showing: correlations, clusters, outliers in two-dimensional space, non-linear relationships.
Histograms: Distribution Shape
Generated when: The story is about how values are distributed — spread, skewness, bimodality.
Common enhancements:
- Vertical lines marking mean and median
- Kernel density estimate (KDE) overlay for smooth distribution shape
- Multiple overlaid histograms for comparing distributions between groups
Histograms excel at showing: value distribution, outlier presence, skewness, bimodality, concentration.
Heatmaps: Two-Dimensional Patterns
Generated when: The story involves two categorical dimensions and a numeric value — or a correlation matrix.
Common uses:
- Correlation matrices between all numeric columns
- Revenue by region (rows) and quarter (columns)
- Activity by day-of-week and hour-of-day
Heatmaps excel at showing: patterns across two dimensions simultaneously, correlation matrices, temporal patterns (hour × day).
Box Plots: Distribution Comparison
Generated when: The story compares distributions across groups, not just averages.
Box plots show median, IQR, and outliers simultaneously across multiple categories. When you steer the analysis toward "compare distributions," you'll often get box plots instead of bar charts.
Influencing Chart Selection
The automatic selection is usually good. But when it's not, you have two levers:
1. Steering Prompt
Mention the chart type explicitly:
steering = (
"Analyze revenue distribution by region. "
"Use box plots to compare distributions, not bar charts — "
"I want to see the spread, not just the averages."
)
Or describe the visual format:
steering = (
"Show the correlation between marketing spend and signups "
"as a scatter plot with a regression line. Color the points "
"by acquisition channel."
)
Code Interpreter follows visualization instructions because they translate directly to matplotlib code. Saying "use a scatter plot" is as clear an instruction as "compute the mean."
2. Story Angle Selection
The chart type often follows from which story angle you select in the /refine step. An angle titled "Revenue Trends Over 12 Months" will produce line charts. An angle titled "Revenue Distribution by Customer Segment" will produce histograms or box plots.
If the /analyze response gives you an angle that naturally maps to your preferred chart type, select it.
Multiple Charts per Story
A single refined story typically includes 2-4 charts, often of different types:
{
"charts": [
{
"fileId": "file-chart001",
"caption": "Monthly revenue trend with year-over-year comparison"
},
{
"fileId": "file-chart002",
"caption": "Revenue distribution by product category"
},
{
"fileId": "file-chart003",
"caption": "Top 10 products by revenue contribution"
}
]
}
Chart 1 is a line chart (trend). Chart 2 is a histogram or box plot (distribution). Chart 3 is a horizontal bar chart (ranking). Three different chart types, all supporting the same narrative.
This happens because the Code Interpreter generates a complete analysis flow — and different aspects of the analysis call for different visualizations. The trend section gets a line chart, the breakdown section gets a bar chart, and so on.
Chart Styling
DataStoryBot's charts use a consistent dark-themed style:
- Dark background (#1a1a2e or similar) — optimized for slides and dashboards
- High-contrast colors — cyan, orange, magenta for data series
- Clean typography — clear axis labels, readable legends
- Publication-quality resolution — 150+ DPI
If you need light-themed charts or specific brand colors, mention it in the steering prompt:
steering = (
"Use a light background (white) for all charts with "
"the color palette: #2563eb (primary), #f59e0b (secondary), "
"#10b981 (tertiary). Use 12pt font for axis labels."
)
Code Interpreter translates color specifications directly into matplotlib parameters. Be specific — hex codes work better than color names for consistent results.
Complete Example: One Dataset, Four Chart Types
import requests
BASE_URL = "https://datastory.bot/api"
with open("ecommerce_orders.csv", "rb") as f:
upload = requests.post(f"{BASE_URL}/upload", files={"file": f})
container_id = upload.json()["containerId"]
# Analysis 1: Trend (line chart)
trend = requests.post(f"{BASE_URL}/analyze", json={
"containerId": container_id,
"steeringPrompt": "Show the revenue trend over time. Use a line chart."
})
# Analysis 2: Comparison (bar chart)
comparison = requests.post(f"{BASE_URL}/analyze", json={
"containerId": container_id,
"steeringPrompt": "Compare total revenue across product categories. Use a bar chart."
})
# Analysis 3: Correlation (scatter plot)
correlation = requests.post(f"{BASE_URL}/analyze", json={
"containerId": container_id,
"steeringPrompt": "Show the relationship between order value and shipping time as a scatter plot."
})
# Analysis 4: Distribution (histogram)
distribution = requests.post(f"{BASE_URL}/analyze", json={
"containerId": container_id,
"steeringPrompt": "Show the distribution of order values as a histogram with a KDE overlay."
})
Four analyses, one upload. Each produces charts of the specified type. The container's 20-minute TTL gives you plenty of time for multiple analyses.
When Automatic Selection Goes Wrong
Occasionally, Code Interpreter makes a suboptimal chart choice:
Bar chart with 50+ categories — unreadable. Solution: steer it to show "top 15" or "aggregate into larger groups."
Line chart for non-temporal data — connecting unrelated points with lines implies continuity that doesn't exist. Solution: specify "scatter plot" or "bar chart" in the steering prompt.
Pie chart — Code Interpreter occasionally generates pie charts. They're almost always worse than bar charts for comparison. If you get a pie chart and don't want one, steer it: "Use bar charts, not pie charts."
Missing chart for important findings — sometimes the narrative mentions a pattern but doesn't generate a supporting chart. Run a follow-up analysis with explicit chart instructions.
What to Read Next
For the foundational guide on chart generation, see how to generate charts from CSV data automatically.
For styling and branding chart output, read about dark-theme data visualization.
For embedding charts into your application, see how to download and embed AI-generated charts.
Or experiment in the DataStoryBot playground — upload a dataset and watch how different steering prompts produce different chart types from the same data.
Ready to find your data story?
Upload a CSV and DataStoryBot will uncover the narrative in seconds.
Try DataStoryBot →