说明

要求做立体感环形饼图

示例图

QQ截图20190530171959.png

HTML代码

  1. <div id="main" style="width: 50%;height:400px;margin: 0 auto;"></div>

JS代码

  1. <script src="js/jquery-1.6.2.min.js"></script>
  2. <script src="js/echarts.min.js"></script>
  3. <script>
  4. $(function () {
  5. pie("main");
  6. });
  7. /**
  8. * @func
  9. * @desc 立体感饼图函数
  10. * @param {string} id - string |目标id
  11. *
  12. */
  13. function pie(id){
  14. var myChart = echarts.init(document.getElementById(id));
  15. var option = {
  16. backgroundColor:"#041c3e",
  17. tooltip: {
  18. trigger: "item"
  19. },
  20. series: [
  21. {
  22. name: "",
  23. type: "pie",
  24. radius: ["38%","75%"],
  25. z: 0,
  26. zlevel: 0,
  27. label: {normal: {show: true, position: "outside"} },
  28. hoverAnimation:false,
  29. itemStyle:{
  30. emphasis:{
  31. opacity:.7
  32. }
  33. },
  34. data: [
  35. {value: 30, name: "燃气", itemStyle: {normal: {color: "#d93551"} } },
  36. {value: 30, name: "风电", itemStyle: {normal: {color: "#12c4e7"} } },
  37. {value: 30, name: "生物质", itemStyle: {normal: {color: "#f9a90f"} } },
  38. {value: 30, name: "光伏", itemStyle: {normal: {color: "#ccfc15"} } },
  39. {value: 30, name: "水电", itemStyle: {normal: {color: "#0ef40d"} } }
  40. ]
  41. },
  42. {
  43. name: "",
  44. type: "pie",
  45. radius: ["38%","75%"],
  46. silent: true,
  47. z: 0,
  48. zlevel: 0,
  49. label: {normal: {show: false, position: "center"} },
  50. data: [
  51. {value: 1, name: "", itemStyle: {normal: {
  52. color: {
  53. type: 'radial',
  54. x: 0.5,
  55. y: 0.5,
  56. r: 0.7,
  57. colorStops: [
  58. {offset: 0, color: 'transparent'},
  59. {offset: 0.379999, color: 'transparent'},
  60. {offset: 0.38, color: 'rgba(255,255,255,0.1)'},
  61. {offset: 0.55, color: 'rgba(255,255,255,0.5)'},
  62. {offset: 0.699999, color: 'rgba(255,255,255,0.1)'},
  63. {offset: 0.7, color: 'transparent'},
  64. {offset: 1, color: 'transparent'}
  65. ],
  66. globalCoord: false // 缺省为 false
  67. }
  68. } } }
  69. ]
  70. }
  71. ]
  72. }
  73. // 画图
  74. myChart.setOption(option,true);
  75. myChart.resize();
  76. }
  77. </script>

本文为原创文章,转载请附上原文链接!