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

vue使用echarts實(shí)現(xiàn)水平柱形圖實(shí)例

 更新時(shí)間:2020年09月09日 17:37:07   作者:走_(dá)開(kāi)  
這篇文章主要介紹了vue使用echarts實(shí)現(xiàn)水平柱形圖實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

文件結(jié)構(gòu):

testData.js文件

const dtuEdition = {
 name: '有方有線',
 number: 60,
 proportion: 40,
 edition: {
 '有方有線V1.0.0': 20,
 '有方有線V1.2.0': 15,
 '有方有線V2.0.1': 10,
 '有方有線V3.0.0': 8,
 '有方有線V3.2.0': 5,
 '有方有線V3.4.0': 4,
 '有方有線V4.0.0': 3,
 '有方有線V4.0.2': 2,
 '有方有線V4.0.3': 1
 }
} 
export default {
 namespaced: true, // 用于在全局引用此文件里的方法時(shí)標(biāo)識(shí)這一個(gè)的文件名
 dtuEdition
}

dtuDistributionCurve.js文件

// DTU連接率bar圖的option
let barOption = {
 grid: {
 // width: '85%', // 設(shè)置gird寬度
 left: 40, // gird距離容器左邊距
 right: 65,
 top: 20,
 bottom: 0,
 containLabel: true
 },
 xAxis: {
 show : false, // 不顯示橫軸
 type: 'value',
 max: 1000, // 橫軸最大值
 },
 yAxis: {
 type: 'category',
 data: [],
 axisLine: {
  show: false
 },
 axisTick: {
  show: false
 },
 splitLine: {
  show: false
 }
 },
 series: [{
 type: 'bar',
 stack: 'chart',
 z: 3,
 itemStyle: {
  normal: {
  color: '#a7c7e9'
  }
 },
 data: []
 }, {
 type: 'bar',
 stack: 'chart',
 silent: true,
 label: {
  normal: {
  formatter: (params) => {
   // console.log(params)
   return barOption.xAxis.max-params.value
  },
  color: '#666666',
  position: 'right',
  distance: 10,
  show: true
  }
 },
 itemStyle: {
  normal: {
  color: '#f3f3f6'
  }
 },
 barWidth : 10,//柱圖寬度
 data: []
 }]
}
 
// 設(shè)置y軸標(biāo)簽
export function setYAxisData(edition) {
 let data = []
 for (let key in edition) {
 data.push(key)
 }
 barOption.yAxis.data = data.reverse()
 console.log(barOption.yAxis.data)
}
 
// 設(shè)置x軸最大值
export function setXAxisMax(number) {
 barOption.xAxis.max = number
}
 
// 設(shè)置series的data數(shù)據(jù)
export function setSeriesData(edition, number) {
 let data0 = []
 let data1 = []
 for(let key in edition) {
 data0.push(edition[key])
 data1.push(number - edition[key])
 }
 barOption.series[0].data = data0.reverse()
 barOption.series[1].data = data1.reverse()
}
 
export default {
 barOption,
 setYAxisData,
 setXAxisMax,
 setSeriesData
}

vue文件

<template>
 <div ref="dtuEdition" class="project-survey-dtu-edition"></div>
</template>
 
