vue highcharts使用

1、安装 highcharts

npm install highcharts --save

2、安装highcharts-vue

npm install highcharts-vue

3、在main中引入

import HighchartsVue from 'highcharts-vue'
Vue.use(HighchartsVue)

4、使用

html代码

<highcharts :options="chartOptions"></highcharts>

data中的数据

  data() {
    return {
      chartOptions: {
        series: [
          {
            data: [1, 2, 3], // sample data
          },
        ],	
      },
    };
  },

效果图
在这里插入图片描述

5、3d图形的使用

main.js中加入

import highcharts from 'highcharts'

import highcharts3d from 'highcharts/highcharts-3d'

highcharts3d(highcharts)

6方法任一都可

6.1 3d图形的实现(一)通过highcharts标签实现

将配置项的内容改为3d配置项的内容

<template>
  <div>
    <highcharts :options="chartOptions"></highcharts>
  </div>
</template>

<script>
export default {
  name: "",
  // 接收父组件传递过来的参数
  props: {},
  // 注册组件
  components: {},
  // 定义变量
  data() {
    return {
      chartOptions: {
        chart: {
          type: "pie",
          options3d: {
            enabled: true,
            alpha: 45,
            beta: 0,
          },
        },
        title: {
          text: "2014年某网站不同浏览器访问量占比",
        },
        tooltip: {
          pointFormat: "{series.name}: <b>{point.percentage:.1f}%</b>",
        },
        plotOptions: {
          pie: {
            allowPointSelect: true,
            cursor: "pointer",
            depth: 35,
            dataLabels: {
              enabled: true,
              format: "{point.name}",
            },
          },
        },
        series: [
          {
            type: "pie",
            name: "浏览器占比",
            data: [
              ["Firefox", 45.0],
              ["IE", 26.8],
              {
                name: "Chrome",
                y: 12.8,
                sliced: true,
                selected: true,
              },
              ["Safari", 8.5],
              ["Opera", 6.2],
              ["Others", 0.7],
            ],
          },
        ],
      },
    };
  },
  // 事件方法执行
  methods: {},
  // 页面初始化方法
  mounted() {},
  // 监听值变化
  watch: {},
  // 计算
  computed: {},
};
</script>

<style scoped lang='scss'>
</style>

效果图
在这里插入图片描述

6.2 3d图形的实现(二)通过HighCharts方法实现 (建议)

在需要的地方引入前5步的基础上

import HighCharts from 'highcharts'

全部代码


<template>
  <div>
    <div :id="id" :option="option"></div>
  </div>
</template>

<script>
import HighCharts from "highcharts";
export default {
  name: "",
  // 接收父组件传递过来的参数
  props: {},
  // 注册组件
  components: {},
  // 定义变量
  data() {
    return {
      id: "test",
      option: {
        chart: {
          type: "pie", //饼图
          options3d: {
            enabled: true, //使用3d功能
            alpha: 60, //延y轴向内的倾斜角度
            beta: 0,
          },
        },
        title: {
          text: "测试用", //图表的标题文字
        },
        subtitle: {
          text: "", //副标题文字
        },

        plotOptions: {
          pie: {
            allowPointSelect: true, //每个扇块能否选中
            cursor: "pointer", //鼠标指针
            depth: 35, //饼图的厚度
            dataLabels: {
              enabled: true, //是否显示饼图的线形tip
            },
          },
        },
        series: [
          {
            type: "pie",
            name: "测试用1", //统一的前置词,非必须
            data: [
              ["测试1", 12], //模块名和所占比,也可以{name: '测试1',y: 12}
              ["测试2", 23],
              ["测试3", 19],
              ["测试4", 29],
            ],
          },
        ],
      },
    };
  },
  // 事件方法执行
  methods: {},
  // 页面初始化方法
  mounted() {
    HighCharts.chart(this.id, this.option)
  },
  // 监听值变化
  watch: {},
  // 计算
  computed: {},
};
</script>

<style scoped lang='scss'>
</style>



效果图
在这里插入图片描述

去掉默认title

          title: {
            text: null
          },

去掉版权

和title同级

   credits: { enabled: false},
  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!要在Vue使用Highcharts的3D饼图,您需要按照以下步骤进行操作: 1. 首先,您需要安装HighchartsHighcharts-Vue插件。使用以下命令进行安装: ```bash npm install highcharts --save npm install highcharts-vue --save ``` 2. 在您的Vue组件中引入HighchartsHighcharts-Vue插件,并注册Highcharts模块。您可以在需要使用3D饼图的组件中进行这些操作。请注意,需要引入3D模块。 ```javascript import HighchartsVue from 'highcharts-vue'; import Highcharts from 'highcharts'; import highcharts3d from 'highcharts/highcharts-3d'; // 注册Highcharts模块 HighchartsVue(Highcharts); // 启用3D模块 highcharts3d(Highcharts); ``` 3. 在组件的模板中使用`<highcharts>`标签,并通过`options`属性传递配置项来绘制3D饼图。以下是一个示例: ```html <template> <div> <highcharts :options="chartOptions"></highcharts> </div> </template> <script> export default { data() { return { chartOptions: { chart: { type: 'pie', options3d: { enabled: true, alpha: 45, beta: 0, }, }, title: { text: '3D Pie Chart', }, series: [ { name: 'Brands', colorByPoint: true, data: [ { name: 'Chrome', y: 61.41, }, { name: 'Internet Explorer', y: 11.84, }, { name: 'Firefox', y: 10.85, }, { name: 'Edge', y: 4.67, }, { name: 'Safari', y: 4.18, }, { name: 'Other', y: 7.05, }, ], }, ], }, }; }, }; </script> ``` 请注意,以上示例仅供参考,您可以根据自己的需求进行相应的配置和样式调整。 希望能帮助到您!如有任何疑问,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值