diff --git a/backend/template.yaml b/backend/template.yaml index 40a18017..300f7a82 100644 --- a/backend/template.yaml +++ b/backend/template.yaml @@ -55,10 +55,10 @@ template: {{"type":"bar", "title": "标题", "axis": {{"x": {{"name":"x轴的中文名称", "value": "SQL 查询 x 轴的列(有别名用别名)"}}, "y": {{"name":"y轴的中文名称","value": "SQL 查询 y 轴的列(有别名用别名)"}}}} 必须从 SQL 查询列中提取“x”和“y”。 - 如果需要折线图,则生成的 JSON 格式应为: - {{"type":"line", "title": "标题", "axis": {{"x": {{"name":"x轴的中文名称","value": "x轴的SQL查询列(有别名用别名)"}}, "y": {{"name":"y轴的中文名称","value": "y轴的SQL查询列(有别名用别名)"}}}} + {{"type":"line", "title": "标题", "axis": {{"x": {{"name":"x轴的中文名称","value": "SQL 查询 x 轴的列(有别名用别名)"}}, "y": {{"name":"y轴的中文名称","value": "SQL 查询 y 轴的列(有别名用别名)"}}}} 其中“x”和“y”必须从SQL查询列中提取。 - 如果需要饼图,则生成的 JSON 格式应为: - {{"type":"pie", "title": "标题", "columns": [{{"name":"中文字段名1","value":"SQL查询列1(有别名用别名)"}},{{"name":"中文字段名2","value":"SQL查询列2(有别名用别名)"}}]}} + {{"type":"pie", "title": "标题", "axis": {{"y": {{"值轴的中文名称","value":"SQL 查询数值的列(有别名用别名)"}}, "series": {{"name":"分类的中文名称","value":"SQL 查询分类的列(有别名用别名)"}}}} 其中“column”必须从SQL查询列中提取。 - 如果答案未知或者与生成JSON无关,则生成的 JSON 格式应为: {{"type":"error", "reason": "抱歉,我无法回答您的问题。"}} diff --git a/frontend/src/views/chat/ChatAnswer.vue b/frontend/src/views/chat/ChatAnswer.vue index 0b00e273..4150305b 100644 --- a/frontend/src/views/chat/ChatAnswer.vue +++ b/frontend/src/views/chat/ChatAnswer.vue @@ -5,6 +5,7 @@ import {computed, nextTick, ref} from "vue"; import type {TabsPaneContext} from 'element-plus-secondary' import {Loading} from "@element-plus/icons-vue"; import Component from "./component/Component.vue" +import type {ChartTypes} from "@/views/chat/component/BaseChart.ts"; const props = defineProps<{ message?: ChatMessage @@ -43,9 +44,13 @@ const dataObject = computed<{ }) const chartObject = computed<{ - type: "table" | "bar" | "line" | "pie" + type: ChartTypes title: string - axis: { x: { name: string, value: string }, y: { name: string, value: string } } + axis: { + x: { name: string, value: string }, + y: { name: string, value: string }, + series: { name: string, value: string } + } columns: Array<{ name: string, value: string }> }>(() => { if (props.message?.record?.chart) { @@ -66,10 +71,16 @@ const yAxis = computed(() => { } return [] }) +const series = computed(() => { + if (chartObject.value?.axis?.series) { + return [chartObject.value.axis.series] + } + return [] +}) -const currentChartType = ref<"table" | "bar" | 'column' | "line" | "pie" | undefined>(undefined) +const currentChartType = ref(undefined) -const chartType = computed<"table" | "bar" | 'column' | "line" | "pie">({ +const chartType = computed({ get() { if (currentChartType.value) { return currentChartType.value @@ -158,6 +169,7 @@ function onTypeChange(type: string) { :columns="chartObject?.columns" :x="xAxis" :y="yAxis" + :series="series" :data="dataObject.data"/> @@ -189,6 +201,6 @@ function onTypeChange(type: string) { .chart-base-container { padding: 20px; - background: rgba(224,224,226,0.29); + background: rgba(224, 224, 226, 0.29); } \ No newline at end of file diff --git a/frontend/src/views/chat/component/BaseChart.ts b/frontend/src/views/chat/component/BaseChart.ts index d2ad74c7..8f1fdeff 100644 --- a/frontend/src/views/chat/component/BaseChart.ts +++ b/frontend/src/views/chat/component/BaseChart.ts @@ -1,15 +1,27 @@ +export interface ChartAxis { + name: string, + value: string, + type?: 'x' | 'y' | 'series' +} + +export interface ChartData { + [key: string]: any +} + +export type ChartTypes = "table" | "bar" | 'column' | "line" | "pie" + export abstract class BaseChart { id: string; _name: string = 'base-chart'; - axis: Array<{ name: string, value: string, type?: 'x' | 'y' }> = []; - data: Array<{ [key: string]: any }> = []; + axis: Array = []; + data: Array = []; constructor(id: string, name: string) { this.id = id; this._name = name; } - init(axis: Array<{ name: string, value: string, type?: 'x' | 'y' }>, data: Array<{ [key: string]: any }>): void { + init(axis: Array, data: Array): void { this.axis = axis; this.data = data; } diff --git a/frontend/src/views/chat/component/Component.vue b/frontend/src/views/chat/component/Component.vue index 93197876..04aeaa43 100644 --- a/frontend/src/views/chat/component/Component.vue +++ b/frontend/src/views/chat/component/Component.vue @@ -1,20 +1,22 @@