echarts环形饼图

图表效果如下:

具体代码如下:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>关系图案例 </title>
  6. <!-- 引入 ECharts 文件 -->
  7. <script src="js/echarts4.0.js" type="text/javascript" charset="utf-8"> </script>
  8. </head>
  9. <body>
  10. <!-- 为 ECharts 准备一个具备大小(宽高)的 容器 -->
  11. <div id="chart1" style="width: 80%;height: 400px;top: 50px;left: 10%;border: 3px solid #000;"> </div>
  12. </body>
  13. </html>
  14. <script type="text/javascript">
  15. // 基于准备好的容器(这里的容器是id为chart1的div),初始化echarts实例
  16. var chart1 = echarts.init( document.getElementById( "chart1"));
  17. // 指定图表的配置项和数据
  18. var option = {
  19. title: {
  20. text: '男女所占比例',
  21. left : '3%', // 标题距离左侧边距
  22. top : '3%', // 标题距顶部边距
  23. textStyle: {
  24. color: '#000'
  25. }
  26. },
  27. series: [{
  28. type: "pie", // 系列1类型: 饼图
  29. center: [ "25%", "50%"], // 饼图的中心(圆心)坐标,数组的第一项是横坐标,第二项是纵坐标。[ default: ['50%', '50%'] ]
  30. radius: [ "49%", "50%"], // 饼图的半径,数组的第一项是内半径,第二项是外半径。[ default: [0, '75%'] ]
  31. // 可以将内半径设大显示成圆环图(Donut chart)。
  32. clockWise: false, // 饼图的扇区是否是顺时针排布。[ default: true ]
  33. startAngle: 90, // 起始角度,支持范围[0, 360]。 [ default: 90 ]
  34. hoverAnimation: true, // 是否开启 hover 在扇区上的放大动画效果。[ default: true ]
  35. itemStyle: { // 图形样式
  36. normal: {
  37. color: "#5886f0", // 图形的颜色
  38. borderColor: "#5886f0", // 图形的描边颜色
  39. borderWidth: 20, // 描边线宽。为 0 时无描边。[ default: 0 ]
  40. borderType: 'solid', // 柱条的描边类型,默认为实线,支持 'solid', 'dashed', 'dotted'。
  41. label: { // 图形内部标签
  42. show: true, // 是否显示标签
  43. textStyle: { // 标签文本样式
  44. fontSize: 15,
  45. fontWeight: "bold" // 标签字体加粗,'normal','bold','bolder','lighter',100 | 200 | 300 | 400...
  46. },
  47. position: "center" // 标签的位置,'outside'(饼图扇区外侧,通过视觉引导线连到相应的扇区)
  48. // 'inside'(饼图扇区内部); 'inner' 同 'inside'。
  49. // 'center'(在饼图中心位置。)
  50. },
  51. labelLine: { // 标签的视觉引导线样式,在 label 位置 设置为'outside'的时候会显示视觉引导线。
  52. show: false
  53. }
  54. },
  55. emphasis: { // 高亮的扇区和标签样式(起强调作用)
  56. color: "#5886f0",
  57. borderColor: "#5886f0",
  58. borderWidth: 20,
  59. borderType: 'solid',
  60. label: {
  61. textStyle: {
  62. fontSize: 15,
  63. fontWeight: "bold"
  64. }
  65. }
  66. }
  67. },
  68. data: [{ value: 52.7, name: "男(480人) 比率52.7%"},
  69. { name: " ", value: 47.3,
  70. itemStyle: {
  71. normal: {
  72. color: "#5886f0",
  73. borderColor: "#5886f0",
  74. borderWidth: 0,
  75. label: {
  76. show: false
  77. },
  78. labelLine: {
  79. show: false
  80. }
  81. },
  82. emphasis: {
  83. color: "#5886f0",
  84. borderColor: "#5886f0",
  85. borderWidth: 0
  86. }
  87. }
  88. }
  89. ]
  90. }, {
  91. type: "pie", // 系列2类型: 饼图
  92. center: [
  93. "75.0%",
  94. "50%"
  95. ],
  96. radius: [
  97. "49%",
  98. "50%"
  99. ],
  100. clockWise: false,
  101. hoverAnimation: true,
  102. itemStyle: {
  103. normal: {
  104. label: {
  105. show: true,
  106. textStyle: {
  107. fontSize: 15,
  108. fontWeight: "bold"
  109. },
  110. position: "center"
  111. },
  112. labelLine: {
  113. show: false
  114. },
  115. color: "#ee3a3a",
  116. borderColor: "#ee3a3a",
  117. borderWidth: 20
  118. },
  119. emphasis: {
  120. label: {
  121. textStyle: {
  122. fontSize: 15,
  123. fontWeight: "bold"
  124. }
  125. },
  126. color: "#ee3a3a",
  127. borderColor: "#ee3a3a",
  128. borderWidth: 20
  129. }
  130. },
  131. data: [{
  132. value: 47.3,
  133. name: "女(421人) 占率47.3%"
  134. },
  135. {
  136. name: " ",
  137. value: 52.7,
  138. itemStyle: {
  139. normal: {
  140. label: {
  141. show: false
  142. },
  143. labelLine: {
  144. show: false
  145. },
  146. color: "#ee3a3a",
  147. borderColor: "#ee3a3a",
  148. borderWidth: 0
  149. },
  150. emphasis: {
  151. color: "#ee3a3a",
  152. borderColor: "#ee3a3a",
  153. borderWidth: 0
  154. }
  155. }
  156. }
  157. ]
  158. }
  159. ]
  160. };
  161. // 使用刚指定的配置项和数据显示图表
  162. chart1.setOption(option);
  163. </script>

想要使用该图表,只需要  复制以上代码  ,再下载    echarts.js  在页面文件中引入即可. 

注:本文的一个关键点就是环形图内部标签位置的设置,相关的配置项是 position,其取值分别为:

    'outside'(饼图扇区外侧,通过视觉引导线连到相应的扇区);

    'inside'(饼图扇区内部);      

    'inner' 同 'inside'; 

    'center'(在饼图中心位置);

echarts.js 下载链接:    http://echarts.baidu.com/download.html

猜你喜欢

转载自blog.csdn.net/rui512777/article/details/80911224