image
Previous
heatmap
Next
interval
Loading...
The image
mark usually does not appear independently and is mainly used as an addition to other marks, which can enhance the visual effect of data and help convey information more intuitively. It is very similar to the point
mark, both using x
and y
data channels for centered positioning. The difference is that image
provides a special src
data channel to specify the remote address or base64 of the image.
import { Chart } from '@antv/g2';const chart = new Chart({container: 'container',});chart.options({width: 200,height: 60,type: 'image',data: [{x: '1',y: 1,url: 'https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*TRZHTaTeWfEAAAAAAAAAAAAAemJ7AQ/original',},{x: '2',y: 1,url: 'https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*TRZHTaTeWfEAAAAAAAAAAAAAemJ7AQ/original',},{x: '3',y: 1,url: 'https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*TRZHTaTeWfEAAAAAAAAAAAAAemJ7AQ/original',},{x: '4',y: 1,url: 'https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*qCegRabhuUIAAAAAAAAAAAAAemJ7AQ/original',},{x: '5',y: 1,url: 'https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*GNP1RLFfQV0AAAAAAAAAAAAAemJ7AQ/original',},{x: '1',y: 2,url: 'https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*TRZHTaTeWfEAAAAAAAAAAAAAemJ7AQ/original',},{x: '2',y: 2,url: 'https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*TRZHTaTeWfEAAAAAAAAAAAAAemJ7AQ/original',},{x: '3',y: 2,url: 'https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*qCegRabhuUIAAAAAAAAAAAAAemJ7AQ/original',},{x: '4',y: 2,url: 'https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*GNP1RLFfQV0AAAAAAAAAAAAAemJ7AQ/original',},{x: '5',y: 2,url: 'https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*GNP1RLFfQV0AAAAAAAAAAAAAemJ7AQ/original',},],// Configure visual channelsencode: {x: 'x', // Configure x channely: 'y', // Configure y channelsrc: 'url', // Configure image src channel},axis: { x: false, y: false },});chart.render();
For more examples, you can visit the Chart Examples - Image page.
Configure the visual channels of the image
mark.
Property | Description | Type | Default | Required |
---|---|---|---|---|
x | Bind the x property channel of the image mark, usually a numeric or character value from data to determine the x position of the image | encode | - | ✓ |
y | Bind the y property channel of the image mark, usually a numeric or character value from data to determine the y position of the image | encode | - | ✓ |
size | Bind the size channel of the image mark to control the display size of the image. Generally, the more information stored in the image, the more it needs to be enlarged | encode | - | |
src | Bind the src image channel of the image mark, which will display images based on the corresponding data | - | ✓ |
The final rendering is handled by G, so the supported data types are consistent with G's atomic Image graphic, supporting:
Remote URL
: Network addressfile
: Local image pathbase64
: Chart base64 format stringblob
: Blob object returned from image requestProperty | Description | Type | Default | Required |
---|---|---|---|---|
width | Width of the graphic. If not configured, the image is displayed by default according to its natural width and size | number | Function<number> | - | |
height | Height of the graphic. If not configured, the image is displayed by default according to its natural height and size | number | Function<number> | - | |
opacity | Overall opacity of the graphic | number | Function<number> | - | |
shadowColor | Shadow color of the graphic | string | Function<string> | - | |
shadowBlur | Gaussian blur coefficient of the graphic shadow | number | Function<number> | - | |
shadowOffsetX | Horizontal distance of the shadow from the graphic | number | Function<number> | - | |
shadowOffsetY | Vertical distance of the shadow from the graphic | number | Function<number> | - | |
cursor | Mouse cursor style. Same as CSS cursor style, default 'default' | string | Function<string> | default |
Try it out: