1# CanvasGradient 2 3> **NOTE** 4> 5> This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version. 6 7**CanvasGradient** provides a gradient object. 8 9## addColorStop 10 11addColorStop(offset: number, color: string): void 12 13Adds a color stop for the **CanvasGradient** object based on the specified offset and gradient color. 14 15**Parameters** 16 17| Name | Type | Description | 18| ------ | ------ | ------------------------------------------------------------ | 19| offset | number | Proportion of the distance between the color stop and the start point to the total length. The value ranges from 0 to 1. | 20| color | string | Gradient color to set. | 21 22**Example** 23 24 ```html 25<!-- xxx.hml --> 26<div> 27 <canvas ref="canvas" style="width: 500px; height: 500px; background-color: #ffff00;"></canvas> 28</div> 29 ``` 30 31 ```js 32// xxx.js 33export default { 34 onShow() { 35 const el =this.$refs.canvas; 36 const ctx = el.getContext('2d'); 37 const gradient = ctx.createLinearGradient(50,0,300,100); 38 gradient.addColorStop(0.0, '#ff0000') 39 gradient.addColorStop(0.5, '#ffffff') 40 gradient.addColorStop(1.0, '#00ff00') 41 ctx.fillStyle = gradient 42 ctx.fillRect(0, 0, 300, 300) 43 } 44} 45 ``` 46 47  48