Vue 中使用vue2-highcharts實(shí)現(xiàn)top功能的示例
1、要實(shí)現(xiàn)的效果如下圖:

2、首先項(xiàng)目中引用vue2-highcharts
package.json中如下:

在命令行中輸入:
cnpm install vue2-highcharts
3、頁(yè)面代碼如下:
<template>
<div >
<div>
<div id="transparent-header" class="rank-head container" >
<img src="../assets/index/back.png" class="rank-head-back" @click="routerBack"/>
<span >用能排名</span>
</div>
</div>
<div >
<div >
<datepicker v-on:picked="picked" style="margin-left:10px;"></datepicker>
</div>
<div >
</div>
</div>
<div >
<div class="charts">
<vue-highcharts :options="options" ref="maxLineCharts"></vue-highcharts>
</div>
</div>
<div >
<div class="charts">
<vue-highcharts :options="options" ref="minLineCharts"></vue-highcharts>
</div>
</div>
</div>
</template>
<script>
import datepicker from '../components/datepicker.vue'
import VueHighcharts from 'vue2-highcharts'
export default {
data() {
return{
topHeight:240,
freezeMon:'',
ownerFreeData: [],
options:{
credits: {
enabled: false
},
legend: {
enabled: false
},
global: {
useUTC: false
},
chart: {
type: 'bar'
},
title: {
text: ' '
},
subtitle: {
text: ''
},
xAxis:[{
categories: ['1', '2', '3', '4', '5','6', '7', '8', '9', '10'],
title: {
text: null
},
labels: {
rotation: -45
}
}],
yAxis:[{
min: 0,
labels:{
overflow: 'justify'
},
title: {
text: '單位 (kwh)',
align: 'high'
}
}],
tooltip: {
formatter: function(){
return this.x+':'+this.y+'kwh';
}
},
credits: {
enabled: false
},
plotOptions: {
bar: {
dataLabels: {
enabled: true
}
},
series: [{
type: 'bar'
}]
}
}
}
},
methods: {
picked(year, month, date) {
if(month < 10){
this.freezeMon = `${year}-0${month}`;
}else{
this.freezeMon = `${year}-${month}`;
}
this.getList();
},
routerBack(){
this.$router.go(-1);
},
getList(){
let maxLineCharts = this.$refs.maxLineCharts;
let minLineCharts = this.$refs.minLineCharts;
if(maxLineCharts != null && minLineCharts != null){
//移除所有Series
maxLineCharts.removeSeries();
minLineCharts.removeSeries();
//設(shè)置標(biāo)題名
maxLineCharts.getChart().title.update({ text: '用能最大TOP10' });
minLineCharts.getChart().title.update({ text: '用能最小TOP10' });
var userType = sessionStorage.getItem('userType');
var areaCode = sessionStorage.getItem('areaCode');
this.$http.post(this.URLINFO + '/mobile/rankingMonitor/getDayFreezeApp.do',{yearMonth:this.freezeMon,userType:userType,areaCode:areaCode})
.then(function (res) {
var seriesData = []
var categoriesData = []
for(var i = 0;i < res.data.max.length; i++) {
//maxLineCharts.addSeries({name:res.data.max[i][1],data: [{name: res.data.max[i][1],y:res.data.max[i][2]}]});
seriesData.push([res.data.max[i][1],res.data.max[i][2]]);
categoriesData.push(res.data.max[i][1]);
}
maxLineCharts.addSeries({name: '用能',data: seriesData});
maxLineCharts.getChart().xAxis[0].setCategories(categoriesData);
seriesData = []
categoriesData = []
for(var i = 0;i < res.data.min.length; i++) {
//minLineCharts.addSeries({name:res.data.min[i][1],data: [{name: res.data.min[i][1],y:res.data.min[i][2]}]});
seriesData.push([res.data.min[i][1],res.data.min[i][2]]);
categoriesData.push(res.data.min[i][1]);
}
minLineCharts.addSeries({name: '用能',data: seriesData});
minLineCharts.getChart().xAxis[0].setCategories(categoriesData);
})
.catch(function (error) {
this.$toast('查詢(xún)排名信息異常');
});
}
}
},
components: {
datepicker,
VueHighcharts
},
mounted () {
this.getList()
}
}
</script>
<style>
*{margin:0;padding:0; list-style:none }
h1,h2,h3,h4,h5,h6{font-size:16px; font-weight:normal;}
.rank-head{
width: 100%;
height: 40px;
position:fixed;
background: -webkit-linear-gradient(top,rgba(0,0,0,.6),rgba(0,0,0,0));
z-index: 999;
color: #fff;
font-size: 16px;
text-align: center;
line-height: 40px;
}
.container{
width: 100%;
overflow: hidden
}
.rank-head-back{
display: block;
float: left;
width: 40px;
height: 40px;
background: url("../assets/index/back.png") no-repeat center center;
background-size: 100% 100%;
}
</style>
以上這篇Vue 中使用vue2-highcharts實(shí)現(xiàn)top功能的示例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- 在vue項(xiàng)目中引入highcharts圖表的方法(詳解)
- Vue 中使用vue2-highcharts實(shí)現(xiàn)曲線(xiàn)數(shù)據(jù)展示的方法
- 在Vue中使用highCharts繪制3d餅圖的方法
- vue中過(guò)濾器filter的講解
- vue計(jì)算屬性computed、事件、監(jiān)聽(tīng)器watch的使用講解
- vue-router傳參用法詳解
- vue-router實(shí)現(xiàn)嵌套路由的講解
- vue-router實(shí)現(xiàn)編程式導(dǎo)航的代碼實(shí)例
- vue-router命名路由和編程式路由傳參講解
- 在vue項(xiàng)目中引入highcharts圖表的方法
相關(guān)文章
Vue監(jiān)聽(tīng)localstorage變化的方法詳解
在日常開(kāi)發(fā)中,我們經(jīng)常使用localStorage來(lái)存儲(chǔ)一些變量,這些變量會(huì)存儲(chǔ)在瀏覽中,對(duì)于localStorage來(lái)說(shuō),即使關(guān)閉瀏覽器,這些變量依然存儲(chǔ)著,方便我們開(kāi)發(fā)的時(shí)候在別的地方使用,本文就給大家介紹Vue如何監(jiān)聽(tīng)localstorage的變化,需要的朋友可以參考下2023-10-10
詳解從react轉(zhuǎn)職到vue開(kāi)發(fā)的項(xiàng)目準(zhǔn)備
這篇文章主要介紹了詳解從react轉(zhuǎn)職到vue開(kāi)發(fā)的項(xiàng)目準(zhǔn)備,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-01-01
vue下載excel的實(shí)現(xiàn)代碼后臺(tái)用post方法
這篇文章主要介紹了vue下載excel的實(shí)現(xiàn)代碼,后臺(tái)用post方法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下2019-05-05
vue打包部署到tomcat上頁(yè)面空白資源加載不出來(lái)的解決
這篇文章主要介紹了vue打包部署到tomcat上頁(yè)面空白資源加載不出來(lái)的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03
vue3中實(shí)現(xiàn)文本顯示省略號(hào)和tooltips提示框的方式詳解
在?B?端業(yè)務(wù)中,我們經(jīng)常會(huì)遇到文本內(nèi)容超出容器區(qū)域需顯示省略號(hào)的需求,當(dāng)鼠標(biāo)移入文本時(shí),會(huì)出現(xiàn)?Tooltip?顯示完整內(nèi)容,最近,我也遇到了這樣的場(chǎng)景,接下來(lái)給大家介紹vue3中實(shí)現(xiàn)文本顯示省略號(hào)和tooltips提示框的方式,需要的朋友可以參考下2024-04-04
詳解Vue中的render:?h?=>?h(App)示例代碼
這篇文章主要介紹了Vue中的render:?h?=>?h(App),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-09-09

