Skip to main content
Glama

plot_line_chart

Generate line charts from Teradata data by specifying table columns for x-axis labels and y-axis values to visualize trends and patterns.

Instructions

Function to generate a line plot for labels and columns. Columns mentioned in labels are used for x-axis and columns are used for y-axis.

PARAMETERS: table_name: Required Argument. Specifies the name of the table to generate the donut plot. Types: str

labels: Required Argument. Specifies the labels to be used for the line plot. Types: str columns: Required Argument. Specifies the column to be used for generating the line plot. Types: List[str]

RETURNS: dict

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
columnsYes
labelsYes
table_nameYes

Implementation Reference

  • Handler function execute_plot_line_chart for the plot_line_chart tool. It validates input parameters and calls the helper get_plot_json_data to generate Chart.js line chart data from Teradata table.
    def handle_plot_line_chart(conn: TeradataConnection, table_name: str, labels: str, columns: str|List[str]): """ Function to generate a line plot for labels and columns. Columns mentioned in labels are used for x-axis and columns are used for y-axis. PARAMETERS: table_name: Required Argument. Specifies the name of the table to generate the donut plot. Types: str labels: Required Argument. Specifies the labels to be used for the line plot. Types: str columns: Required Argument. Specifies the column to be used for generating the line plot. Types: List[str] RETURNS: dict """ # Labels must be always a string which represents a column. if not isinstance(labels, str): raise ValueError("labels must be a string representing the column name for x-axis.") return get_plot_json_data(conn, table_name, labels, columns)
  • Helper function get_plot_json_data that executes SQL query on Teradata table, processes data into labels and datasets, formats for Chart.js line chart, and returns structured JSON response.
    def get_plot_json_data(conn, table_name, labels, columns, chart_type='line'): """ Helper function to fetch data from a Teradata table and formats it for plotting. Right now, designed only to support line plots from chart.js . """ # Define the colors first. colors = ['rgb(75, 192, 192)', '#99cbba', '#d7d0c4', '#fac778', '#e46c59', '#F9CB99', '#280A3E', '#F2EDD1', '#689B8A'] # Chart properties. Every chart needs different property for colors. chart_properties = {'line': 'borderColor', 'polar': 'backgroundColor', 'pie': 'backgroundColor'} columns = [columns] if isinstance(columns, str) else columns sql = "select {labels}, {columns} from {table_name} order by {labels}".format( labels=labels, columns=','.join(columns), table_name=table_name) # Prepare the statement. with conn.cursor() as cur: recs = cur.execute(sql).fetchall() # Define the structure of the chart data. Below is the structure expected by chart.js # { # labels: labels, # datasets: [{ # label: 'My First Dataset', # data: [65, 59, 80, 81, 56, 55, 40], # fill: false, # borderColor: 'rgb(75, 192, 192)', # tension: 0.1 # }] # } labels = [] datasets = [[] for _ in range(len(columns))] for rec in recs: labels.append(rec[0]) for i_, val in enumerate(rec[1:]): datasets[i_].append(val) # Prepare the datasets for chart.js datasets_ = [] for i, dataset in enumerate(datasets): datasets_.append({ 'label': columns[i], 'data': dataset, 'borderColor': colors[i], 'fill': False }) # For polar plot, every dataset needs different colors. if chart_type in ('polar', 'pie'): for i, dataset in enumerate(datasets_): # Remove borderColor and add backgroundColor dataset.pop('borderColor', None) dataset['backgroundColor'] = colors chart_data = {"labels": [str(l) for l in labels], "datasets": datasets_} logger.debug("Chart data: %s", json.dumps(chart_data, indent=2)) return create_response(data=chart_data, metadata={ "tool_description": "chart js {} plot data".format(chart_type), "table_name": table_name, "labels": labels, "columns": columns })
  • The 'plot' module containing plot_line_chart tool is mapped in MODULE_MAP for dynamic lazy-loading based on config profiles.
    # Map tool prefixes to their corresponding module paths MODULE_MAP = { 'base': 'teradata_mcp_server.tools.base', 'dba': 'teradata_mcp_server.tools.dba', 'fs': 'teradata_mcp_server.tools.fs', 'qlty': 'teradata_mcp_server.tools.qlty', 'rag': 'teradata_mcp_server.tools.rag', 'sql_opt': 'teradata_mcp_server.tools.sql_opt', 'sec': 'teradata_mcp_server.tools.sec', 'tmpl': 'teradata_mcp_server.tools.tmpl', 'plot': 'teradata_mcp_server.tools.plot', 'tdvs': 'teradata_mcp_server.tools.tdvs' }
  • Imports all functions from plot_tools.py making handle_plot_line_chart available at module level for discovery.
    from .plot_tools import *

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/blitzstermayank/MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server