generate_polar_chart
Create polar charts (rose, radar, pie) to visualize numerical differences across categories using polar coordinates, with customizable dimensions, themes, and axis settings.
Instructions
Generate a polar chart (rose, radar, pie) to display numerical differences among different categories using radius and angle in polar coordinates.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| angleAxisHasGrid | No | Show grid lines for the angle axis. | |
| angleAxisHasLabel | No | Show angle axis labels. | |
| angleAxisHasTick | No | Show angle axis ticks. | |
| angleAxisTitle | No | Angle axis title. | |
| angleAxisType | No | Angle axis type: categorical ('band') or continuous ('linear'). | |
| background | No | Chart background color (hex). Optional, defaults to white. | |
| categoryField | Yes | Dimension field. Must exist in the data. | |
| chartTheme | No | Chart theme. Optional, defaults to 'light'. | |
| chartType | Yes | ||
| colorField | No | Color grouping field. Should not duplicate the dimension field. | |
| colors | No | Color palette for chart elements. | |
| dataTable | Yes | Data for the chart, e.g., [{ category: 'Category 01', value: 10 }]. | |
| height | No | Chart height. Optional, defaults to 500. | |
| output | No | Chart output type. Defaults to 'image'. | image |
| radiusAxisHasGrid | No | Show grid lines for the radius axis. | |
| radiusAxisHasLabel | No | Show radius axis labels. | |
| radiusAxisHasTick | No | Show radius axis ticks. | |
| radiusAxisTitle | No | Radius axis title. | |
| radiusAxisType | No | Radius axis type: categorical ('band') or continuous ('linear'). | |
| stackOrPercent | No | Stacking mode: 'stack' for stacked data, 'percent' for percentage stacking. Requires 'color' field. | |
| subTitle | No | Chart subtitle text. | |
| title | No | Chart title text. | |
| titleOrient | No | Title position in the chart. | |
| transpose | No | ||
| valueField | Yes | Measure field. Must be numeric and exist in the data. | |
| width | No | Chart width. Optional, defaults to 500. |
Implementation Reference
- src/server.ts:43-125 (handler)Generic MCP tool call handler for all chart generation tools. For 'generate_polar_chart', it resolves chartType to 'polar', validates input using the polar schema, calls generateChartByType('polar', args), and returns the chart output (spec, image, or HTML).server.setRequestHandler(CallToolRequestSchema, async request => { const toolName = request.params.name; const chartType = Object.keys(Charts).find( key => (Charts as any)[key].tool.name === toolName ); if (!chartType) { throw new McpError( ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}.` ); } try { // Validate input using Zod before generating chart const args = request.params.arguments || {}; // Select the appropriate schema based on the chart type const schema = Charts[chartType as keyof typeof Charts].schema; if (schema) { const result = schema.safeParse(args); if (!result.success) { throw new McpError( ErrorCode.InvalidParams, `Invalid parameters: ${result.error.message}` ); } } const res = await generateChartByType(chartType, args); if (res && (res as any).spec) { return { content: [ { type: 'text', text: JSON.stringify((res as any).spec, null, 2), }, ], }; } if (res && (res as any).image) { return { content: [ { type: 'text', text: (res as any).image, }, ], }; } if (res && (res as any).html) { return { content: [ { type: 'text', text: (res as any).html, }, ], }; } return { content: [ { type: 'text', text: 'Failed to generate chart', }, ], }; } catch (error: any) { if (error instanceof McpError) { throw error; } throw new McpError( ErrorCode.InternalError, `Failed to generate chart: ${error?.message || 'Unknown error.'}` ); } });
- src/charts/polar.ts:29-67 (schema)Zod schema defining the input parameters and validation for the generate_polar_chart tool.const schema = z.object({ output: ChartOutputSchema, width: WidthSchema, height: HeightSchema, dataTable: z .array(z.any()) .describe( "Data for the chart, e.g., [{ category: 'Category 01', value: 10 }]." ) .nonempty({ message: "Data must not be empty." }), chartType: z.enum(["rose", "radar", "pie"]), transpose: z.boolean().optional(), categoryField: XFieldSchema, valueField: YFieldSchema, colorField: ColorFieldSchema, chartTheme: ThemeSchema, title: TitleTextSchema, subTitle: TitleSubTextSchema, titleOrient: TitleOrientSchema, angleAxisTitle: AngleAxisTitleSchema, angleAxisHasGrid: AngleAxisHasGridSchema, angleAxisHasLabel: AngleAxisHasLabelSchema, angleAxisHasTick: AngleAxisHasTickSchema, angleAxisType: AngleAxisTypeSchema, radiusAxisHasGrid: RadiusAxisHasGridSchema, radiusAxisHasLabel: RadiusAxisHasLabelSchema, radiusAxisHasTick: RadiusAxisHasTickSchema, radiusAxisType: RadiusAxisTypeSchema, radiusAxisTitle: RadiusAxisTitleSchema, background: BackgroundSchema, colors: ColorsSchema, stackOrPercent: StackSchema, });
- src/server.ts:34-38 (registration)Registration of all chart tools, including generate_polar_chart from Charts.polar.tool, for MCP listTools request.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: Object.values(Charts).map(chart => (chart as any).tool), }; });
- src/charts/polar.ts:69-79 (registration)Tool metadata definition (name, description, schema) and export for registration.const tool = { name: "generate_polar_chart", description: "Generate a polar chart (rose, radar, pie) to display numerical differences among different categories using radius and angle in polar coordinates.", inputSchema: convertZodToJsonSchema(schema), }; export const polar = { schema, tool, };