VSeed, an elegant data composer, transforming complexity into simplicity.
!!!###!!!title=generateChart——VisActor/VMind api documents!!!###!!!
generateChart
Interface Description:
The generateChart function is used to call LLM to complete intelligent generation of charts, and returns the generated chart spec, chart type, and field mapping, etc.
If the passed in dataset is undefined, a spec template will be generated, and fillSpecWithData can be called later to fill data into the spec.
userPrompt (string): User's visualization intention (What information you want to show in the chart)
fieldInfo (Array): Information about the fields in the dataset, including field name, type, etc
dataset (Array): The raw dataset used in the chart, it can be undefined. If dataset is undefined, a spec template will be generated and fillSpecTemplateWithData can be called later to fill data into the spec template.
options: Optional, option parameters, include the following:
chartTypeList (ChartType[], optional): Supported chart type list. If not undefined, a chart will be generated from the chart types specified in this list.
enableDataQuery (boolean, optional): Determines whether to enable data aggregation during chart generation
colorPalette (Array, optional): Used to set the color palette of the chart
animationDuration (number, optional): Used to set the playback duration of the chart animation
theme (ChartTheme | string, optional): Sets the theme style of the final spec. By default, VMind uses a theme style with gradient colors. You can set VChart's general light or dark theme ('light' | 'dark') or a theme style that suits your usage scenario.
Return Value Type:
interface GenerateChartResult {
/** Chart spec */spec: Record<string, any>;
/** Chart type */ chartType: ChartType;
/** Final visual channel mapping */ cell: Cell;
/** Token consumption */ usage: Usage;
/* Specific command to generate the current chart, consistent with user prompt in the case of user prompt */ command: string;
/** Configuration time used for converting to gif/video */ time: {
totalTime : number;
frameArr: number[];
};
/** Rule-based chart recommendation results, generated as a fallback when manually setting rules or when the large model generation is incorrect */ chartAdvistorRes: {
/** Chart spec */spec: Record<string, any>;
/** Chart type */ chartType: ChartType;
/** Recommendation score */ score: number }[]
}
spec (Object): The generated VChart chart spec. If the dataset is empty, it is a spec template that does not contain data
chartType (ChartType): The type of the chart generated, see Chart Type List section
cell (Record<string, string | string[]>): The field mapping in the chart, describing how the fields in the dataset map to the various visual channels on the chart
usage (any): Total LLM token consumption
time (number): The duration of the chart animation, which can be used to export GIF and video
chartAdvistorRes (Array): This result is the chart recommendation result derived based on the current data and field information through VMind's built-in rules, generated as a fallback when the model is set to Model.CHART_ADVISOR or the user's large model settings are incorrect and no result can be obtained. For details, see: Rule-Based Chart Generation-
//Setting up a custom color paletteconst colorPalette = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'];
const { spec } = await vmind.generateChart(userPrompt, fieldInfo, dataset, {colorPalette});
VMind also comes built-in with Arco-design, Semi-design, VeO design, and other multiple theme color palettes, which can be directly imported to use:
import VMind, {ArcoTheme} from'@visactor/vmind';
// Use Arco-design color paletteconst {spec} = await vmind.generateChart(describe, finalFieldInfo, finalDataset, {
colorPalette: ArcoTheme.colorScheme
});
Built-in color palette list:
SemiTheme: Semi design theme color palette
ArcoTheme: Arco design theme color palette
VeOTheme: VeO design theme color palette
VeOThemeFinance: VeO design for finance industry theme color palette
VeOThemeGovernment: VeO design for government industry theme color palette
VeOThemeConsumer: VeO design for consumer industry theme color palette
VeOThemeAutomobile: VeO design for automobile industry theme color palette
VeOThemeCulturalTourism: VeO design for cultural tourism industry theme color palette
VeOThemeMedical: VeO design for medical industry theme color palette
VeOThemeNewEnergy: VeO design for new energy industry theme color palette
Limit the type of charts generated
import VMind, {ChartType} from'@visactor/vmind';
//Restrict the generation of the following types of charts: bar charts, line charts, scatter plots, pie charts, word cloudsconst chartTypeList = [
ChartType.BarChart,
ChartType.LineChart,
ChartType.ScatterPlot,
ChartType.PieChart,
ChartType.WordCloud
]
const { spec } = await vmind.generateChart(userPrompt, fieldInfo, dataset, {chartTypeList});
Generate a spec template without a dataset
In some cases, we may generate a chart without a specific dataset, but only with data fields (for example, generate a chart based on the fields in the dataset before querying, and then complete the relevant query based on the type and fields of the chart generated), and then call the fillSpecWithData method to get the final spec for chart rendering:
The generateChart method will pass the userPrompt and fieldInfo to the large language model for chart generation, but the detailed data in the dataset will not be passed.
In the process of generating the chart, VMind will first use the large language model, according to the userPrompt and fieldInfo, to recommend a suitable chart type. Then, it will map the fields in the fieldInfo to the x-axis, y-axis, color, size and other visual channels of the chart.
VMind will add an entrance animation to the generated chart by default, so it will also return the duration of the chart animation time. If you want to turn off the chart animation, you can set spec.animation to false.
When the model type is set to chart-advisor, it will not call a large language model to generate charts. The results generated will include multiple types of charts. For details, please refer to Rule-based Chart Generation.