highcharts(3d饼图)

前言

最近要把饼图改成3d的,原来的echart图做不了,这里推荐一下highcharts

链接:传送门

使用

文档

配置项文档

安装

npm install --save highcharts

使用

main.js里注册

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

实例

<template>
    <div class="pie" id="3dpie" :options="chartOptions">
    </div>
</template>

<script>
import highChart from 'highcharts';
export default {
    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]
                    ]
                }]
            }
        };
    },
    mounted() {
        highChart.chart('3dpie',this.chartOptions);
    },
    methods: {

    }
};
</script>

<style scoped lang="scss">
.pie{
    width: 100%;
    height: 90%;
    background: #09184F;
}
</style>

效果图:
在这里插入图片描述
如果需要从后台获取数据可以这样

<template>
    <div class="pie" id="3dpie" :options="chartOptions">
    </div>
</template>

<script>
import highChart from 'highcharts';
export default {
    data() {
        return {
            chartOptions: {
                chart: {
                    type: 'pie',
                    options3d: {
                        enabled: true,
                        alpha: 45,
                        beta: 0
                    }
                },
                title: '',
                plotOptions: {
                    pie: {
                        allowPointSelect: true,
                        cursor: 'pointer',
                        depth: 35,
                        dataLabels: {
                            enabled: true,
                            format: '{point.name}'
                        }
                    }
                },
                series: [{
                    type: 'pie',
                    data: []
                }]
            }
        };
    },
    mounted() {
        this.init();
    },
    methods: {
        // 初始化饼图
        init() {
            this.$http.post(url,params)
                .then(({data: d}) => {
                    if(d.code == 0) {
                        let res = d.data || [];
                        this.chartOptions.series[0].data = res.map(e => {
                            return [e.inspectionItemName,e.totalNum];
                        });
                        highChart.chart('3dpie',this.chartOptions);
                    }
                });
            window.addEventListener('resize', function() {
                highChart.resize();
            });
        }
    }
};
</script>

<style scoped lang="scss">
.pie{
    width: 100%;
    height: 90%;
    background: #09184F;
}
</style>

其他内容

修改背景色

chart:{
  backgroundColor: '#09184F'
}

tooltip格式化

tooltip: {
     formatter() {
         console.log(this);
         return `
          <div>
          类型: ${this.key}
          <br />
          值:${this.percentage}
          </div>
         `;
     }
 },

当鼠标移入后,会打印出this,看看自己需要什么值,其他属性自行查看文档

去掉右下角的链接

credits: {
     enabled: false
 },

修改label样式

pie: {
     allowPointSelect: true,
     cursor: 'pointer',
     depth: 35,
     dataLabels: {
         enabled: true,
         formatter() {
             console.log(this.point);
             return this.point.name;
         }
     }
 }

在这里插入图片描述
修改颜色
chartOptions对象里有一个colors属性,该属性是个数组,用于自定义颜色

  colors: ['#3E6FF6','#2BFFDF','#1B2B53','#FFB139','#434348','#7CB5EC','#F7A35C'],

观看饼图的角度

chart: {
    type: 'pie',
    options3d: {
        enabled: true,
        //设置观看的角度
        alpha: 65,
        beta: 0
    }
},

在这里插入图片描述
饼图的厚度

plotOptions: {
     pie: {
         allowPointSelect: true,
         cursor: 'pointer',
         //设置饼图厚度
         depth: 65,
         dataLabels: {
             enabled: true,
             format: '{point.name}'
         }
     }
 },

在这里插入图片描述
饼图大小

plotOptions: {
     pie: {
         allowPointSelect: true,
         cursor: 'pointer',
         depth: 65,
         dataLabels: {
             enabled: true,
             format: '{point.name}'
         },
         //饼图大小
         size: 300
     }
 },

在这里插入图片描述

显示图例

plotOptions: {
     pie: {
         allowPointSelect: true,
         cursor: 'pointer',
         depth: 65,
         dataLabels: {
             enabled: true,
             format: '{point.name}'
         },
         size: 300,
         //显示图例
         showInLegend: true
     }
 },

图例的其他配置看legend选项
在这里插入图片描述

  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
要配置highcharts 3D饼图,首先需要引入必要的模块和库: - 首先,使用引用中提到的highcharts3d(highcharts)来调用3D图表。 - 其次,需要引入highcharts3d模块,可以使用引用中提到的import highcharts3d from 'highcharts/highcharts-3d'。 - 接下来,在项目的main.js文件中进行配置,引入highcharts库,可以使用引用中提到的import highcharts from 'highcharts'。 一旦完成了这些步骤,就可以开始配置highcharts 3D饼图。高图3D饼图的配置项包括以下几个重要参数: - chart类型设置为'pie'。 - series数组中的data属性设置为要显示的数据。 - plotOptions中的pie对象设置3D相关属性,如depth、innerSize等。 - title对象设置饼图的标题。 以下是一个示例配置项的代码: ``` Highcharts.chart('container', { chart: { type: 'pie', options3d: { enabled: true, alpha: 45, beta: 0 } }, title: { text: '3D Pie Chart' }, plotOptions: { pie: { allowPointSelect: true, innerSize: 100, depth: 45 } }, series: [{ name: 'Data', data: [ ['Category 1', 30], ['Category 2', 20], ['Category 3', 15], ['Category 4', 10] ] }] }); ``` 以上配置项可以在HTML页面中使用highcharts库和相应的容器元素(如div)来呈现一个高图3D饼图。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [highcharts 3D饼图](https://blog.csdn.net/weixin_42246997/article/details/121510397)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

无知的小菜鸡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值