vue3+Highcharts实现柱状图

1.效果图

2.准备工作

npm install --save highcharts

//main.js
// 引入charts
import Highcharts from 'highcharts';
// 使用3d图还需要引入下面的
import Highcharts3d from 'highcharts/highcharts-3d';
// 调用3d图表
Highcharts3d(Highcharts);


//页面还需引入
import Highcharts from 'highcharts';

3.html

父组件

import threeDPie from '@/components/threeDPie.vue' 
import threeDTwoPie from '@/components/threeDTwoPie.vue' 



<div class="pie-chart">
                                <threeDPie></threeDPie>
                                <threeDTwoPie></threeDTwoPie>
</div>

子组件


<template>
    <div>
        <div id="pie"
             style="height:120px;width:120px;"></div>
    </div>
</template>

<script setup>
import Highcharts from 'highcharts';
 import {onMounted,defineProps} from 'vue';
var init = () =>{
    Highcharts.chart('pie', {
        accessibility: {
        enabled: false
    },
    chart: {
        type: 'pie',
        options3d: {
            enabled: true,
            alpha: 50
        },
        margin: [0, 0, 0, 0],
        //将白色背景颜色设置成透明
        backgroundColor: 'rgba(0,0,0,0)'
    },
    plotOptions: {
        pie: {
            innerSize: 60,
            depth: 20, //鼠标厚度
            dataLabels: {
            enabled: false, //是否显示饼图的线形tip
          
            align: "center",
          // position:'center',
        }, 
        }
    },
    // 去掉默认标题
    title: {
          text: ''
        },
        //去掉右下角网址链接,禁用版本信息
     credits: {
          
          enabled: false,
        },

    series: [{
        name: 'Medals',
        data: [
            ['Norway', 16],
            ['Germany', 12],
            ['USA', 8],
            ['Sweden', 8],
            ['Netherlands', 8],
            ['ROC', 6],
            ['Austria', 7],
            ['Canada', 4],
            ['Japan', 3]

        ]
    }]
});

}
onMounted(()=>{
    init();
})
</script>
<style scoped>
</style>

<template>
    <div>
        <div id="pie1"
             style="height:120px;width:120px;"></div>
    </div>
</template>

<script setup>
import Highcharts from 'highcharts';
import {onMounted,defineProps} from 'vue';
var init = () =>{
    Highcharts.chart('pie1', {
        accessibility: {
        enabled: false
    },
    chart: {
        type: 'pie',
        options3d: {
            enabled: true,
            alpha: 50
        },
        margin: [0, 0, 0, 0],
        //将白色背景颜色设置成透明
        backgroundColor: 'rgba(0,0,0,0)'
    },
    plotOptions: {
        pie: {
            innerSize: 60,
            depth: 20, //鼠标厚度
            dataLabels: {
            enabled: false, //是否显示饼图的线形tip
            align: "center",
          // position:'center',
        }, 
        }
    },
    // 去掉默认标题
    title: {
          text: ''
        },
        //去掉右下角网址链接,禁用版本信息
     credits: {
          
          enabled: false,
        },

    series: [{
        name: 'Medals',
        data: [
            ['Norway', 16],
            ['Germany', 12],
            ['USA', 8],
            ['Sweden', 8],
            ['Netherlands', 8],
            ['ROC', 6],
            ['Austria', 7],
            ['Canada', 4],
            ['Japan', 3]

        ]
    }]
});

}
onMounted(()=>{
    init();
})
</script>
<style scoped>
</style>

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值