Skip to main content
Glama

Line Chart

render_line_chart
Read-onlyIdempotent

Render interactive line or area charts with multiple series, smooth curves, gradient fill, and customizable themes. Use for visualizing trends over time with annotations and style options.

Instructions

Render an interactive line or area chart. Supports smooth curves, gradient fill, and multiple series. Supports themes for styled visuals.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYesChart title
labelsYesX-axis labels (e.g. dates, categories)
datasetsYesOne or more data series
optionsNo
themeNoTheme preset: boardroom, corporate, sales-floor, golden-treasury, clinical, startup, ops-control, tokyo-midnight, zen-garden, consultant, black-tron, black-elegance, black-matrix, forest-amber, forest-earth, sky-light, sky-ocean, sky-twilight, gray-hf, gray-copilot
paletteNoOverride palette only (mix-and-match)
typographyNoOverride typography: professional, luxury, cyberpunk, editorial, mono, bold, system, techno
effectsNoOverride effects: none, subtle, shimmer, neon, energetic

Implementation Reference

  • The main handler function that renders a line chart using Chart.js. Creates a canvas-based line chart with configurable fill, smoothness, points, colors, annotations, and theme support. Also sets up click interaction, export/refresh buttons, and deferred resize handling.
    export function renderLineChart(container: HTMLElement, payload: LineData): void {
      const { title, labels, datasets, options } = payload;
      const shouldFill = options.fill !== false;
      const isSmooth = options.smooth !== false;
      const showPoints = options.showPoints === true;
    
      // Apply theme if specified
      const theme = resolveTheme(payload.theme, {
        palette: payload.palette,
        typography: payload.typography,
        effects: payload.effects,
      });
      if (theme) applyTheme(container, theme);
    
      container.innerHTML = `
        <div class="chart-view">
          <div class="card chart-card">
            <div class="chart-card__header">
              <div>
                <div class="chart-card__title${theme?.effects.shimmerTitle ? " shimmer-text" : ""}">${escapeHtml(title)}</div>
                <div class="chart-card__subtitle">${datasets.length} series - ${labels.length} points</div>
              </div>
            </div>
            <div class="chart-card__body">
              <canvas id="chart-canvas"></canvas>
            </div>
          </div>
        </div>
      `;
    
      const canvas = container.querySelector<HTMLCanvasElement>("#chart-canvas")!;
      const palette = resolveColors(options.colors, datasets.length);
    
      const chartInstance = new Chart(canvas, {
        type: "line",
        data: {
          labels,
          datasets: datasets.map((ds, i) => {
            const color = palette[i % palette.length];
            return {
              label: ds.label,
              data: ds.data,
              borderColor: color,
              borderWidth: 2,
              tension: isSmooth ? 0.4 : 0,
              fill: shouldFill,
              backgroundColor: (ctx: any) => {
                if (!shouldFill) return "transparent";
                const gradient = ctx.chart.ctx.createLinearGradient(
                  0, 0, 0, ctx.chart.height
                );
                gradient.addColorStop(0, color + "40");
                gradient.addColorStop(1, color + "00");
                return gradient;
              },
              pointRadius: showPoints ? 4 : 0,
              pointHoverRadius: 6,
              pointBackgroundColor: color,
              pointBorderColor: getCSSVar("--bg-card"),
              pointBorderWidth: 2,
              pointHoverBorderWidth: 2,
            };
          }),
        },
        options: {
          responsive: true,
          maintainAspectRatio: false,
          interaction: {
            mode: "index",
            intersect: false,
          },
          onClick: (_event, elements) => {
            if (elements.length === 0) return;
            const idx = elements[0].index;
            const label = labels[idx];
            const values = datasets.map((ds) => `${ds.label}: ${ds.data[idx]?.toLocaleString()}`).join(", ");
            sendClickMessage(`${label} (${values}) in "${title}"`);
          },
          scales: {
            x: {
              border: { display: false },
              grid: { display: false },
              ticks: { color: getCSSVar("--text-secondary"), font: { size: 11 } },
            },
            y: {
              border: { display: false },
              grid: {
                color: getCSSVar("--border"),
                drawTicks: false,
              },
              ticks: {
                color: getCSSVar("--text-secondary"),
                font: { size: 11 },
                padding: 8,
              },
            },
          },
          plugins: {
            legend: {
              display: datasets.length > 1,
              position: "top",
              align: "end",
              labels: {
                color: getCSSVar("--text-secondary"),
                boxWidth: 10,
                padding: 12,
                font: { size: 11 },
              },
            },
            tooltip: tooltipStyle(),
            annotation: buildAnnotations(options.annotations) ? { annotations: buildAnnotations(options.annotations) } : undefined,
          },
        },
      });
    
      deferResize(chartInstance);
      addExportButton(container, chartInstance, title);
      addRefreshButton(container, () => (window as any).__mcpRefresh?.());
    }
  • The LineData interface defines the input schema for renderLineChart: title, labels, datasets (with label + data array), options (fill, smooth, showPoints, colors, annotations), and optional theme/palette/typography/effects styling.
    interface LineData {
      title: string;
      labels: string[];
      datasets: Array<{ label: string; data: number[] }>;
      options: {
        fill?: boolean;
        smooth?: boolean;
        showPoints?: boolean;
        colors?: string[];
        annotations?: any[];
      };
      theme?: string;
      palette?: string;
      typography?: string;
      effects?: string;
    }
  • Registers the line chart under the type 'line' with the tool name 'render_line_chart' and the renderLineChart handler function. This is called as a side-effect when the module is imported.
    registerChart("line", "render_line_chart", renderLineChart);
  • Helper function that transforms raw data (object key-value pairs or array of objects with date/number keys) into the LineData format expected by renderLineChart. Used by the auto chart renderer when it detects a line chart is appropriate.
    function toLineData(title: string, data: any): Parameters<typeof renderLineChart>[1] {
      // Object {key: value} - treat keys as x-axis labels
      if (!Array.isArray(data) && typeof data === "object" && data !== null) {
        const flat = tryFlatten(data) as Record<string, any>;
        const entries = Object.entries(flat).filter(([, v]) => isNumeric(v));
        return {
          title,
          labels: entries.map(([k]) => k),
          datasets: [{ label: title, data: entries.map(([, v]) => Number(v)) }],
          options: {},
        };
      }
    
      const { dateKeys, numberKeys, stringKeys } = analyzeArray(data);
      const xKey = dateKeys[0] ?? stringKeys[0] ?? Object.keys(data[0])[0];
      const seriesKeys = numberKeys.length > 0
        ? numberKeys
        : Object.keys(data[0]).filter((k) => k !== xKey && isNumeric(data[0][k]));
    
      return {
        title,
        labels: data.map((row: any) => String(row[xKey] ?? "")),
        datasets: seriesKeys.map((key) => ({
          label: key,
          data: data.map((row: any) => Number(row[key] ?? 0)),
        })),
        options: {},
      };
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint=true, destructiveHint=false, and idempotentHint=true, which indicate safe, non-modifying behavior. The description adds no further behavioral details (e.g., auth requirements, side effects, or limitations) beyond stating interactive rendering. With annotations covering safety, a 3 is appropriate.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences long, front-loading the core purpose ('Render an interactive line or area chart') followed by key features. No redundant information or filler. Every sentence adds value, making it highly efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite having 8 parameters, nested objects, and no output schema, the description covers the main functional aspects (interactive, supports themes, multiple series, smooth curves). It does not explain return value or page limitations, but the schema provides detailed parameter documentation. The description is sufficiently complete for a chart-rendering tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 88%, so the schema already documents parameters. The description mentions 'smooth curves' and 'gradient fill' which map to options.smooth and options.fill, adding slight context. However, it does not detail parameter semantics like types or required fields beyond what the schema provides. Baseline 3 is justified.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it renders an interactive line or area chart, specifying key features like smooth curves, gradient fill, and multiple series. This distinguishes it from sibling chart tools (e.g., render_bar_chart, render_pie_chart) by explicitly naming the chart type and supported features.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description lists features but lacks explicit guidance on when to use this tool versus alternatives. It doesn't mention typical use cases (e.g., time-series data) or conditions where a different chart type would be more appropriate. No exclusion criteria or alternative tool names are provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/KyuRish/mcp-dashboards'

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