Quick Start
@VisActor/VChart provides a full-process solution from data to presentation, with "visualization narrative" and "intelligence" as its core competitiveness. The powerful generation ability of the large language model provides VChart with a natural language interaction interface, allowing us to directly call VChart's capabilities through natural language, and complete chart generation and editing simply, quickly, and with high quality. @VisActor/VMind is a chart intelligence module based on VChart and the large language model, providing capabilities such as intelligent chart recommendation, intelligent color matching, and dialog-style chart editing, which can greatly reduce the threshold for using VChart and improve the efficiency of users in creating data visualization works. In this tutorial, we will introduce how to use the VMind component to generate a simple chart.
Get VMind
Use NPM Package
First, you need to install VMind in the project root directory using the following command
VMind needs to be used in conjunction with VChart. In order to draw charts, you also need to introduce VChart into the project. For specific tutorials, please see Quick Start
Introduce VMind
Import through NPM Package
Use import
at the top of the JavaScript file to introduce VMind
Initialize VMind Instance
First, we need to initialize a VMind instance and use it to complete subsequent operations. VMind currently supports OpenAI GPT-3.5, GPT-4 series models and Volcano Engine Skylark (skylark-pro) series models. In the future, we will support more large language models. Welcome to visit Github page to propose your needs. Use the following code to initialize a VMind instance:
When initializing the VMind instance, you can specify the url of the LLM service, the type of model, custom model request methods and other parameters. For detailed tutorials, please go to the Create VMind Instance chapter
Chart Intelligent Generation Module
In traditional chart generation steps, in order to make a complete chart, you need to complete the following steps:
- First prepare a set of data you want to display
- Specify a chart type (chart recommendation)
- Describe how the fields in the data are mapped to the visual channels of the chart (field mapping)
- Modify the style of each element and set the chart palette (intelligent color matching)
And to generate a chart with VMind, you only need to:
- Provide a set of data you want to display (csv or JSON format)
- Describe your requirements for the chart, such as what information you want to display in the chart, what style of color matching to use, etc.
For example, we want to use the following product sales data to show the sales of various products in different regions:
Product Name | region | Sales |
---|---|---|
Cola | south | 2350 |
Cola | east | 1027 |
Cola | west | 1027 |
Cola | north | 1027 |
Sprite | south | 215 |
Sprite | east | 654 |
Sprite | west | 159 |
Sprite | north | 28 |
Fanta | south | 345 |
Fanta | east | 654 |
Fanta | west | 2100 |
Fanta | north | 1679 |
Red Bull | south | 1476 |
Red Bull | east | 830 |
Red Bull | west | 532 |
Red Bull | north | 498 |
To use data in CSV or JSON formats in subsequent processes, it's necessary to call data processing methods to convert CSV data to a JSON format dataset and obtain fieldInfo, or directly obtain fieldInfo from JSON formatted data. VMind provides rule-based methods to get this information. These methods will not transfer detailed data to a larger model.
We can call parseCSVData to obtain a JSON format dataset and fieldInfo from CSV data for intelligent chart generation and data aggregation:
If you already have JSON formatted data, we can also call the getFieldInfo method to obtain fieldInfo from the data:
The content we want to show is "the changes in the sales rankings of various car brands". Call the generateChart method and pass the data and display content description directly to VMind:
Next, we can use VChart to draw the generated chart. Before drawing, we need to prepare a DOM container with height and width for VChart.
Next, we create a VChart
instance, pass in the spec just generated and the ID of the DOM container:
The generated chart is as follows:
We can also make more requests for the chart, for example:
The generated chart is as follows:
Export GIF and Video
VMind supports exporting the generated chart as a GIF animation and video, which can be shared anytime and anywhere. In order to implement the video export function, you need to additionally introduce VChart and FFMPEG into the project and pass them in as objects to VMind. The following will show how to get the ObjectURL of the chart GIF and video:
First install VChart and FFMPEG:
Once you get the ObjectURL of the chart, we can save it as a file. Take saving the video file as an example:
Summary
This chapter introduces how to install and use VMind for chart generation, and demonstrates how to save the generated chart as a GIF and video. VMind currently supports bar charts, pie charts, line charts, scatter plots, word clouds, dynamic bar charts, and more chart types are under development. VMind can recommend suitable chart types based on user data and display intentions, map fields to suitable visual channels, and automatically generate palettes that meet user needs, reducing the threshold for users to perform data visualization and helping you easily complete data narratives.