温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

vue中怎么使用hightchats

发布时间:2020-12-10 09:59:34 来源:亿速云 阅读:156 作者:小新 栏目:编程语言

小编给大家分享一下vue中怎么使用hightchats,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

vue中使用hightchats

1、安装highcharts

npm install highcharts --save

2、在main.js中

import Highcharts from 'highcharts/highstock';
import HighchartsMore from 'highcharts/highcharts-more';
import HighchartsDrilldown from 'highcharts/modules/drilldown';
import Highcharts3D from 'highcharts/highcharts-3d';
import Highmaps from 'highcharts/modules/map';

HighchartsMore(Highcharts)
HighchartsDrilldown(Highcharts);
Highcharts3D(Highcharts);
Highmaps(Highcharts);
new Vue({
  el: '#app',
  router,
  axios,
  components: { App },
  template: '<App/>',
  methods:{
 
    moreChart() {
        var options = this.getMoreOptions(this.type);
 
        if (this.chart) {
            this.chart.destroy();
        };
    // 初始化 Highcharts 图表
    this.chart = new Highcharts.Chart('highcharts-more', options);
    }
  }
})

3、创建chart组件

<template>
    <p class="chart">
        <p :id="id" :option="option"></p>
    </p>
</template>

<script>
import HighCharts from 'highcharts'
    export default {
        // 验证类型
        props: {
            id: {
                type: String
            },
            option: {
                type: Object
            }
        },
        mounted() {
            HighCharts.chart(this.id, this.option)
        }
    }
</script>

<style scoped>

</style>

4、其他组件引用图表

<Chart :id="id" :option="option"></Chart>
import Chart from "./Chart";
export default {
  name: "HelloWorld",
  components: {
    Chart
  },
  data() {
    return {
      msg: "Welcome to Your Vue.js App",
      id: "test",
      option: {
        credits: {
          enabled: false
        },
        chart: {
          type: "line"
        },
        title: {
          text: "月平均气温" //表头文字
        },
        subtitle: {
          text: "数据来源: WorldClimate.com" //表头下文字
        },
        xAxis: {
          //x轴显示的内容
          categories: [
            "一月",
            "二月",
            "三月",
            "四月",
            "五月",
            "六月",
            "七月",
            "八月",
            "九月",
            "十月",
            "十一月",
            "十二月"
          ],
          plotbands: [
            {
              //可以显示一个方块,如果需要的话可以更改透明度和颜色
              from: 4.5,
              to: 6.5,
              color: "rgba(68,170,213,0)" //透明度和颜色
            }
          ]
        },

        yAxis: {
          //y轴显示的内容
          title: {
            text: "气温 (°C)"
          }
        },
        plotOptions: {
          line: {
            dataLabels: {
              enabled: false // 开启数据标签
            },
            enableMouseTracking: false // 关闭鼠标跟踪,对应的提示框、点击事件会失效
          }
        },
        series: [
          {
            //两条数据
            name: "东京",
            data: [
              7.0,
              6.9,
              9.5,
              14.5,
              18.4,
              21.5,
              25.2,
              26.5,
              23.3,
              18.3,
              13.9,
              9.6
            ]
          },
          {
            name: "伦敦",
            data: [
              3.9,
              4.2,
              5.7,
              8.5,
              11.9,
              15.2,
              17.0,
              16.6,
              14.2,
              10.3,
              6.6,
              4.8
            ]
          }
        ]
      }
}
}

以上是“vue中怎么使用hightchats”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI