Skip to main content
Glama

create-chart-using-apexcharts

Generate chart images from Apex Charts configurations, either returning URLs or saving files directly for data visualization needs.

Instructions

Create charts using Apex Charts - get chart image URL or save chart image to file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesWhether to get chart URL or save as file
outputPathNoPath where to save the file (only used with action=save_file)
configYesApex Charts JSON configuration
widthNoImage width in pixels
heightNoImage height in pixels
apexChartsVersionNoApex Charts version to use

Implementation Reference

  • The main handler function that executes the core logic: validates inputs, builds ApexCharts config, fetches image from QuickChart API, generates base64 image and URL, handles file saving.
    export async function handleApexChartsTool(args: any): Promise<any> {
      const config = args.config as any;
      const action = args.action as string;
      
      validateConfig(config);
      validateAction(action);
      validateOutputPath(args.outputPath, action);
      validateDimensions(args.width, args.height);
      validateApexChartsVersion(args.apexChartsVersion);
    
      const postConfig = buildApexChartsConfig(config, {
        width: args.width as number,
        height: args.height as number,
        apexChartsVersion: args.apexChartsVersion as string,
      });
      const chartUrl = buildApexChartsUrl(config);
    
      const result: any = {
        content: [
          {
            type: "text",
            text: "Below is the chart URL:",
          },
          {
            type: "text",
            text: chartUrl,
          },
        ],
        metadata: {
          chartType: config?.chart?.type || "unknown",
          generatedAt: new Date().toISOString(),
          chartUrl: chartUrl,
        },
      };
    
      try {
        const pngData = await fetchApexChartsContent(postConfig, "png");
        const pngBase64 = Buffer.from(pngData).toString("base64");
    
        result.content.push(
          {
            type: "text",
            text: "Below is the PNG image:",
          },
          {
            type: "image",
            data: pngBase64,
            mimeType: "image/png",
          }
        );
        result.metadata.pngBase64 = pngBase64;
      } catch (error) {
        result.content.unshift({
          type: "text",
          text: "⚠️ Failed to fetch chart image",
        });
        result.content.push({
          type: "text",
          text: `Error: ${error instanceof Error ? error.message : String(error)}`,
        });
        result.metadata.error =
          error instanceof Error ? error.message : String(error);
      }
    
      if (action === "get_url") {
        return result;
      }
    
      const format = "png";
      const outputPath = getDownloadPath(
        args.outputPath as string | undefined,
        format
      );
    
      try {
        const dir = path.dirname(outputPath);
        if (!fs.existsSync(dir)) {
          fs.mkdirSync(dir, { recursive: true });
        }
    
        const data = await fetchApexChartsContent(postConfig, format);
        fs.writeFileSync(outputPath, data);
    
        result.metadata.savedPath = outputPath;
        result.content.push({
          type: "text",
          text: "Below is the saved file path:",
        });
        result.content.push({
          type: "text",
          text: outputPath,
        });
        return result;
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to save chart: ${
            error instanceof Error ? error.message : String(error)
          }`
        );
      }
    }
  • The Tool object definition containing the inputSchema for parameter validation, description, and name.
    export const CREATE_CHART_USING_APEXCHARTS_TOOL: Tool = {
      name: "create-chart-using-apexcharts",
      description:
        "Create charts using Apex Charts - get chart image URL or save chart image to file",
      inputSchema: {
        type: "object",
        properties: {
          action: {
            type: "string",
            enum: ["get_url", "save_file"],
            description: "Whether to get chart URL or save as file",
          },
          outputPath: {
            type: "string",
            description:
              "Path where to save the file (only used with action=save_file)",
          },
          config: {
            type: "object",
            description: "Apex Charts JSON configuration",
          },
          width: {
            type: "integer",
            description: "Image width in pixels",
          },
          height: {
            type: "integer",
            description: "Image height in pixels",
          },
          apexChartsVersion: {
            type: "string",
            description: "Apex Charts version to use",
          },
        },
        required: ["action", "config"],
      },
    };
  • Maps the tool name to its handler function in the central TOOL_HANDLERS registry.
    "create-chart-using-apexcharts": {
      handler: handleApexChartsTool,
      toolName: ToolNames.APEXCHARTS,
    },
  • Includes the tool in the ALL_TOOLS array for conditional enabling and export.
    { tool: CREATE_CHART_USING_APEXCHARTS_TOOL, name: ToolNames.APEXCHARTS },
  • Documentation metadata including description, supported chart types, examples, and links used in the help tool.
    "create-chart-using-apexcharts": {
      name: "create-chart-using-apexcharts",
      description:
        "Create charts using ApexCharts library - get chart image URL or save chart image to file",
      documentation:
        "https://quickchart.io/documentation/apex-charts-image-rendering/",
      additionalResources: {
        apexchartsDocumentation: "https://apexcharts.com/docs/",
        apexchartsDemos: "https://apexcharts.com/javascript-chart-demos/",
        quickChartGallery: "https://quickchart.io/gallery/",
      },
      supportedChartTypes: [
        "line - Line charts for depicting trends and behaviors over time",
        "area - Area charts for showing cumulative data trends",
        "bar - Bar charts for categorical data comparison",
        "column - Column charts for vertical data comparison",
        "pie - Pie charts for proportion visualization",
        "donut - Donut charts for enhanced proportion display",
        "scatter - Scatter plots for correlation analysis",
        "bubble - Bubble charts for multi-dimensional data",
        "candlestick - Candlestick charts for financial data",
        "boxplot - Box plots for statistical data distribution",
        "heatmap - Heat maps for matrix data visualization",
        "treemap - Tree maps for hierarchical data",
        "radar - Radar charts for multi-variable comparison",
        "radialbar - Radial bar charts and circular gauges",
        "rangearea - Range area charts for data ranges",
        "rangebar - Range bar charts for time periods",
        "funnel - Funnel charts for process visualization",
      ],
      promptExamples: [
        'Financial Dashboards: "Create a candlestick chart for stock prices"',
        'Interactive Reports: "Generate a multi-series area chart with zoom functionality"',
        'Time Series Analysis: "Show real-time data with datetime axis charts"',
      ],
      usageExample: {
        action: "save_file",
        config: {
          series: [
            {
              name: "Sales",
              data: [30, 40, 45, 50, 49, 60, 70, 91],
            },
          ],
          chart: {
            type: "line",
          },
          xaxis: {
            categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug"],
          },
        },
      },
    },
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the two actions (get_url, save_file) but doesn't explain what the URL points to (e.g., temporary storage, expiration), file formats (e.g., PNG, SVG), error handling, rate limits, or authentication needs. For a tool with 6 parameters and no annotations, this leaves significant behavioral gaps.

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

Conciseness4/5

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

The description is a single, efficient sentence that front-loads the core purpose and key output options. It avoids redundancy and wastes no words, though it could be slightly more structured by separating purpose from action options for better readability.

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

Completeness2/5

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

Given the tool's complexity (6 parameters, nested 'config' object, no output schema, and no annotations), the description is inadequate. It doesn't explain the output format (e.g., image type, URL validity), error cases, or provide any context for the 'config' parameter, which is critical for correct usage. This leaves the agent with insufficient information to use the tool effectively.

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 already documents all parameters thoroughly. The description adds no additional meaning beyond what's in the schema—it doesn't explain the 'config' parameter's structure, provide examples for 'width'/'height', or clarify dependencies like 'outputPath' only being used with 'save_file'. Baseline 3 is appropriate as the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Create charts using Apex Charts' specifies the verb (create) and resource (charts), and distinguishes it from sibling tools like create-chart-using-chartjs by naming the specific library. However, it doesn't explicitly differentiate from create-chart-using-natural-language in terms of input method (JSON config vs. natural language).

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It mentions two output options (get URL or save file) but doesn't explain when to choose one over the other, nor does it compare with sibling tools like create-chart-using-chartjs or create-chart-using-googlecharts. There are no prerequisites, exclusions, or context for selection.

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/TakanariShimbo/quickchart-mcp-server'

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