欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue中使用詞云圖的實(shí)現(xiàn)示例

 更新時(shí)間:2022年01月28日 08:43:54   作者:木豆mudou  
本文主要介紹了vue中使用詞云圖的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

在vue中, 查找到有兩種方法來實(shí)現(xiàn)詞云圖, 分別是echarts 和 highcharts

Echarts:

注意,wordcloud對應(yīng)的echarts版本有要求:echarts-wordcloud@2 is for echarts@5 echarts-wordcloud@1 is for echarts@4

需要下載echartsjs 和 wordcloud, 全局注冊引用echarts

	npm install echarts@5
	npm install echarts-wordcloud@2
<div class="cloud-wrap">
    <div ref="cloudEl" class="cloud-box"></div>
</div>
<style>
.cloud-wrap {
    width: 100%;
    height: 100%;
}
 .cloud-box {
     width: 100%;
     height: 100%;
 }
</style>
<script>
import wordcloud from 'echarts-wordcloud';
export default {
	data() {
		return {
			words:[{
				id:1,
				content:'name'
			}],
			bgImg:'base64格式, 底色為白色', 
		}
	},
	mounted() {
      this.drawCloud(this.$refs.cloudEl, this.words);
  	},
  	methods:{
	  	drawCloud(wrapEl, data) {
	        // let maskImage = new Image(); //可以根據(jù)圖片形狀生成有形狀的詞云圖
	        // maskImage.src= this.bgImg;
	        let list = this.wordCloudData.map((item) => ({
	            name: item.content,
	            value: item.id
	        }))
	        if(list.length == 0){
	            list = [{name:'無',value:50}]
	        }
	        let myChart = echarts.init(wrapEl);
	        let option = 
	        {
	            tooltip: {
	                show: true,
	            },
	            // backgroundColor:'#fff', // 畫布背景色
	            series: [
	            {
	                name: "熱詞",
	                type: "wordCloud",
	                // maskImage: maskImage, // 圖片形狀
	                keepAspect: false,
	                sizeRange: [10, 40], //畫布范圍,如果設(shè)置太大會出現(xiàn)少詞(溢出屏幕)
	                rotationRange: [0, 0], //數(shù)據(jù)翻轉(zhuǎn)范圍
	                // shape: "circle",
	                // drawOutOfBound: true, // 超出畫布的詞匯是否隱藏
	                drawOutOfBound: false,
	                color:"#fff",
	                left: "center",
	                top: "center",
	                right: null,
	                bottom: null,
	                // width: "100%",
	                height: "100%",
	                gridSize: 8,
	                textPadding: 10,
	                autoSize: {
	                    enable: true,
	                    minSize: 6,
	                },
	                textStyle: {
	                    normal: {
	                        fontFamily: 'sans-serif',
	                        fontWeight: 'bold',
	                        color:"#333", // 字體顏色
	                        // color: function () { // 字體顏色
	                        //     return 'rgb(' + [
	                        //         Math.round(Math.random() * 160),
	                        //         Math.round(Math.random() * 160),
	                        //         Math.round(Math.random() * 160)
	                        //     ].join(',') + ')';
	                        // },
	                    },
	                    emphasis: {
	                        // focus: 'self',
	                        textStyle:{
	                            shadowBlur: 10,
	                            shadowColor: "#333",
	                        }
	                    },
	                },
	                data: list,
	            },
	            ],
	        };
	        // maskImage.onload = function() {
	            myChart.setOption(option, true)
	        // };
	    },
  	}
}
</script>

1

無遮罩層的詞云圖↑

2

有遮罩層的詞云圖↑

Highcharts

下載包

npm install highcharts@7.2.1
<div class="cloud-wrap">
    <div id="container" style="width: 100%;height: 100%;"></div>
</div>
<style>
	// 同上
</style>
<script>
import Highcharts from 'highcharts'
export default {
	data() {
		return {
			words:[{
				id:1,
				content:'name'
			}],
		}
	},
	mounted() {
      this.dealData();
  	},
  	methods:{
	    dealData(){
	        let data = this.words.map((item,index) => ({
	            name: item.content,
	            value: item.id,
	            //weight: Math.floor(Math.random()*3+1)
	            //控制加粗,隨機(jī)數(shù)取1~3, 若需要按照接口返回的順序, 可不隨機(jī)
	            weight: item.id*100 
	        }))
	        this.drawPic(data)
	    },
	    drawPic(data){
	        Highcharts.chart('container', {
	            //highcharts logo
	            credits: { enabled: false },
	            //導(dǎo)出
	            exporting: { enabled: false },
	            //提示關(guān)閉
	            tooltip: { enabled: false },
	            //顏色配置
	            colors:[
	                '#ffffff'
	                // ,'#00c0d7','#2594ce','#de4c85',
	                // '#ff7f46','#ffb310','#e25c52'
	            ],
	            //圖形配置
	            chart: {
	                // spacingBottom: 15,
	                // spacingTop: 12,
	                spacingLeft: 5,
	                spacingRight: 5,
	                backgroundColor: "rgba(255, 255, 255,0)",
	            },
	
	            series: [{
	                type: "wordcloud",// 類型
	                data: data,
	                rotation: 90,//字體不旋轉(zhuǎn)
	                maxFontSize: 40,//最大字體
	                minFontSize: 14,//最小字體
	                style: {
	                    fontFamily: "sans-serif",
	                    fontWeight: '500'
	                }
	            }],
	        });
	    },
  	}
}
</script>

