最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue+canvas如何實(shí)現(xiàn)根據(jù)數(shù)據(jù)展示不同高度,不同漸變顏色的長(zhǎng)方體效果

 更新時(shí)間:2024年09月06日 08:54:56   作者:言不及行yyds  
這篇文章主要介紹了vue+canvas如何實(shí)現(xiàn)根據(jù)數(shù)據(jù)展示不同高度,不同漸變顏色的長(zhǎng)方體效果,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

不一樣的長(zhǎng)方體

1. 實(shí)現(xiàn)效果預(yù)覽

俗話(huà)說(shuō)的好,沒(méi)有實(shí)現(xiàn)不了的頁(yè)面效果,只有禁錮的思想,

這不ui又給整了個(gè)新奇的頁(yè)面效果,

2.實(shí)現(xiàn)思路

2.1效果難點(diǎn)

  • 根據(jù)不同的數(shù)據(jù)展示不同的顏色,而且需要漸變并有塊狀效果。
  • 繪制多個(gè)單獨(dú)的區(qū)域

2.2 實(shí)現(xiàn)思路

3.實(shí)現(xiàn)

3.1 測(cè)試數(shù)據(jù)編寫(xiě)

testData1:[
{ name:“庫(kù)房1”, now:888, extends:1800 },
{ name:“庫(kù)房2”, now:988, extends:1700 },
{ name:“庫(kù)房3”, now:488, extends:2200 },
{ name:“庫(kù)房4”, now:1888, extends:800 },
{ name:“庫(kù)房5”, now:1088, extends:1600 },
{ name:“庫(kù)房6”, now:1388, extends:1300 },
{ name:“庫(kù)房7”, now:288, extends:2400 },
{ name:“庫(kù)房8”, now:888, extends:1800 },
{ name:“庫(kù)房9”, now:888, extends:1800 },
{ name:“庫(kù)房10”, now:1888, extends:800 },
{ name:“庫(kù)房11”, now:1288, extends:1400 },
{ name:“庫(kù)房12”, now:1488, extends:1200 },
{ name:“庫(kù)房13”, now:1888, extends:800 },
{ name:“庫(kù)房14”, now:188, extends:2500 },
{ name:“庫(kù)房2”, now:988, extends:1700 },
{ name:“庫(kù)房3”, now:488, extends:2200 },
{ name:“庫(kù)房4”, now:1888, extends:800 },
{ name:“庫(kù)房5”, now:1088, extends:1600 },
{ name:“庫(kù)房13”, now:1888, extends:800 },
{ name:“庫(kù)房14”, now:188, extends:2500 },
{ name:“庫(kù)房3”, now:488, extends:2200 },
{ name:“庫(kù)房4”, now:1888, extends:800 },
{ name:“庫(kù)房5”, now:1088, extends:1600 },
],

3.2 編寫(xiě)canvas繪制函數(shù)

  • js部分
draw(i,item){
      canvas = document.getElementById(`myCanvas${i}`);
      const ctx = canvas.getContext('2d');
      
     // 定義矩形塊的寬度和高度
 	const rectWidth = canvas.width;
    const rectHeight = canvas.height/8;

    // 定義矩形塊之間的間距
    const rectSpacing = 0.25 ;

    // 定義要繪制的行數(shù)和列數(shù)
    //其中2688代表測(cè)試數(shù)據(jù)中的now+extends的總和,
    //可根據(jù)具體情況自己調(diào)整
     const numRows = Math.ceil(item.now*10/2688);
     const numCols = 1;

     let color=[]
     if(Math.ceil(item.now*10/2688) >= 7){
           color[0]='#EE5E5D'
           color[1]='#FFECEC'
      }else if(Math.ceil(item.now*10/2688) >= 4){
           color[0]='#EEA750'
           color[1]='#FFF0DD'
      }else{
           color[0]='#4BCBA6'
           color[1]='#9EFAE0'
       }
     // 繪制矩形塊
     for (let row = 0; row < numRows; row++) {
          for (let col = 0; col < numCols; col++) {
                const x = col * (rectWidth + rectSpacing);
                const y = row * (rectHeight + rectSpacing);
                // 設(shè)置矩形塊的顏色
                const grd = ctx.createLinearGradient(canvas.width/2, 0,canvas.width/2,canvas.height);
                grd.addColorStop(0, color[1]);
                grd.addColorStop(1,color[0]);
                // 用漸變填充
                ctx.fillStyle = grd;
				// 繪制矩形塊
                ctx.fillRect(x, y, rectWidth, rectHeight);
                }
            }
        }
  • html部分
 <ul>
     <li v-for="item,index in testData1" :key="index">
         <p class="title">{{item.now}}/{{item.extends}}m3</p>
         <div class="show">
             <canvas :id="`myCanvas${index}`" class="canvas"></canvas>
         </div>
          <p class="storeName">{{item.name}}</p>
     </li>
 </ul>
  • scss部分
