Vue 中使用vue2-highcharts实现top功能的示例
网络编程 2021-07-04 17:33www.168986.cn编程入门
狼蚁网站SEO优化长沙网络推广就为大家分享一篇Vue 中使用vue2-highcharts实现功能的示例,具有很好的参考价值,希望对大家有所帮助。一起跟随长沙网络推广过来看看吧
1、要实现的效果如下图:
2、首先项目中引用vue2-highcharts
package.json中如下:
在命令行中输入:
pm install vue2-highcharts
3、页面代码如下:
<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 '../ponents/datepicker.vue' import VueHighcharts from 'vue2-highcharts' export default { data() { return{ Height: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(); //设置标题名 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('查询排名信息异常'); }); } } }, ponents: { 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(,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实现功能的示例就是长沙网络推广分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持狼蚁SEO。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程