create_bar_chart
Generate horizontal or vertical ASCII bar charts directly in terminal environments using numeric data, labels, and customizable options like width, height, and color.
Instructions
Create horizontal or vertical ASCII bar charts
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| color | No | ANSI color name | |
| data | Yes | Array of numeric values to plot | |
| height | No | Chart height (5-50, default: 15) | |
| labels | No | Optional labels for bars | |
| orientation | No | Bar orientation (default: horizontal) | |
| title | No | Optional chart title | |
| width | No | Chart width (10-200, default: 60) |
Implementation Reference
- src/charts/bar-chart.ts:10-23 (handler)Core handler function that implements the create_bar_chart tool logic, validating input and dispatching to horizontal or vertical bar chart generators based on options.export function createBarChart(data: ChartData, options: BarChartOptions = {}): ChartResult { const { data: values } = data; const { orientation = 'horizontal', showValues = true } = options; if (values.length === 0) { throw new Error('Data array cannot be empty'); } if (orientation === 'horizontal') { return createHorizontalBarChart(data, showValues); } else { return createVerticalBarChart(data, showValues); } }
- src/index.ts:107-149 (schema)JSON Schema defining the input parameters for the create_bar_chart tool, including data array, optional labels, title, dimensions, color, and orientation.inputSchema: { type: 'object', properties: { data: { type: 'array', items: { type: 'number' }, description: 'Array of numeric values to plot' }, labels: { type: 'array', items: { type: 'string' }, description: 'Optional labels for bars', optional: true }, title: { type: 'string', description: 'Optional chart title', optional: true }, width: { type: 'number', description: 'Chart width (10-200, default: 60)', optional: true }, height: { type: 'number', description: 'Chart height (5-50, default: 15)', optional: true }, color: { type: 'string', description: 'ANSI color name', optional: true }, orientation: { type: 'string', enum: ['horizontal', 'vertical'], description: 'Bar orientation (default: horizontal)', optional: true } }, required: ['data'], examples: getToolExamples('create_bar_chart')
- src/index.ts:104-151 (registration)Registration of the create_bar_chart tool in the MCP ListTools response, specifying name, description, and reference to input schema.{ name: 'create_bar_chart', description: 'Create horizontal or vertical ASCII bar charts', inputSchema: { type: 'object', properties: { data: { type: 'array', items: { type: 'number' }, description: 'Array of numeric values to plot' }, labels: { type: 'array', items: { type: 'string' }, description: 'Optional labels for bars', optional: true }, title: { type: 'string', description: 'Optional chart title', optional: true }, width: { type: 'number', description: 'Chart width (10-200, default: 60)', optional: true }, height: { type: 'number', description: 'Chart height (5-50, default: 15)', optional: true }, color: { type: 'string', description: 'ANSI color name', optional: true }, orientation: { type: 'string', enum: ['horizontal', 'vertical'], description: 'Bar orientation (default: horizontal)', optional: true } }, required: ['data'], examples: getToolExamples('create_bar_chart') } },
- src/index.ts:348-356 (handler)MCP CallToolRequest dispatch handler for create_bar_chart, extracting orientation and invoking the core createBarChart function.case 'create_bar_chart': { progress.nextStep('Generating bar chart'); const orientation = params.orientation || 'horizontal'; result = await withRequestTracking( () => Promise.resolve(createBarChart(chartData, { orientation })), 'create_bar_chart' )(); break; }
- src/utils/examples.ts:25-46 (helper)Helper examples providing sample inputs for testing the create_bar_chart tool in different configurations (horizontal, vertical, comparison).create_bar_chart: { horizontal: { data: [85, 67, 54, 92], labels: ["Frontend", "Backend", "DevOps", "QA"], title: "Team Performance", orientation: "horizontal" }, vertical: { data: [12, 19, 15, 25, 22, 18], labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun"], title: "Monthly Sales", orientation: "vertical", color: "cyan" }, comparison: { data: [45, 55, 60, 40, 70], labels: ["Product A", "Product B", "Product C", "Product D", "Product E"], title: "Product Comparison", width: 70, height: 18 } },