web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. seo教程
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站

vue+百度echarts做一个饼图

354 ℃
     

vue+百度echarts做一个饼图

在vue项目开发中如何利用百度echarts做一个饼图数据分析图,下面web建站小编给大家简单介绍一下具体实现代码,如右图!

1、在需要的页面引入

import * as echarts from 'echarts'

//如果没有安装,根据提示安装echarts

2、实现代码如下:

drawPie() {
  var myindex = 0
  var colorArr = [
    {
      c1: '#3266f6',
      c2: '#661dcf'
    },
    {
      c1: '#ec489e',
      c2: '#fdae40'
    },
    {
      c1: '#4b96e0',
      c2: '#4fdac5'
    },
    {
      c1: '#4fabda',
      c2: '#1395d8'
    }
  ]
  let myPieChart = echarts.init(document.getElementById('pies'))
  myPieChart.setOption({
    title: {
      text: ''
    },
    tooltip: {
      trigger: 'item',
      formatter: '{b}: {c}个 ({d}%)'
    },
    legend: {
      top: '10%',
      itemGap: 10 //图例之间间距
    },
    series: {
      name: '近三十天访问统计',
      type: 'pie',
      silent: true,
      radius: ['0', '75%'],
      center: ['50%', '55%'],
      avoidLabelOverlap: false,
      minAngle: 15, //最小角度
      zlevel: 1,
      itemStyle: {
        normal: {
          color: function(params) {
            let colorList = colorArr
            return new echarts.graphic.LinearGradient(1, 0, 0, 0, [
              {
                //颜色渐变函数 前四个参数分别表示四个位置依次为左、下、右、上
                offset: 0,
                color: colorList[params.dataIndex].c1
              },
              {
                offset: 1,
                color: colorList[params.dataIndex].c2
              }
             ])
           }
          }
        },
        label: {
          normal: {
            show: true,
            position: 'inner',
            formatter: '{b}:{d}%\n{c}',
            lineHeight: 15,
            color: '#fff'
          }
        },
        labelLine: {
          normal: {
            show: false
          }
        },
        data: [
          { name: '学习', value: 300 },
          { name: '资料', value: 500 },
          { name: '下载', value: 200 }
        ]
      }
   })
},

百度echarts雷达图radar根据分数点显示每个不同颜色

百度ECharts文档官网介绍

百度echarts柱状图设置不同颜色(每根柱子一种颜色)

百度echarts图表数据为空如何展示"暂无数据"

百度echarts柱状图/折线图x轴显示全部文本(太长自动换行)

标签: 百度echarts, 饼图

上面是“vue+百度echarts做一个饼图”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_3692.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > js
本文共计1072个字,预计阅读时长8分钟
生活小工具,收录了80多款小工具
上一篇: 推荐一款免费可商用仿宋字体——汉字之美仿宋GBK
下一篇: 推荐一款免费可商用英文字体——Atkinson Hyperlegible
x 打工人ai神器