<script>
 import testData from '../constvalue/testData'
 import dtuDistributionOption from '../curveoption/dtuDistributionCurve'
 export default {
  name: 'ProjectSurvey',
  data() {
   return {
 dtuEditionChart: null
 }
  },
 
  methods: {
 // 點(diǎn)擊DTU模塊數(shù)量分布展示圖的扇區(qū)item
 distributionChartClick(param) {
 console.log(param)
 let dtuEdition = testData.dtuEdition
 this.dtuName = dtuEdition.name
 this.dtuNumber = dtuEdition.number
 this.dtuProportion = dtuEdition.proportion + '%'
 dtuDistributionOption.setYAxisData(dtuEdition.edition)
 dtuDistributionOption.setXAxisMax(dtuEdition.number)
 dtuDistributionOption.setSeriesData(dtuEdition.edition, dtuEdition.number)
 this.dtuEditionChart.setOption(dtuDistributionOption.barOption)
 this.dtuEditionChart.resize()
 },
 // 點(diǎn)擊tab的某頁(yè)
 tabClick(tab, event) {
 console.log(this.activeName)
 if(this.activeName === 'first') { // 從后端獲取連接率統(tǒng)計(jì)數(shù)據(jù)
 
 } else { // 從后端獲取模塊數(shù)量分布展示數(shù)據(jù)
  let distributionInfo = testData.dtuDistribution.distributionInfo
  this.deadline = testData.dtuDistribution.deadline
  dtuDistributionOption.setSectorValue(distributionInfo)
    dtuDistributionOption.setSectorName(testData.dtuDistribution.allDistribution)
  this.distributionChart.setOption(dtuDistributionOption.pieOption)
  this.distributionChart.resize()
  this.distributionChart.on('click', this.distributionChartClick)
 }
 }
 },
 mounted() {
 this.dtuEditionChart = this.$echarts.init(this.$refs.dtuEdition)
 this.distributionChart = this.$echarts.init(this.$refs.dtuDistribution)
 let maxV = this.getMaxV()
 let minV = this.getMinV()
 for(let item of this.connectionInfo) {
 this.charts[item.dtuName] = this.$echarts.init(document.getElementById(item.dtuName))
 let normalizationRatio = this.normalization(item.connectionRatio, maxV, minV)
 dtuConnectionOption.setSectorColor(normalizationRatio)
 dtuConnectionOption.setTitleText(item.dtuName)
 dtuConnectionOption.setSectorValue(item.connectionRatio)
 dtuConnectionOption.setSectorName(item.connectionRatio)
 // console.log(dtuConnectionOption.option)
 this.charts[item.dtuName].setOption(dtuConnectionOption.option)
 this.charts[item.dtuName].resize()
 }
 window.onresize = () => {
 this.distributionChart.resize()
 this.dtuEditionChart.resize()
  }
 },
 updated() {
 this.distributionChart.resize()
 for(let item of this.connectionInfo) {
 this.charts[item.dtuName].resize()
 }
 } 
 
 }
</script>
 
<style>
 .project-survey-dtu-edition {
 height: 580px;
 }
</style>

圖表

補(bǔ)充知識(shí):vue+echart實(shí)現(xiàn) X軸 雙柱狀圖 漸變色

一: 安裝

1. 首先需要安裝echarts依賴包

npm install echarts -S

2. 或者使用國(guó)內(nèi)的淘寶鏡像:

npm install -g cnpm --registry=https://registry.npm.taobao.org

二: 創(chuàng)建圖表

全局引入

main.js

