It is not only a fully functional graph visualization library, but also an explorer of data relationships.
!!!###!!!title=How to Assemble a VChart——VisActor/VChart Contributing Documents!!!###!!!!!!###!!!description=---title: 3 How to "assemble" a VChart chart key words: VisActor,VChart,VTable,VStrory,VMind,VGrammar,VRender,Visualization,Chart,Data,Table,Graph,Gis,LLM---In the previous chapters, we talked about the composition and basic principles of charts. Now let's see how to assemble a VChart chart using declarative syntax. !!!###!!!
In the previous chapters, we talked about the composition and basic principles of charts. Now let's see how to assemble a VChart chart using declarative syntax.
3.1 Interface Definition
A basic spec needs to include the following parts:
type Chart type
data Data source
Data mapping, in most cases in a Cartesian coordinate system as xField and yField, in a polar coordinate system as categoryField and valueField
Series configuration, VChart charts are composed of series, which include elements and labels. The configuration of elements and labels is in the series configuration
Component configuration, such as legends, axes, etc. Except for composite charts that must configure axes, the configuration of components for other charts is actually optional and can be configured as needed
3.1.1 Chart Type
In the spec, we first need to decide the chart type, for example:
Note that there is a special chart type called common, which is a composite chart type series. Examples will be provided later.
3.1.2 Data Source
Data is the foundation of chart visualization, and we need to specify the data source in the spec. Typically, data is represented in JSON format, using the data field to specify it. For example, we can specify the data source in the following format:
The id field is used to identify the data source, and the values field is used to specify the data of the data source.
In VChart, in most cases, we expect to use flattened data objects. The difference between flattened and non-flattened data objects is shown in the example below
The most important significance of flattening data is that it allows for a one-to-one correspondence between data and graphics.
3.1.3 Data Mapping
Next, we need to map the data to the basic graphical elements (marks) of the chart. For the grouped bar chart in this tutorial, we specify xField, yField, and seriesField. Here, xField and yField are used for position mapping, and seriesField is used for color mapping
A series refers to the main body of the chart in the image, such as the line in a line chart, which will be introduced in more detail later.
3.1.5 Component Configuration
VChart also supports configuring various components of the chart, such as axes, legends, crosshair, and tooltip. Currently, the components supported by VChart are:
3.2 Series
3.2.1 Concept and Types
In VChart, Series are the core building blocks of visual charts, responsible for mapping data into visual expressions. A series represents a set of related data items that share the same visual representation (such as line, bar, etc.). Series are converters from data to graphics, including data processing, coordinate mapping, visual encoding, and other functions. Each series type corresponds to a specific visual representation form, with unique data structure requirements and visual mapping rules.
Basic and Coordinate System Classes
base: Basic implementation of series, providing common functions for all series
cartesian: Cartesian coordinate system base class, used for X-Y axis series
polar: Polar coordinate system base class, used for circular and radial series
geo: Geographic coordinate system base class, used for map-related series
Cartesian Coordinate System Series
bar: Bar chart, used for category data comparison
line: Line chart, showing data trends and changes
area: Area chart, emphasizing cumulative changes in data volume
scatter: Scatter plot, showing the distribution of data points
box-plot: Box plot, displaying data distribution and outliers
dot: Dot plot, simplified scatter plot
heatmap: Heatmap, using color intensity to represent value size
range-area: Range area chart, showing upper and lower boundary areas
range-column: Range column chart, showing data range
Extract data from the spec's data or option and convert it into a DataView
Then register a Listener, which triggers the rawDataUpdate function when the data changes
Add index and key to the Data
Then we will generate DataViews of different levels
If stacked data is needed, we create an intermediate DataView
If stacked data is not needed, directly create viewData, which is used by the chart for statistics and rendering
What is a DataView?
It is a view encapsulation of a data set, providing a series of operations and capabilities to transform data. You can think of a DataView as an "intelligent data container" that not only stores data but also processes and transforms it in various ways.
Create a series of statistics, such as maximum, minimum, etc. The statistics generated by different types of charts may vary. The specific chart's series class will implement this `abstract function getStatisticFields` to control what Statistics are generated.
```xml
abstract getStatisticFields(): {
key: string;
operations: StatisticOperations;
}[];