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('查詢排名信息異常'); }); } } }, 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)曲線數(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)文章
vue2.0頁(yè)面前進(jìn)刷新回退不刷新的實(shí)現(xiàn)方法
這篇文章主要介紹了vue2.0頁(yè)面前進(jìn)刷新回退不刷新的實(shí)現(xiàn)方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-07-07詳解Vue學(xué)習(xí)筆記進(jìn)階篇之列表過(guò)渡及其他
本篇文章主要介紹了詳解Vue學(xué)習(xí)筆記進(jìn)階篇之列表過(guò)渡及其他,具有一定的參考價(jià)值,有興趣的可以了解一下2017-07-07詳解vue-router 2.0 常用基礎(chǔ)知識(shí)點(diǎn)之router.push()
本篇文章主要介紹了vue-router 2.0 常用基礎(chǔ)知識(shí)點(diǎn)之router.push(),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-05-05vue單向以及雙向數(shù)據(jù)綁定方式(v-bind和v-model的使用)
這篇文章主要介紹了vue單向以及雙向數(shù)據(jù)綁定方式(v-bind和v-model的使用),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04IDEA創(chuàng)建Vue項(xiàng)目的兩種方式總結(jié)
這篇文章主要介紹了IDEA創(chuàng)建Vue項(xiàng)目的兩種方式總結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。2023-04-04如何利用vue實(shí)現(xiàn)css過(guò)渡和動(dòng)畫(huà)
過(guò)渡Vue在插入、更新或者移除 DOM 時(shí),提供多種不同方式的應(yīng)用過(guò)渡效果這篇文章主要給大家介紹了關(guān)于如何利用vue實(shí)現(xiàn)css過(guò)渡和動(dòng)畫(huà)的相關(guān)資料,需要的朋友可以參考下2021-11-11vue3+element Plus實(shí)現(xiàn)在table中增加一條表單數(shù)據(jù)的示例代碼
這篇文章主要介紹了vue3+element Plus實(shí)現(xiàn)在table中增加一條表單數(shù)據(jù)的操作,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2024-01-01vue子組件實(shí)時(shí)獲取父組件的數(shù)據(jù)實(shí)現(xiàn)
本文主要介紹了vue子組件實(shí)時(shí)獲取父組件的數(shù)據(jù)實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-12-12