Vue 中使用vue2-highcharts实现top功能的示例

 更新时间:2018年03月05日 09:45:01   作者:蔚蓝色天空sky  
下面小编就为大家分享一篇Vue 中使用vue2-highcharts实现top功能的示例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

1、要实现的效果如下图:

2、首先项目中引用vue2-highcharts

package.json中如下:

在命令行中输入:

cnpm 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 '../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();
//设置标题名 
   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实现top功能的示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • Vue监听localstorage变化的方法详解

    Vue监听localstorage变化的方法详解

    在日常开发中,我们经常使用localStorage来存储一些变量,这些变量会存储在浏览中,对于localStorage来说,即使关闭浏览器,这些变量依然存储着,方便我们开发的时候在别的地方使用,本文就给大家介绍Vue如何监听localstorage的变化,需要的朋友可以参考下
    2023-10-10
  • 详解从react转职到vue开发的项目准备

    详解从react转职到vue开发的项目准备

    这篇文章主要介绍了详解从react转职到vue开发的项目准备,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2019-01-01
  • vue下载excel的实现代码后台用post方法

    vue下载excel的实现代码后台用post方法

    这篇文章主要介绍了vue下载excel的实现代码,后台用post方法,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值 ,需要的朋友可以参考下
    2019-05-05
  • vue3下eslint配置方式

    vue3下eslint配置方式

    这篇文章主要介绍了vue3下eslint配置方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-01-01
  • vue打包部署到tomcat上页面空白资源加载不出来的解决

    vue打包部署到tomcat上页面空白资源加载不出来的解决

    这篇文章主要介绍了vue打包部署到tomcat上页面空白资源加载不出来的解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-03-03
  • 深入理解Vue3响应式原理

    深入理解Vue3响应式原理

    响应式就是当对象本身(对象的增删值)或者对象属性(重新赋值)发生变化时,将会运行一些函数,最常见的就是render函数,下面这篇文章主要给大家介绍了关于Vue3响应式原理的相关资料,需要的朋友可以参考下
    2022-12-12
  • vue init失败简单解决方法(终极版)

    vue init失败简单解决方法(终极版)

    这篇文章主要介绍了vue init失败的简单解决方法-终极版,需要的朋友可以参考下
    2017-12-12
  • vue3中实现文本显示省略号和tooltips提示框的方式详解

    vue3中实现文本显示省略号和tooltips提示框的方式详解

    在 B 端业务中,我们经常会遇到文本内容超出容器区域需显示省略号的需求,当鼠标移入文本时,会出现 Tooltip 显示完整内容,最近,我也遇到了这样的场景,接下来给大家介绍vue3中实现文本显示省略号和tooltips提示框的方式,需要的朋友可以参考下
    2024-04-04
  • 详解Vue中的render: h => h(App)示例代码

    详解Vue中的render: h => h(App)示例代码

    这篇文章主要介绍了Vue中的render: h => h(App),本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2023-09-09
  • vue中组件通信的八种方式(值得收藏!)

    vue中组件通信的八种方式(值得收藏!)

    这篇文章主要给大家总结介绍了关于vue中八种组件通信方式的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用vue具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-08-08

最新评论