Skip to main content
Glama

Variance Chart

render_variance_chart
Read-onlyIdempotent

Render a variance chart comparing actual vs budget with color-coded over/under indicators. Identify budget performance gaps at a glance.

Instructions

Render a variance chart - 'Over or under budget?' Bars showing actual vs budget with color-coded over/under indicators.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYesChart title
dataYesArray of {label, budget, actual} items
unitNoUnit suffix (e.g. '$', 'k')
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

  • Main handler function that renders a variance (budget vs actual) chart. Computes bar widths, builds HTML rows with over/under styling, attaches click handlers for sending selection messages, and adds export/refresh buttons.
    export function renderVarianceChart(container: HTMLElement, payload: VarianceData): void {
      const theme = resolveTheme(payload.theme, {
        palette: payload.palette,
        typography: payload.typography,
        effects: payload.effects,
      });
      if (theme) applyTheme(container, theme);
    
      const shimmer = theme?.effects.shimmerTitle ? " shimmer-text" : "";
      const unit = payload.unit || "";
      const maxVal = Math.max(...payload.data.flatMap((d) => [d.budget, d.actual]), 1);
    
      const rows = payload.data.map((item, i) => {
        const budgetPct = (item.budget / maxVal) * 100;
        const actualPct = (item.actual / maxVal) * 100;
        const diff = item.actual - item.budget;
        const isOver = diff > 0;
        const diffLabel = `${isOver ? "+" : ""}${diff.toLocaleString()}${unit}`;
        const diffClass = isOver ? "variance__diff--over" : "variance__diff--under";
    
        return `
          <div class="variance__row" data-idx="${i}">
            <div class="variance__label">${escapeHtml(item.label)}</div>
            <div class="variance__track">
              <div class="variance__bar ${isOver ? "variance__bar--over" : "variance__bar--under"}" style="width:${actualPct}%"></div>
              <div class="variance__budget-marker" style="left:${budgetPct}%"></div>
            </div>
            <div class="variance__diff ${diffClass}">${diffLabel}</div>
          </div>
        `;
      }).join("");
    
      container.className = "chart-view";
      container.innerHTML = `
        <div class="card chart-card">
          <div class="chart-card__header">
            <div><div class="chart-card__title${shimmer}">${escapeHtml(payload.title)}</div></div>
          </div>
          <div class="chart-card__body chart-card__body--css">
            <div class="variance">${rows}</div>
          </div>
        </div>
      `;
    
      container.querySelectorAll<HTMLElement>(".variance__row").forEach((el) => {
        el.style.cursor = "pointer";
        el.addEventListener("click", () => {
          const idx = parseInt(el.dataset.idx ?? "0", 10);
          const item = payload.data[idx];
          const diff = item.actual - item.budget;
          sendClickMessage(`[Variance] "${payload.title}" - ${item.label}: actual ${item.actual}${unit} vs budget ${item.budget}${unit} (${diff > 0 ? "+" : ""}${diff}${unit})`);
        });
      });
    
      const card = container.querySelector<HTMLElement>(".chart-card")!;
      addHtmlExportButton(card, payload.title);
      addRefreshButton(card, () => (window as any).__mcpRefresh?.());
    }
  • Type definitions for the variance chart: VarianceItem (label, budget, actual) and VarianceData (type, title, data, optional unit/theme/palette/typography/effects).
    interface VarianceItem {
      label: string;
      budget: number;
      actual: number;
    }
    
    interface VarianceData {
      type: "variance";
      title: string;
      data: VarianceItem[];
      unit?: string;
      theme?: string;
      palette?: string;
      typography?: string;
      effects?: string;
    }
  • Registers the tool with name 'render_variance_chart' under the chart type 'variance' via the shared registerChart function.
    registerChart("variance", "render_variance_chart", renderVarianceChart);
  • The registerChart function itself, which stores toolName -> render function mappings in a CHART_REGISTRY.
    export function registerChart(
      type: string,
      toolName: string,
      render: (root: HTMLElement, data: any) => void,
    ): void {
      CHART_REGISTRY[type] = { toolName, render };
    }
  • Imports for shared utilities (escapeHtml, sendClickMessage, addHtmlExportButton, addRefreshButton, registerChart) and theme helpers (resolveTheme, applyTheme).
    import { escapeHtml, sendClickMessage, addHtmlExportButton, addRefreshButton, registerChart } from "./shared.js";
    import { resolveTheme, applyTheme } from "../themes.js";
    
    interface VarianceItem {
      label: string;
      budget: number;
      actual: number;
    }
    
    interface VarianceData {
      type: "variance";
      title: string;
      data: VarianceItem[];
      unit?: string;
      theme?: string;
      palette?: string;
      typography?: string;
      effects?: string;
    }
    
    export function renderVarianceChart(container: HTMLElement, payload: VarianceData): void {
      const theme = resolveTheme(payload.theme, {
        palette: payload.palette,
        typography: payload.typography,
        effects: payload.effects,
      });
      if (theme) applyTheme(container, theme);
Behavior4/5

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

Annotations already indicate readOnlyHint=true, destructiveHint=false, and idempotentHint=true. The description adds that bars are color-coded to indicate over/under budget, which is helpful behavioral context beyond annotations. No contradiction.

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 a single, well-structured sentence that front-loads the core purpose and adds a clarifying question. Every word earns its place with no redundancy.

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

Completeness5/5

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

Given the rich input schema and the presence of many sibling chart tools, this description sufficiently completes the context. It explains the chart's nature and visual indicators, allowing an AI agent to select and invoke it correctly.

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 100%, so the schema thoroughly documents all parameters. The description adds marginal value by implying the meaning of budget and actual fields, but it mostly restates what the schema already conveys.

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 the tool renders a variance chart comparing actual vs budget, with color-coded over/under indicators. It uses a specific verb ('Render'), specifies the resource ('variance chart'), and adds a clarifying question ('Over or under budget?'), distinguishing it from sibling chart tools.

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 implies usage for budget variance visualization but does not explicitly state when to use this tool over alternatives like render_bar_chart or render_bullet_chart. No guidance on when not to use or which scenarios it suits best.

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