在這里插入圖片描述

echarts 和 highcharts 都可以在vue中實(shí)現(xiàn)詞云圖. 但是如果使用echarts的話, 需要當(dāng)前的echarts進(jìn)行升級或降級才能實(shí)現(xiàn)字體多顏色, 而highcharts則不需要. 自定義形狀highcharts暫時(shí)還沒探究, 需要的可以自行查找, 以后有機(jī)會的話我也會看看.

到此這篇關(guān)于vue中使用詞云圖的文章就介紹到這了,更多相關(guān)vue中使用詞云圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 實(shí)例分析vue循環(huán)列表動態(tài)數(shù)據(jù)的處理方法

    實(shí)例分析vue循環(huán)列表動態(tài)數(shù)據(jù)的處理方法

    本篇文章給大家詳細(xì)分享了關(guān)于vue循環(huán)列表動態(tài)數(shù)據(jù)的處理方法以及相關(guān)知識點(diǎn)內(nèi)容,有需要的朋友們參考下。
    2018-09-09
  • vue移動端寫的拖拽功能示例代碼

    vue移動端寫的拖拽功能示例代碼

    這篇文章主要介紹了vue移動端寫的拖拽功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-09-09
  • Vue精簡版風(fēng)格指南(推薦)

    Vue精簡版風(fēng)格指南(推薦)

    這篇文章主要介紹了Vue精簡版風(fēng)格指南的相關(guān)資料,包括組件名稱,指令及特征,需要的朋友可以參考下
    2018-01-01
  • Vue.js構(gòu)建你的第一個(gè)包并在NPM上發(fā)布的方法步驟

    Vue.js構(gòu)建你的第一個(gè)包并在NPM上發(fā)布的方法步驟

    這篇文章主要介紹了Vue.js構(gòu)建你的第一個(gè)包并在NPM上發(fā)布的方法步驟,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2019-05-05
  • 計(jì)算屬性和偵聽器詳情

    計(jì)算屬性和偵聽器詳情

    這篇文章主要介紹了計(jì)算屬性和偵聽器,文章以介紹計(jì)算屬性、偵聽器的相關(guān)資料展開詳細(xì)內(nèi)容,需要的朋友可以參考一下,希望對你有所幫助
    2021-11-11
  • vue 登錄滑動驗(yàn)證實(shí)現(xiàn)代碼

    vue 登錄滑動驗(yàn)證實(shí)現(xiàn)代碼

    這篇文章主要介紹了vue 登錄滑動驗(yàn)證實(shí)現(xiàn)代碼,代碼簡單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-08-08
  • Vue——前端生成二維碼的示例

    Vue——前端生成二維碼的示例

    這篇文章主要介紹了Vue——前端生成二維碼的示例,幫助大家更好的理解和使用vue框架,感興趣的朋友可以了解下
    2020-12-12
  • 基于vue實(shí)現(xiàn)圖片驗(yàn)證碼倒計(jì)時(shí)60s功能

    基于vue實(shí)現(xiàn)圖片驗(yàn)證碼倒計(jì)時(shí)60s功能

    這篇文章主要介紹了基于vue實(shí)現(xiàn)圖片驗(yàn)證碼倒計(jì)時(shí)60s功能,本文通過截圖實(shí)例代碼的形式給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-12-12
  • el-form-renderer使用教程

    el-form-renderer使用教程

    本文主要介紹了el-form-renderer使用教程,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-05-05
  • vue3?process.env.XXX環(huán)境變量不生效的解決方法

    vue3?process.env.XXX環(huán)境變量不生效的解決方法

    這篇文章主要給大家介紹了關(guān)于vue3?process.env.XXX環(huán)境變量不生效的解決方法,通過文中介紹的方法可以很方便的解決遇到的問題,對大家學(xué)習(xí)或者使用vue3具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-08-08

最新評論