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.
Supported Models:
- GPT-3.5
- GPT-4
- skylark2-pro
- chart-advisor
Chart Type List
VMind supports 13 common chart types:
You can restrict the type of chart generated through the chartTypeList in the options parameter.
Interface Parameters:
-
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
Return Value Type:
- 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
- chartSource: string: The source of the chart generation. If the chart is successfully generated using LLM, it is the specific model name; if the final use is rule-based chart generation, then it is chart-advisor
- usage (any): Total LLM token consumption
- time (number): The duration of the chart animation, which can be used to export GIF and video
Usage Example:
Generate a chart with a custom color palette
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:
Built-in color palette list:
SemiTheme
: Semi design theme color paletteArcoTheme
: Arco design theme color paletteVeOTheme
: VeO design theme color paletteVeOThemeFinance
: VeO design for finance industry theme color paletteVeOThemeGovernment
: VeO design for government industry theme color paletteVeOThemeConsumer
: VeO design for consumer industry theme color paletteVeOThemeAutomobile
: VeO design for automobile industry theme color paletteVeOThemeCulturalTourism
: VeO design for cultural tourism industry theme color paletteVeOThemeMedical
: VeO design for medical industry theme color paletteVeOThemeNewEnergy
: VeO design for new energy industry theme color palette
Limit the type of charts generated
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:
Notes:
- 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.