Geometry

The type of the chart is determined by geometry.

chart.<geomType>()
  .position()
  .size()
  .color()
  .shape()
  .adjust()
  .style()
  .animate();

The following is a simple grammar for a basic bar chart..

chart.interval().position('x*y').color('x');

NOTE: The return of the above method chart.interval() is a geom instance, not a chart instance.

Currently we support 7 geometry types:

Type

Description

point

point, used for drawing point chart, scatter chart, bubble chart.

path

path, a line of unordered connected.

line

line, used for drawing line chart, and the data will be ordered.

area

area, used for drawing area chart

interval

used to form a bar chart or a pie chart.

polygon

It is usually used to form heat map chart or map.

schema

Used to form a candlesticks chart or box chart.

Properties

generatePoints

  • type: Boolean

  • description: Wether to generate multiple points to draw charts, if true, multiple points will be generated.

  • default: false for line and path, other geometry types default to be true.

sortable

  • type: Boolean

  • description: Whether to sort the data according to the corresponding field of the x-axis, and sort it when true

  • default: true for area and line, other geometry types default to be false.

Note: When drawing a line or area chart, if your data has been sorted, you can set this property to false to improve performance.

startOnZero

  • type: Boolean

  • description: Wether to set the baseline of the y-axis starting from 0, default to be true, means starts from 0.

  • default: true

The usage scenarios for this property are as follows:

startOnZero: true

startOnZero: false

connectNulls

  • type: Boolean

  • description: Used to set whether to connect empty data (for line, area and path types)

  • default: false

connectNulls: true

connectNulls: false

Methods

position()

Declare the two data fields which determine the position of data points. Choose one of the following two ways to declare:

The following code will render a bar chart, which the x-axis representing the fruit and the y-axis representing the price.

color()

A method of mapping data values ​​to the color of the geometry.

color(value)

  • value: String

At this time, value can be:

  • The data field mapped to the color attribute. If the field name does not exist in the data, it will be parsed as a constant. This time, the default color provided by F2 will be used.

  • also can be a specific color value, such as 'red', '#ddd', '#dddddd', 'rgb(255, 10, 30)' or 'l(0) 0:#ffffff 0.5:#7ec2f3 1:#1890ff'.

color(fieldName, colors)

  • fieldName: String

    Data field name mapped to colors, multiple fields are supported.

  • colors: String / Array / Function

    • If colors is null, the built-in colors are used;

    • If you need to specify colors, you need to pass in an color array.

    • When the map field is a linear scale type(for continuous quantitative data), you can declare the gradient color as follows, detailed demo here.

  • Colors can also be a callback function, the parameters of the callback are the data field values. If the function is going to map multiple data fields, parameters will be passed in the declared order, for example:

shape()

A method of mapping data values ​​to the shape of the geometry.

shape(shapeName)

  • shapeName: String

Specify the shape that the geometry draws. The following table lists the shapes supported by different geometry types:

Geometry Type

Supported Shape

Description

point

'circle', 'hollowCircle', 'rect'

'circle' is default

line

'line', 'smooth', 'dash'

'line' is default, 'dash': dash line, 'smooth': smooth line

area

'area', 'smooth'

'area' is default

interval

'rect'

polygon

'polygon'

schema

'candle'

only candlestick chart is supported currently

shape(fieldName, shapes)

  • fieldName: String

    The name of the data field that maps to the shape attribute.

  • shapes: String / Array / Function

    shapes is an optional parameter.

    • If this parameter is not provided, shapes will be rendered defaultly.

    • Users can also specify shapes to render. The specific shapes are listed above.

    • shapes can also be a callback function, the parameters of the callback are the data field values. If the function is going to map multiple data fields, parameters will be passed in the declared order, for example:

size()

A method of mapping data values ​​to the size of the geometry.

size(field, [ min, max ])

Map the size of the geometry based on the value of the field, the maximum value (default to 10) and minimum value (default to 1) are specified by max and min.

size(field, callback)

Use callback function to calculate the size of the geometry.

adjust()

Declare the data adjustment method for the geometry instance, which can be used to draw stacked charts, grouped charts, etc.

F2 supports two kinds of data adjustment: stack and dodge.

style()

Used to configure the display the geometries, see Canvas for more details.

There are two ways to use style() method:

style(cfg)

  • cfg: Object, configuration for graphical attributes, see Canvas for more details.

style(field, cfg)

Mapping from data fields to style configuration.

  • field: String, field name of data

  • cfg: Object, configuration for graphical attributes, callback is also supported here

animate()

Configuration for geometry's animation.Includes animation type, duration time and easing function and so on.

For more about animations, see Animation.

Last updated