Vue中用Highcharts制作3D环形图

1.首先在需要用到的页面引入Highcharts

import * as Highcharts from 'highcharts'

2.html中写一个容器并设置大小

 <div id="container" class="container-left"></div>
 .container-left{
                width: 50%;
                height: 100%;
            }

3.js部分


 initCharts() {
      //数据格式
      // let dataSource = this.initData.hyfb[0].total
      let that = this;
      let colorList = ["#89651f", "#c8474a", "#5d8cdc", "#07c563", "#c4cd46"];
      Highcharts.chart("container", {
        colors: that.chartsColors,
        chart: {
          renderTo: "graph",
          defaultSeriesType: "line",
          zoomType: "x",
          margin: [0, 0, 0, 0],
          type: "pie",
          backgroundColor: null,
          color: "#fff",
          options3d: {
            enabled: true,
            alpha: 50,
            // alpha: this.getFontSize(30),
          },
        },
        title: {
          text: '人数',
          align: "center",
          floating: true,
        },
        //图例
        legend: {
          show: true,
          align: "center",
          verticalAlign: "top",
          // y:40,
          padding: 5,
          itemMarginTop: 40,
          itemDistance: 40,
          itemStyle: {
            color: "#fff",
          },
          // labelFormatter: function() {
          //   return `${this.name}\xa0\xa0\xa0${this.y}台`;
          // }
        },
        tooltip: {
          enabled: true,
          // shared: true, //是否共享提示,也就是X一样的所有点都显示出来
          useHTML: true, //是否使用HTML编辑提示信息
          // headerFormat: '<small>{point.key}</small><table>',
          backgroundColor: " rgb(2, 82, 114,0.5)",
          borderWidth: 0,
          // 是否显示提示的下降阴影
          shadow: false,
          borderRadius: that.getFontSize(20),
          style: {
            // 文字内容相关样式
            color: "white",
            textAlign: "center",
          },
          formatter: function (series) {
            // console.log(this.y);
            // console.log(series);
            // this.num=this.y
            // console.log(this.num);
            let res = `<div style="text-align:center;padding:3px;font-size:${that.getFontSize(
              28
            )}px;">
            <div style="margin-top:5px;">
              <span style="border-bottom:1px solid #ffffff;font-family: 'pfm';">${
              this.key
            }</span>
            <span style="font-family: 'pfm';">:&nbsp; ${this.y.toFixed(1)}%</span>
              </div>
            </div>`;
            return res;
          },
        },
        subtitle: {
          text: "",
        },
        credits: {
          enabled: false,
        },
        plotOptions: {
          pie: {
            allowPointSelect: true,
            cursor: "pointer",
            innerSize: this.getFontSize(260),
            size: this.getFontSize(340),
            depth: this.getFontSize(80),
            // showInLegend: true,
          },
        },
        series: [
          {
            type: "pie",
            name: "货物金额",
            label: {
              show: false,
            },
            dataLabels: {
              enabled: true,
              connectorWidth: 0,
              distance: this.getFontSize(-8),
              padding: this.getFontSize(24),
              formatter: function () {
                // console.log(this.point.y);
                if (this.point.y) {
                  // console.log(5555);
                  return `<span style="color:#fff;font-size:${that.getFontSize(
                    34
                  )};font-weight:100;font-family:'DINA';">${
                    this.point.y
                  }%</span>`;
                }
              },
              style: {
                textOutline: "none",
                fontFamily: "DINA",
              },
            },
            data: [
                  ['香蕉', 8],
                  ['猕猴桃', 3],
                  ['桃子', 1],
                  ['橘子', 6],
                  ['苹果', 8],
                  ['梨', 4],
                  ['柑橘', 4],
                  ['橙子', 1],
                  ['葡萄 (串)', 1]
                ],
            selected:false,
            events:{
              click:function(e){
                that.pieClick(e.point.options,e.point)
              } ,
              // select:function(e){
              //   console.log('选择',e);
              // }
            }
          },
        ],
      });
    },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue 3 中实现轮播可以使用第三方库或编写自定义组件。以下是一个简单的示例,演示如何使用 Vue 3 和 Vue Slick Carousel 库来实现轮播: 1. 首先,确保已经安装了 Vue 3 和 Vue Slick Carousel。可以使用 npm 或 yarn 进行安装: ``` npm install vue@next npm install vue-slick-carousel ``` 2. 在你的 Vue 组件中,导入 VueVue Slick Carousel: ```javascript import { createApp } from 'vue'; import VueSlickCarousel from 'vue-slick-carousel'; import 'vue-slick-carousel/dist/vue-slick-carousel.css'; import 'vue-slick-carousel/dist/vue-slick-carousel-theme.css'; ``` 3. 在组件的 template 中,使用 Vue Slick Carousel 的轮播组件: ```html <template> <vue-slick-carousel :options="carouselOptions"> <div v-for="item in items" :key="item.id"> <img :src="item.imageUrl" alt="Slide"> </div> </vue-slick-carousel> </template> ``` 4. 在组件的 script 部分,定义轮播的选项和数据: ```javascript export default { data() { return { carouselOptions: { // 可以根据需要配置轮播的选项,例如自动播放、滑动速度等 autoplay: true, speed: 500, // 更多选项可以参考 Vue Slick Carousel 文档 }, items: [ { id: 1, imageUrl: 'path/to/image1.jpg' }, { id: 2, imageUrl: 'path/to/image2.jpg' }, { id: 3, imageUrl: 'path/to/image3.jpg' }, // 添加更多轮播项 ], }; }, }; ``` 这样就可以在 Vue 3 中实现一个简单的轮播了。根据实际需求,你可以自定义轮播的样式和配置选项。请注意,这只是一个简单的示例,实际使用时可能需要根据具体情况进行调整。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值