>```javascript
// 引入echarts
import echarts from 'echarts'
Vue.prototype.$echarts = echarts

Hello.vue

<div id="myChart" :style="{width: '300px', height: '300px'}"></div>

 export default {
 data(){
  return {}
 }, 
  mounted(){
  this.myChart() //函數(shù)調(diào)用
  },
  methods:{
  	myChart(){
	  let myChart= this.$echarts.init(document.getElementById('myChart'));
	  // var colors = ['rgba(15,115,255,0.6)', 'rgba(15,235,255,0.6)'];
	  var data1 = [350, 250, 170, 360, 240];
	  var data2 = [187, 146, 129, 174,245];
	  var xData = ['3.12','3.13','3.14','3.15','3.16']
	  rightBtns.setOption({
   // backgroundColor:'#fff',
   tooltip: {
    trigger: "axis",
    // formatter: '<br/>{a1}-違規(guī)率:{c1}<br/>{a0}-違規(guī)率:{c0}',
    axisPointer: {
     type: "shadow",
     textStyle: {
     color: "#fff"
     }
    },
   },
   grid: {
    top: '8%',
    right: '8%',
    bottom: '60%'
   },
   legend: {
    data: ['省內(nèi)', '省外'],
    align: 'left',
    left: '30%',
    top: '4%',
    textStyle:{
     color:'#fff'
    }
   },
   calculable: true,
   xAxis: [{
    type: "category",
    data: xData,
    axisLine: {
    lineStyle: {
     color: 'rgba(255,255,255,0.1)'
    },
    },
    axisLabel: {
    show: true,
    textStyle: {
     color: '#fff'
    }
    },
   }],
   yAxis: {
    type: 'value',
    // name:'單位:(人次 )',
    min: 0,
    max: 500,
    interval: 100,
    axisLine: {
    lineStyle: {
     color: 'rgba(255,255,255,0.1)'
    }
    },
    splitLine: {
    lineStyle: {
     type: 'dashed',
    },
    show:false
    },
    axisLabel: {
    show: true,
    textStyle: {
     color: '#fff'
    }
    },
   },
   series: [{
    name: '省內(nèi)',
    type: 'bar',
    // color: colors[0],
    data: data1,
    itemStyle:{
     normal: {
     //每個(gè)柱子的顏色即為colorList數(shù)組里的每一項(xiàng),如果柱子數(shù)目多于colorList的長(zhǎng)度,則柱子顏色循環(huán)使用該數(shù)組
     //此處的箭頭函數(shù)是為了不改變this的指向
     color: (params) => {
      var index = params.dataIndex;
      var colorList = [
      // 漸變顏色的色值和透明度
      //雙柱狀圖漸變的 第一個(gè)柱子的漸變色['rgba(15,235,255,0)','rgba(15,235,255,0)','rgba(15,235,255,0)','rgba(15,235,255,0)','rgba(15,235,255,0)'],
      ['rgba(15,235,255,0.6)','rgba(15,235,255,0.6)','rgba(15,235,255,0.6)','rgba(15,235,255,0.6)','rgba(15,235,255,0.6)'] 
      
      ];
      if(params.dataIndex >= colorList.length){
      index=params.dataIndex-colorList.length;
      }
      //方法一:
      //不使用箭頭函數(shù)的寫法改變漸變色
      // return {
      // colorStops: [{
      //  offset: 0, //顏色開(kāi)始的位置
      //  color: colorList[0][index] // 0% 處的顏色
      // },{
      //  offset: 0.6, //顏色結(jié)束的位置
      //  color: colorList[1][index] // 100% 處的顏色
      // }]
      // }
      //方法二:使用箭頭函數(shù)的寫法 改變雙柱狀圖的漸變顏色
      return new this.$echarts.graphic.LinearGradient(0,0,0,1,[
      {offset: 0.2, color: colorList[1][index]},
      {offset: 1, color: colorList[0][index]}
      ])
     }
     }
    }
   },
   {
    name: '省外',
    type: 'bar',
    // color: colors[1],
    data: data2,
    itemStyle:{
     normal: {
     //每個(gè)柱子的顏色即為colorList數(shù)組里的每一項(xiàng),如果柱子數(shù)目多于colorList的長(zhǎng)度,則柱子顏色循環(huán)使用該數(shù)組
     color: (params) => {
      var index = params.dataIndex;
      var colorList = [
      // 漸變顏色的色值和透明度
      //雙柱狀圖漸變的 漸變第二個(gè)柱子的漸變色['rgba(15,115,255,0)','rgba(15,115,255,0)','rgba(15,115,255,0)','rgba(15,115,255,0)','rgba(15,115,255,0)'],
      ['rgba(15,115,255,0.6)','rgba(15,115,255,0.6)','rgba(15,115,255,0.6)','rgba(15,115,255,0.6)','rgba(15,115,255,0.6)'] 
      ];
      //方法一:
      //不使用箭頭函數(shù)的寫法改變漸變色
      // return {
      // colorStops: [{
      //  offset: 0,
      //  color: colorList[0][index] // 0% 處的顏色
      // },{
      //  offset:0.6,
      //  color: colorList[1][index] // 100% 處的顏色
      // }]
      // }
      //方法二:使用箭頭函數(shù)的寫法 改變雙柱狀圖的漸變顏色
      return new this.$echarts.graphic.LinearGradient(0,0,0,1,[
      {offset: 0.2, color: colorList[1][index]},
      {offset: 1, color: colorList[0][index]}
      ])
     }
     }
    }
   }]
   })
  }
  }
	}

最終結(jié)果

以上這篇vue使用echarts實(shí)現(xiàn)水平柱形圖實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • vuex直接修改state、commit和dispatch修改state的用法及區(qū)別說(shuō)明

    vuex直接修改state、commit和dispatch修改state的用法及區(qū)別說(shuō)明

    這篇文章主要介紹了vuex直接修改state、commit和dispatch修改state的用法及區(qū)別說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • 在 Vue 應(yīng)用中使用 Netlify 表單功能的方法詳解

    在 Vue 應(yīng)用中使用 Netlify 表單功能的方法詳解

    Netlify 帶有內(nèi)置表單處理功能,可以用來(lái)存儲(chǔ)表單數(shù)據(jù),下載 csv 文件,同時(shí)可以在接收到新的提交時(shí)發(fā)送郵件通知或者通過(guò)配置 webhook 發(fā)送請(qǐng)求。這篇文章主要介紹了在 Vue 應(yīng)用中使用 Netlify 表單功能,需要的朋友可以參考下
    2019-06-06
  • axios全局請(qǐng)求參數(shù)設(shè)置,請(qǐng)求及返回?cái)r截器的方法

    axios全局請(qǐng)求參數(shù)設(shè)置,請(qǐng)求及返回?cái)r截器的方法

    下面小編就為大家分享一篇axios全局請(qǐng)求參數(shù)設(shè)置,請(qǐng)求及返回?cái)r截器的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-03-03
  • vue?ant?design?封裝彈窗表單的使用

    vue?ant?design?封裝彈窗表單的使用

    這篇文章主要介紹了vue?ant?design?封裝彈窗表單的使用,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • 使用Vue動(dòng)態(tài)生成form表單的實(shí)例代碼

    使用Vue動(dòng)態(tài)生成form表單的實(shí)例代碼

    這篇文章主要介紹了使用Vue動(dòng)態(tài)生成form表單的實(shí)例代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2018-04-04
  • Vue3+Element?Plus按需引入(自動(dòng)導(dǎo)入)詳解

    Vue3+Element?Plus按需引入(自動(dòng)導(dǎo)入)詳解

    element-plus根據(jù)官網(wǎng)文檔,推薦用戶采用按需導(dǎo)入的方式進(jìn)行導(dǎo)入,下面這篇文章主要給大家介紹了關(guān)于Vue3+Element?Plus按需引入(自動(dòng)導(dǎo)入)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-10-10
  • vue實(shí)現(xiàn)左右伸縮方式(el-drawer自定義位置展開(kāi)收縮)

    vue實(shí)現(xiàn)左右伸縮方式(el-drawer自定義位置展開(kāi)收縮)

    這篇文章主要介紹了vue實(shí)現(xiàn)左右伸縮方式(el-drawer自定義位置展開(kāi)收縮),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • vue報(bào)錯(cuò)Cannot?read?properties?of?undefined?(...)類型的解決辦法

    vue報(bào)錯(cuò)Cannot?read?properties?of?undefined?(...)類型的解決辦法

    這篇文章主要給大家介紹了關(guān)于vue報(bào)錯(cuò)Cannot?read?properties?of?undefined?(...)類型的解決辦法,文中通過(guò)代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2024-04-04
  • vue項(xiàng)目啟動(dòng)時(shí)無(wú)法識(shí)別es6的擴(kuò)展語(yǔ)法的解決

    vue項(xiàng)目啟動(dòng)時(shí)無(wú)法識(shí)別es6的擴(kuò)展語(yǔ)法的解決

    啟動(dòng)項(xiàng)目時(shí)遇到ES6的拓展運(yùn)算符報(bào)錯(cuò)可以通過(guò)切換到淘寶鏡像,以及在項(xiàng)目根目錄下新增.babelrc和postcss.config.js文件來(lái)解決,這些操作有助于正確配置項(xiàng)目環(huán)境,從而避免報(bào)錯(cuò),并保證項(xiàng)目的順利運(yùn)行,希望這些經(jīng)驗(yàn)?zāi)軌驇椭接龅较嗤瑔?wèn)題的開(kāi)發(fā)者
    2024-10-10
  • Vue Cli項(xiàng)目重構(gòu)為Vite的方法步驟

    Vue Cli項(xiàng)目重構(gòu)為Vite的方法步驟

    本文主要介紹了Vue Cli項(xiàng)目重構(gòu)為Vite的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04

最新評(píng)論