At Nimbus Analytics, analysts want a simple helper that recommends clear chart types for exploratory data analysis. Given metadata about dataset columns and optional analysis goals, write a function that returns the most appropriate chart recommendation for each request.
Implement a function that takes:
columns: a list of dictionaries, where each dictionary has:
name: string column nametype: one of "numeric", "categorical", "datetime", "boolean"unique_count: non-negative integerrequests: a list of dictionaries, where each dictionary has:
columns: list of 1 or 2 column namesgoal: one of "distribution", "comparison", "relationship", "trend", "composition"Return a list of chart names, one per request, using these rules:
"histogram""bar""line""scatter""bar""line""stacked_bar""table"If a request references an unknown column, return "invalid" for that request.
Example 1
Input: columns = [{"name":"age","type":"numeric","unique_count":40}], requests = [{"columns":["age"],"goal":"distribution"}]
Output: ["histogram"]
Explanation: A single numeric variable is best shown with a histogram for distribution.
Example 2
Input: columns = [{"name":"date","type":"datetime","unique_count":365},{"name":"sales","type":"numeric","unique_count":200}], requests = [{"columns":["date","sales"],"goal":"trend"}]
Output: ["line"]
Explanation: A time variable paired with a numeric measure is best shown as a line chart.
1 <= len(columns) <= 10^41 <= len(requests) <= 10^4