Canvas API in F2
Last updated
Last updated
Since F2 use html5 canvas as its renderer, all charts drawn support the attributes of the canvas. This chapter lists commonly used properties, see Canvas Attributes for more details.
Name
Description
fill
the color or style to use inside shapes, can be a color string, aCanvasGradient
object (a linear or radial gradient) or a CanvasPattern
object (a repetitive image).
fillStyle
same as fill
stroke
the color or style to use for the lines around shapes, can be a color string, a CanvasGradient
object (a linear or radial gradient) or a CanvasPattern
object (a repetitive image).
strokeStyle
same as stroke
shadowColor
the color of the shadow.
shadowBlur
shadowOffsetX
shadowOffsetY
opacity
globalOpacity
same as opacity
.
globalCompositionOperation
sets the type of compositing operation to apply when drawing new shapes, where type is a string identifying which of the compositing or blending mode operations to use. See MDN.
For the convenience of users, F2 provides support for two types of gradient color:
Linear gradient
Radial gradient
Name
Description
lineCap
determines how the end points of every line are drawn. There are three possible values for this property and those are: butt
, round
and square
. By default this property is set to butt
. See MDN.
lineJoin
determines how two connecting segments (of lines, arcs or curves) with non-zero lengths in a shape are joined together (degenerate segments with zero lengths, whose specified endpoints and control points are exactly at the same position, are skipped). See MDN.
lineWidth
miterLimit
lineDash
An Array
of numbers which specify distances to alternately draw a line and a gap (in coordinate space units). If the number of elements in the array is odd, the elements of the array get copied and concatenated. For example, [5, 15, 25]
will become [5, 15, 25, 5, 15, 25]
. If the array is empty, the line dash list is cleared and line strokes return to being solid.
Name
Description
textAlign
specifies the horizontal alignment of text in an element. The value can be set same as css property text-align.
textBaseline
sets the vertical alignment of an element. The value can be set same as css property vertical-align.
fontStyle
specifies the font style for text. The value can be set same as css property font-style.
fontSize
specifies the font size of text. The value can be set same as css property font-size.
fontFamily
specifies the font family for text.The value can be set same as css property font-family.
fontWeight
specifies the weight of a font. The value can be set same as css property font-weight.
fontVariant
specifies whether or not a text should be displayed in a small-caps font. The value can be set same as css property font-variant.
lineHeight
specifies the height of a line. The value can be set same as css property line-height.
roate
rotation angle for text, should be a radian value.