container{
    width:100%;
    height:100%;
    position:relative;
        ul{
            display:grid;
            margin-top:20px;
            margin-left:10px;
            width:97%;
            grid-template-columns: repeat(10,1fr);
            gap:10px;
            font-family: Source Han Sans-Regular, Source Han Sans;
            li{
                width:100%;
                aspect-ratio: 1 / 1.5;
                background: #FFFFFF;
                box-shadow: 0px 8px 14px 0px rgba(48,78,121,0.5);
                border-radius: 4px;
                position:relative;
                text-align: center;
                .title{
                    font-size: 14px;
                    font-weight: 400;
                    color: #929292;
                    margin-top:14px;
                }
                .show{
                   width:33%;
                   height:70%;
                   background: #EFF2F7;
                   margin:10px auto;
                   border-radius: 4px;
                   .canvas{
                        width:100%;
                        height:100%;
                        transform: rotate(180deg);
                   }
                }
            }
        }
}

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue項(xiàng)目中components組件(模板)的使用及說(shuō)明

    Vue項(xiàng)目中components組件(模板)的使用及說(shuō)明

    這篇文章主要介紹了Vue項(xiàng)目中components組件(模板)的使用及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • vant的picker組件設(shè)置文字超長(zhǎng)滾動(dòng)方式

    vant的picker組件設(shè)置文字超長(zhǎng)滾動(dòng)方式

    這篇文章主要介紹了vant的picker組件設(shè)置文字超長(zhǎng)滾動(dòng)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • vue+animation動(dòng)畫(huà)實(shí)現(xiàn)跑馬燈效果

    vue+animation動(dòng)畫(huà)實(shí)現(xiàn)跑馬燈效果

    這篇文章主要為大家詳細(xì)介紹了vue+animation動(dòng)畫(huà)實(shí)現(xiàn)跑馬燈效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • vue3 數(shù)組間取消強(qiáng)關(guān)聯(lián)的幾種實(shí)現(xiàn)方法

    vue3 數(shù)組間取消強(qiáng)關(guān)聯(lián)的幾種實(shí)現(xiàn)方法

    在Vue3中,如果你想要從一個(gè)數(shù)組中獲取數(shù)據(jù)并替換另一個(gè)數(shù)組中的數(shù)據(jù),但又不想讓這些數(shù)組之間存在強(qiáng)關(guān)聯(lián),你可以通過(guò)使用數(shù)組的拷貝、展開(kāi)運(yùn)算符或使用數(shù)組的slice()方法來(lái)實(shí)現(xiàn),感興趣的可以了解一下
    2025-11-11
  • 詳解vue-router 2.0 常用基礎(chǔ)知識(shí)點(diǎn)之router-link

    詳解vue-router 2.0 常用基礎(chǔ)知識(shí)點(diǎn)之router-link

    這篇文章主要介紹了詳解vue-router 2.0 常用基礎(chǔ)知識(shí)點(diǎn)之router-link,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • vue組件之Alert的實(shí)現(xiàn)代碼

    vue組件之Alert的實(shí)現(xiàn)代碼

    本篇文章主要介紹了vue組件之Alert的實(shí)現(xiàn)代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-10-10
  • Vue實(shí)現(xiàn)靜態(tài)資源的OSS部署的完整指南

    Vue實(shí)現(xiàn)靜態(tài)資源的OSS部署的完整指南

    在大型前端項(xiàng)目的生產(chǎn)環(huán)境部署中,靜態(tài)資源(JS、CSS、字體文件等)通常占據(jù)較大的體積,將這些資源部署到對(duì)象存儲(chǔ)服務(wù)(OSS)并通過(guò) CDN 加速,可以帶來(lái)很多優(yōu)勢(shì),所以本文給大家介紹了Vue實(shí)現(xiàn)靜態(tài)資源的OSS部署的完整指南,需要的朋友可以參考下
    2025-11-11
  • Vue3+Springboot實(shí)現(xiàn)前后端防抖增強(qiáng)的示例代碼

    Vue3+Springboot實(shí)現(xiàn)前后端防抖增強(qiáng)的示例代碼

    這篇文章主要為大家詳細(xì)介紹了Vue3如何結(jié)合Springboot實(shí)現(xiàn)前后端防抖增強(qiáng)功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2025-06-06
  • vue+element-ui JYAdmin后臺(tái)管理系統(tǒng)模板解析

    vue+element-ui JYAdmin后臺(tái)管理系統(tǒng)模板解析

    這篇文章主要介紹了vue+element-ui JYAdmin后臺(tái)管理系統(tǒng)模板解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • Vue結(jié)合Element-Plus封裝遞歸組件實(shí)現(xiàn)目錄示例

    Vue結(jié)合Element-Plus封裝遞歸組件實(shí)現(xiàn)目錄示例

    本文主要介紹了Vue結(jié)合Element-Plus封裝遞歸組件實(shí)現(xiàn)目錄示例,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04

最新評(píng)論

襄垣县| 夏河县| 香格里拉县| 老河口市| 成武县| 布尔津县| 瓦房店市| 体育| 沁水县| 怀集县| 长沙市| 巴楚县| 太仓市| 河东区| 曲阜市| 阳泉市| 新田县| 普兰县| 陵川县| 旬邑县| 秦安县| 湟源县| 汕头市| 青田县| 慈利县| 平和县| 普兰县| 澄江县| 江北区| 临城县| 贵阳市| 韩城市| 平阳县| 金沙县| 南通市| 沙田区| 长春市| 景洪市| 东莞市| 乐安县| 水城县|