mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-19 10:07:24 +00:00
fix: charts plugins (#3530)
This commit is contained in:
@@ -4,8 +4,8 @@ import { SystemPluginSpecialResponse } from '../../../type.d';
|
||||
|
||||
type Props = {
|
||||
title: string;
|
||||
xAxis: string;
|
||||
yAxis: string;
|
||||
xAxis: string[];
|
||||
yAxis: string[];
|
||||
chartType: string;
|
||||
};
|
||||
|
||||
@@ -27,7 +27,12 @@ type Option = {
|
||||
series: SeriesData[]; // 使用定义的类型
|
||||
};
|
||||
|
||||
const generateChart = async (title: string, xAxis: string, yAxis: string, chartType: string) => {
|
||||
const generateChart = async (
|
||||
title: string,
|
||||
xAxis: string[],
|
||||
yAxis: string[],
|
||||
chartType: string
|
||||
) => {
|
||||
// @ts-ignore 无法使用dom,如使用jsdom会出现生成图片无法正常展示,有高手可以帮忙解决
|
||||
const chart = echarts.init(undefined, undefined, {
|
||||
renderer: 'svg', // 必须使用 SVG 模式
|
||||
@@ -36,21 +41,11 @@ const generateChart = async (title: string, xAxis: string, yAxis: string, chartT
|
||||
height: 300
|
||||
});
|
||||
|
||||
let parsedXAxis: string[] = [];
|
||||
let parsedYAxis: number[] = [];
|
||||
try {
|
||||
parsedXAxis = json5.parse(xAxis);
|
||||
parsedYAxis = json5.parse(yAxis);
|
||||
} catch (error: any) {
|
||||
console.error('解析数据时出错:', error);
|
||||
return Promise.reject('Data error');
|
||||
}
|
||||
|
||||
const option: Option = {
|
||||
backgroundColor: '#f5f5f5',
|
||||
title: { text: title },
|
||||
tooltip: {},
|
||||
xAxis: { data: parsedXAxis },
|
||||
xAxis: { data: xAxis },
|
||||
yAxis: {},
|
||||
series: [] // 初始化为空数组
|
||||
};
|
||||
@@ -58,18 +53,18 @@ const generateChart = async (title: string, xAxis: string, yAxis: string, chartT
|
||||
// 根据 chartType 生成不同的图表
|
||||
switch (chartType) {
|
||||
case '柱状图':
|
||||
option.series.push({ name: 'Sample', type: 'bar', data: parsedYAxis });
|
||||
option.series.push({ name: 'Sample', type: 'bar', data: yAxis.map(Number) });
|
||||
break;
|
||||
case '折线图':
|
||||
option.series.push({ name: 'Sample', type: 'line', data: parsedYAxis });
|
||||
option.series.push({ name: 'Sample', type: 'line', data: yAxis.map(Number) });
|
||||
break;
|
||||
case '饼图':
|
||||
option.series.push({
|
||||
name: 'Sample',
|
||||
type: 'pie',
|
||||
data: parsedYAxis.map((value, index) => ({
|
||||
value,
|
||||
name: parsedXAxis[index] // 使用 xAxis 作为饼图的名称
|
||||
data: yAxis.map((value, index) => ({
|
||||
value: Number(value),
|
||||
name: xAxis[index] // 使用 xAxis 作为饼图的名称
|
||||
}))
|
||||
});
|
||||
break;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"author": "silencezhang",
|
||||
"version": "4812",
|
||||
"version": "4817",
|
||||
"name": "基础图表",
|
||||
"avatar": "core/workflow/template/baseChart",
|
||||
"intro": "根据数据生成图表,可根据chartType生成柱状图,折线图,饼图",
|
||||
@@ -68,7 +68,7 @@
|
||||
"canEdit": true,
|
||||
"key": "yAxis",
|
||||
"label": "yAxis",
|
||||
"description": "y轴数据,例如:['1', '2', '3']",
|
||||
"description": "y轴数据,例如:[1,2,3]",
|
||||
"defaultValue": "",
|
||||
"list": [
|
||||
{
|
||||
@@ -77,7 +77,7 @@
|
||||
}
|
||||
],
|
||||
"required": true,
|
||||
"toolDescription": "y轴数据,例如:['1', '2', '3']"
|
||||
"toolDescription": "y轴数据,例如:[1,2,3]"
|
||||
},
|
||||
{
|
||||
"renderTypeList": ["select", "reference"],
|
||||
@@ -145,8 +145,8 @@
|
||||
"flowNodeType": "pluginOutput",
|
||||
"showStatus": false,
|
||||
"position": {
|
||||
"x": 2122.252754006148,
|
||||
"y": -63.5218674613718
|
||||
"x": 2128.8138851197145,
|
||||
"y": -63.52186746137181
|
||||
},
|
||||
"version": "481",
|
||||
"inputs": [
|
||||
@@ -154,10 +154,12 @@
|
||||
"renderTypeList": ["reference"],
|
||||
"valueType": "string",
|
||||
"canEdit": true,
|
||||
"key": "相对路径URL",
|
||||
"label": "相对路径URL",
|
||||
"key": "图表 url",
|
||||
"label": "图表 url",
|
||||
"description": "可用使用markdown格式展示图片,如:",
|
||||
"value": ["ws0DFKJnCPhk", "bzaYjKyQFOw2"]
|
||||
"value": ["ws0DFKJnCPhk", "bzaYjKyQFOw2"],
|
||||
"isToolOutput": true,
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"outputs": []
|
||||
@@ -170,8 +172,8 @@
|
||||
"flowNodeType": "httpRequest468",
|
||||
"showStatus": true,
|
||||
"position": {
|
||||
"x": 1216.5166647574395,
|
||||
"y": -206.30162946606856
|
||||
"x": 1264.2009472531117,
|
||||
"y": -455.0773486762623
|
||||
},
|
||||
"version": "481",
|
||||
"inputs": [
|
||||
@@ -275,7 +277,7 @@
|
||||
"key": "system_httpJsonBody",
|
||||
"renderTypeList": ["hidden"],
|
||||
"valueType": "any",
|
||||
"value": "{\r\n \"title\": \"{{title-plugin}}\",\r\n \"xAxis\": \"{{xAxis-plugin}}\",\r\n \"yAxis\": \"{{yAxis-plugin}}\",\r\n \"chartType\": \"{{chartType-plugin}}\"\r\n}",
|
||||
"value": "{\r\n \"title\": \"{{$pluginInput.title$}}\",\r\n \"xAxis\": {{$pluginInput.xAxis$}},\r\n \"yAxis\": {{$pluginInput.yAxis$}},\r\n \"chartType\": \"{{$pluginInput.chartType$}}\"\r\n}",
|
||||
"label": "",
|
||||
"required": false,
|
||||
"valueDesc": "",
|
||||
@@ -306,126 +308,6 @@
|
||||
"description": "",
|
||||
"debugLabel": "",
|
||||
"toolDescription": ""
|
||||
},
|
||||
{
|
||||
"renderTypeList": ["reference"],
|
||||
"valueType": "string",
|
||||
"canEdit": true,
|
||||
"key": "title-plugin",
|
||||
"label": "title-plugin",
|
||||
"customInputConfig": {
|
||||
"selectValueTypeList": [
|
||||
"string",
|
||||
"number",
|
||||
"boolean",
|
||||
"object",
|
||||
"arrayString",
|
||||
"arrayNumber",
|
||||
"arrayBoolean",
|
||||
"arrayObject",
|
||||
"arrayAny",
|
||||
"any",
|
||||
"chatHistory",
|
||||
"datasetQuote",
|
||||
"dynamic",
|
||||
"selectApp",
|
||||
"selectDataset"
|
||||
],
|
||||
"showDescription": false,
|
||||
"showDefaultValue": true
|
||||
},
|
||||
"required": true,
|
||||
"value": ["pluginInput", "title"]
|
||||
},
|
||||
{
|
||||
"renderTypeList": ["reference"],
|
||||
"valueType": "string",
|
||||
"canEdit": true,
|
||||
"key": "xAxis-plugin",
|
||||
"label": "xAxis-plugin",
|
||||
"customInputConfig": {
|
||||
"selectValueTypeList": [
|
||||
"string",
|
||||
"number",
|
||||
"boolean",
|
||||
"object",
|
||||
"arrayString",
|
||||
"arrayNumber",
|
||||
"arrayBoolean",
|
||||
"arrayObject",
|
||||
"arrayAny",
|
||||
"any",
|
||||
"chatHistory",
|
||||
"datasetQuote",
|
||||
"dynamic",
|
||||
"selectApp",
|
||||
"selectDataset"
|
||||
],
|
||||
"showDescription": false,
|
||||
"showDefaultValue": true
|
||||
},
|
||||
"required": true,
|
||||
"value": ["pluginInput", "xAxis"]
|
||||
},
|
||||
{
|
||||
"renderTypeList": ["reference"],
|
||||
"valueType": "string",
|
||||
"canEdit": true,
|
||||
"key": "yAxis-plugin",
|
||||
"label": "yAxis-plugin",
|
||||
"customInputConfig": {
|
||||
"selectValueTypeList": [
|
||||
"string",
|
||||
"number",
|
||||
"boolean",
|
||||
"object",
|
||||
"arrayString",
|
||||
"arrayNumber",
|
||||
"arrayBoolean",
|
||||
"arrayObject",
|
||||
"arrayAny",
|
||||
"any",
|
||||
"chatHistory",
|
||||
"datasetQuote",
|
||||
"dynamic",
|
||||
"selectApp",
|
||||
"selectDataset"
|
||||
],
|
||||
"showDescription": false,
|
||||
"showDefaultValue": true
|
||||
},
|
||||
"required": true,
|
||||
"value": ["pluginInput", "yAxis"]
|
||||
},
|
||||
{
|
||||
"renderTypeList": ["reference"],
|
||||
"valueType": "string",
|
||||
"canEdit": true,
|
||||
"key": "chartType-plugin",
|
||||
"label": "chartType-plugin",
|
||||
"customInputConfig": {
|
||||
"selectValueTypeList": [
|
||||
"string",
|
||||
"number",
|
||||
"boolean",
|
||||
"object",
|
||||
"arrayString",
|
||||
"arrayNumber",
|
||||
"arrayBoolean",
|
||||
"arrayObject",
|
||||
"arrayAny",
|
||||
"any",
|
||||
"chatHistory",
|
||||
"datasetQuote",
|
||||
"dynamic",
|
||||
"selectApp",
|
||||
"selectDataset"
|
||||
],
|
||||
"showDescription": false,
|
||||
"showDefaultValue": true
|
||||
},
|
||||
"required": true,
|
||||
"value": ["pluginInput", "chartType"]
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
|
Reference in New Issue
Block a user