{
"pluginFunctions": [
{
"id": "44adfca5-44ad-4a4c-b224-5e476136665d",
"name": "render_chart",
"implementationType": "javascript",
"openaiSpec": {
"name": "render_chart",
"parameters": {
"type": "object",
"required": [
"title",
"chartType",
"data",
"options"
],
"properties": {
"data": {
"type": "object",
"required": [
"labels",
"datasets"
],
"properties": {
"labels": {
"type": "array",
"items": {
"type": "string"
},
"description": "Labels for the chart"
},
"datasets": {
"type": "array",
"items": {
"type": "object",
"required": [
"label",
"data"
],
"properties": {
"data": {
"type": "array",
"items": {
"type": "number"
},
"description": "Data points for the dataset"
}
}
},
"description": "Datasets to be rendered in the chart"
}
},
"description": "Data to be rendered in the chart"
},
"title": {
"type": "string",
"description": "The title of the chart"
},
"chartType": {
"enum": [
"line",
"bar",
"doughnut",
"pie",
"radar",
"polarArea",
"bubble",
"scatter"
],
"type": "string",
"description": "Type of the chart to render"
}
}
},
"description": "Generate a Chart.js chart"
},
"code": "function render_chart(params) {\n const { chartType, options, title, data } = params;\n const dataString = JSON.stringify(data)\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/\"/g, '\\\\\"')\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r')\n .replace(/\\t/g, '\\\\t');\n\n const optionsString = JSON.stringify(options)\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/\"/g, '\\\\\"')\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r')\n .replace(/\\t/g, '\\\\t');\n\n const htmlString = `\n <!DOCTYPE html>\n <html>\n <head>\n <title>${title}</title>\n <script src=\"https://cdn.jsdelivr.net/npm/chart.js\"></script>\n </head>\n <body>\n <canvas id=\"generated-chart\" style=\"width: 100%; height: 90vh;\"></canvas>\n <script>\n var ctx = document.getElementById('generated-chart').getContext('2d');\n var chart = new Chart(ctx, {\n type: '${chartType}',\n data: JSON.parse(\"${dataString}\"),\n options: JSON.parse(\"${optionsString}\")\n });\n </script>\n </body>\n </html>\n `;\n return htmlString;\n}\n",
"outputType": "render_html"
}
]
}