最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

通过在Vue中使用vue2-highcharts实现top功能(详细教程)

来源:动视网 责编:小OO 时间:2020-11-27 19:42:43
文档

通过在Vue中使用vue2-highcharts实现top功能(详细教程)

1、要实现的效果如下图。2、首先项目中引用vue2-highcharts。package.json中如下:在命令行中输入。cnpm install vue2-highcharts。3、页面代码如下:
推荐度:
导读1、要实现的效果如下图。2、首先项目中引用vue2-highcharts。package.json中如下:在命令行中输入。cnpm install vue2-highcharts。3、页面代码如下:
 下面我就为大家分享一篇Vue 中使用vue2-highcharts实现top功能的示例,具有很好的参考价值,希望对大家有所帮助。

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

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

package.json中如下:

在命令行中输入:

cnpm install vue2-highcharts

3、页面代码如下:

<template>
 <p >
 <p>
 <p id="transparent-header" class="rank-head container" >
 <img src="../assets/index/back.png" class="rank-head-back" @click="routerBack"/>
 <span >用能排名</span>
 </p>
 </p>
 <p >
 <p >
 <datepicker v-on:picked="picked" style="margin-left:10px;"></datepicker>
 </p>
 <p >
 </p>
 </p>
 <p >
 <p class="charts">
 <vue-highcharts :options="options" ref="maxLineCharts"></vue-highcharts>
 </p>
 </p>
 <p >
 <p class="charts">
 <vue-highcharts :options="options" ref="minLineCharts"></vue-highcharts>
 </p>
 </p>
 </p>
</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中实现先请求数据再渲染dom分享

解决vue页面DOM操作不生效的问题

nodejs实现超简单生成二维码的方法

文档

通过在Vue中使用vue2-highcharts实现top功能(详细教程)

1、要实现的效果如下图。2、首先项目中引用vue2-highcharts。package.json中如下:在命令行中输入。cnpm install vue2-highcharts。3、页面代码如下:
推荐度:
标签: VUE 教程 top
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top