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. backgroundColor: { // 背景颜色
  20. type: 'linear',
  21. x: 0,
  22. y: 0,
  23. x2: 0,
  24. y2: 1,
  25. colorStops: [{
  26. offset: 0, color: 'rgba(102,255,255,0.6)' // 0% 处的颜色
  27. }, {
  28. offset: 0.5, color: '#fff' // 50% 处的颜色
  29. }, {
  30. offset: 1, color: 'rgba(102,255,255,0.6)' // 100% 处的颜色
  31. }],
  32. globalCoord: false // 缺省为 false
  33. },
  34. title: { // 图表标题
  35. text: '漏斗图标题', // 标题文本内容
  36. link: 'https://blog.csdn.net/gray_key', // 标题链接地址
  37. target: 'blank', // 链接在新窗口打开
  38. left: '5%', // 标题距容器左侧5%
  39. top: '5%', // 标题距容器顶部5%
  40. textStyle: { // 标题文本样式
  41. color: '#000', // 字体颜色
  42. fontSize: 20, // 字体大小
  43. }
  44. },
  45. // 弹框提示
  46. tooltip: {
  47. trigger: 'item',
  48. formatter: "{a} <br/>{b} : {c}%" // a对应系列名称,b对应数据项名称,c对应数据项值.
  49. },
  50. // 图例
  51. legend: {
  52. data: [ '本市', '省内', '省外', '国外', '情况不明']
  53. },
  54. // 金字塔块的颜色
  55. color: [ '#FF0000', '#FFFF00', '#33ff00', '#33ffff', '#0000ff', ],
  56. // 系列
  57. series: [
  58. // 系列1 (外部)
  59. {
  60. name: '就业范围分析',
  61. type: 'funnel',
  62. left: '10%',
  63. width: '80%',
  64. sort : 'ascending', // 金字塔形:'ascending', 漏斗图形:'descending'
  65. label: {
  66. normal: {
  67. formatter: '{b}' // 金字塔外标签
  68. },
  69. /* emphasis: {
  70. position:'inside',
  71. formatter: '{b}预期: {c}%'
  72. }*/
  73. },
  74. labelLine: { // 标签的视觉引导线样式
  75. normal: {
  76. show: true, // 是否显示引导线
  77. length: 30 // 视觉引导线第一段的长度。
  78. }
  79. },
  80. itemStyle: { // 图形样式
  81. normal: {
  82. opacity: 0.4 // 系列1图形透明度
  83. }
  84. },
  85. tooltip: {
  86. show: false // 让系列一(金字塔外层图形的提示框不显示)
  87. },
  88. // 系列1数据(数据项值和数据项名称)
  89. // 系列1(外金字塔)的数据项值一般固定为:20、40、60、80、100,这种有规律的数值,
  90. // 这样外金字塔才能是一个正三角形.
  91. data: [
  92. { value: 20, name: '国外'},
  93. { value: 40, name: '情况不明'},
  94. { value: 60, name: '省外'},
  95. { value: 80, name: '省内'},
  96. { value: 100, name: '本市'}
  97. ]
  98. },
  99. // 系列2 (内部)
  100. {
  101. name: '就业范围分析',
  102. type: 'funnel',
  103. left: '10%',
  104. width: '80%',
  105. maxSize: '80%',
  106. sort : 'ascending',
  107. label: {
  108. normal: {
  109. position: 'inside', // 标签的位置:'left'漏斗图的左侧)、'right'(右侧)、'inside'(内部) [ default: 'outside' ]
  110. formatter: '{c}%', // 标签文本
  111. textStyle: {
  112. color: '#fff'
  113. }
  114. },
  115. emphasis: { // 本系列每个数据项中特定的 tooltip 设定
  116. position: 'inside',
  117. formatter: '{b}: {c}%'
  118. }
  119. },
  120. itemStyle: {
  121. normal: {
  122. opacity: 08, // 系列2图形透明度
  123. borderColor: '#fff', // 图形边框颜色
  124. borderWidth: 3 // 图形边框宽度大小
  125. }
  126. },
  127. // 系列2数据(数据项值和数据项名称)
  128. // 系列2(内金字塔)的数据项值才是真实的数据值,通过ajax请求获取数据后展示.
  129. // 至于系列1和系列2的数据项名一般相同或是相关联的.
  130. data: [
  131. { value: 5, name: '国外'},
  132. { value: 12, name: '情况不明'},
  133. { value: 18, name: '省外'},
  134. { value: 25, name: '省内'},
  135. { value: 40, name: '本市'}
  136. ]
  137. }
  138. ]
  139. };
  140. // 使用刚指定的配置项和数据显示图表
  141. chart1.setOption(option)
  142. </script>

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

注:想要让图表由金字塔转变为漏斗图,只需建将代码中图表配置项中的  sort : 'ascending'   改为  sort : 'descending'  即可。

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

猜你喜欢

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