饼图的数据是由 name 和 value 组成的字典所形成的数组 饼图无须配置 xAxis 和 yAxis 饼图可以很好地帮助用户快速了解不同分类的数据的占比情况

基本使用

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <script src="../js/echarts.js"></script>
  9. </head>
  10. <body>
  11. <div style="width: 600px;height:400px"></div>
  12. <script> var mCharts = echarts.init(document.querySelector("div"))
  13. // 准备数据
  14. var pieData = [{ value: 11231, name: "淘宝", }, { value: 22673, name: "京东" }, { value: 6123, name: "唯品会" }, { value: 8989, name: "1号店" }, { value: 6700, name: "聚美优品" }]
  15. // 准备配置项 在 series 下设置 type:pie
  16. var option = { series: [ { type: 'pie', data: pieData } ] }
  17. mCharts.setOption(option)
  18. </script>
  19. </body>
  20. </html>

image.png

饼图的常见效果

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <script src="../js/echarts.js"></script>
  9. </head>
  10. <body>
  11. <div style="width: 600px;height:400px"></div>
  12. <script> var mCharts = echarts.init(document.querySelector("div"))
  13. // 准备数据
  14. var pieData = [{ value: 11231, name: "淘宝", }, { value: 22673, name: "京东" }, { value: 6123, name: "唯品会" }, { value: 8989, name: "1号店" }, { value: 6700, name: "聚美优品" }]
  15. // 准备配置项 在 series 下设置 type:pie
  16. var option = {
  17. series: [{
  18. type: 'pie', data: pieData,
  19. label: {
  20. // label.show : 显示文字
  21. // label.formatter : 格式化文字
  22. show: true,
  23. formatter: function (arg) { return arg.data.name + '平台' + arg.data.value + '元\n' + arg.percent + '%' }
  24. }
  25. }]
  26. }
  27. mCharts.setOption(option)
  28. </script>
  29. </body>
  30. </html>

image.png

南丁格尔图

南丁格尔图指的是每一个扇形的半径随着数据的大小而不同, 数值占比越大, 扇形的半径也就越大

  1. var option = {
  2. series: [{
  3. type: 'pie', data: pieData,
  4. label: {
  5. // label.show : 显示文字
  6. // label.formatter : 格式化文字
  7. show: true,
  8. formatter: (arg)=> { return arg.data.name + '平台' + arg.data.value + '元\n' + arg.percent + '%'
  9. }
  10. }
  11. , roseType: 'radius'
  12. }]
  13. }

image.png

选中效果

selectedMode: ‘multiple’ 选中模式,表示是否支持多个选中,默认关闭,支持布尔值和字符串,字符串取值可 选 ‘single’ , ‘multiple’ ,分别表示单选还是多选 selectedOffset: 30 选中扇区的偏移距离

image.png

圆环效果

饼图的半径。可以为如下类型:number :直接指定外半径值。 string :例如, ‘20%’ ,表示外半径为可视区尺寸(容器高宽中 较小一项)的 20% 长度。 Array. :数组的第一项是内半径,第二项是外半径, 通过 Array , 可以 将饼图设置为圆环图

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <script src="../js/echarts.js"></script>
  9. </head>
  10. <body>
  11. <div style="width: 600px;height:400px"></div>
  12. <script> var mCharts = echarts.init(document.querySelector("div"))
  13. // 准备数据
  14. var pieData = [{ value: 11231, name: "淘宝", }, { value: 22673, name: "京东" }, { value: 6123, name: "唯品会" }, { value: 8989, name: "1号店" }, { value: 6700, name: "聚美优品" }]
  15. // 准备配置项 在 series 下设置 type:pie
  16. var option = { series: [ { type: 'pie', data: pieData,
  17. //设置圆环
  18. radius: ['50%', '70%'],
  19. selectedMode: 'multiple',
  20. //选中后的偏移量
  21. selectedOffset: 30 } ] }
  22. mCharts.setOption(option)
  23. </script>
  24. </body>
  25. </html>

image.png