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: 'rgba(204,204,204,0.7 )', // 背景色,默认无背景 rgba(51,255,255,0.7)
  20. title: {
  21. text: '各教育阶段男女人数统计',
  22. link: 'https://blog.csdn.net/gray_key',
  23. target: 'blank',
  24. top: '5%',
  25. left: '3%',
  26. textStyle: {
  27. color: '#fff',
  28. fontSize: 20,
  29. }
  30. },
  31. legend: { // 图例组件
  32. show: true,
  33. icon: 'rect', // 图例项的 icon。ECharts 提供的标记类型包括 'circle', 'rect', 'roundRect', 'triangle', 'diamond', 'pin', 'arrow'也可以通过 'image://url' 设置为图片,其中 url 为图片的链接,或者 dataURI。可以通过 'path://' 将图标设置为任意的矢量路径。
  34. top : '40%', // 图例距离顶部边距
  35. left : '15%', // 图例距离左侧边距
  36. itemWidth: 10, // 图例标记的图形宽度。[ default: 25 ]
  37. itemHeight: 10, // 图例标记的图形高度。[ default: 14 ]
  38. itemGap: 30, // 图例每项之间的间隔。[ default: 10 ]横向布局时为水平间隔,纵向布局时为纵向间隔。
  39. orient: 'vertical', // 图例列表的布局朝向,'horizontal'为横向,''为纵向.
  40. textStyle: { // 图例的公用文本样式。
  41. fontSize: 15,
  42. color: '#fff'
  43. },
  44. data: [{ // 图例的数据数组。数组项通常为一个字符串,每一项代表一个系列的 name(如果是饼图,也可以是饼图单个数据的 name)。图例组件会自动根据对应系列的图形标记(symbol)来绘制自己的颜色和标记,特殊字符串 ''(空字符串)或者 '\n'(换行字符串)用于图例的换行。
  45. name: '男', // 图例项的名称,应等于某系列的name值(如果是饼图,也可以是饼图单个数据的 name)。
  46. icon: 'rect', // 图例项的 icon。
  47. textStyle: { // 图例项的文本样式。
  48. color: 'rgba(51,0,255,1)',
  49. fontWeight: 'bold' // 文字字体的粗细,可选'normal','bold','bolder','lighter'
  50. }
  51. },{
  52. name: '女',
  53. icon: 'rect',
  54. textStyle: {
  55. color: 'rgba(255,0,0,1)',
  56. fontWeight: 'bold' // 文字字体的粗细,可选'normal','bold','bolder','lighter'
  57. }
  58. }],
  59. },
  60. radar: [{ // 雷达图坐标系组件,只适用于雷达图。
  61. center: [ '50%', '50%'], // 圆中心坐标,数组的第一项是横坐标,第二项是纵坐标。[ default: ['50%', '50%'] ]
  62. radius: 160, // 圆的半径,数组的第一项是内半径,第二项是外半径。
  63. startAngle: 90, // 坐标系起始角度,也就是第一个指示器轴的角度。[ default: 90 ]
  64. name: { // (圆外的标签)雷达图每个指示器名称的配置项。
  65. formatter: '{value}',
  66. textStyle: {
  67. fontSize: 15,
  68. color: '#000'
  69. }
  70. },
  71. nameGap: 15, // 指示器名称和指示器轴的距离。[ default: 15 ]
  72. splitNumber: 4, // (这里是圆的环数)指示器轴的分割段数。[ default: 5 ]
  73. shape: 'circle', // 雷达图绘制类型,支持 'polygon'(多边形) 和 'circle'(圆)。[ default: 'polygon' ]
  74. axisLine: { // (圆内的几条直线)坐标轴轴线相关设置
  75. lineStyle: {
  76. color: '#fff', // 坐标轴线线的颜色。
  77. width: 1, // 坐标轴线线宽。
  78. type: 'solid', // 坐标轴线线的类型。
  79. }
  80. },
  81. splitLine: { // (这里是指所有圆环)坐标轴在 grid 区域中的分隔线。
  82. lineStyle: {
  83. color: '#fff', // 分隔线颜色
  84. width: 2, // 分隔线线宽
  85. }
  86. },
  87. splitArea: { // 坐标轴在 grid 区域中的分隔区域,默认不显示。
  88. show: true,
  89. areaStyle: { // 分隔区域的样式设置。
  90. color: [ 'rgba(250,250,250,0.3)', 'rgba(200,200,200,0.3)'], // 分隔区域颜色。分隔区域会按数组中颜色的顺序依次循环设置颜色。默认是一个深浅的间隔色。
  91. }
  92. },
  93. indicator: [{ // 雷达图的指示器,用来指定雷达图中的多个变量(维度),跟data中 value 对应
  94. name: '高中', // 指示器名称
  95. max: 15000, // 指示器的最大值,可选,建议设置
  96. //color: '#fff' // 标签特定的颜色。
  97. }, {
  98. name: '专科',
  99. max: 10000
  100. }, {
  101. name: '本科',
  102. max: 8000
  103. }, {
  104. name: '硕士',
  105. max: 2000
  106. }, {
  107. name: '博士',
  108. max: 500
  109. }]
  110. }],
  111. series: [{
  112. name: '雷达图', // 系列名称,用于tooltip的显示,legend 的图例筛选,在 setOption 更新数据和配置项时用于指定对应的系列。
  113. type: 'radar', // 系列类型: 雷达图
  114. itemStyle: { // 折线拐点标志的样式。
  115. normal: { // 普通状态时的样式
  116. lineStyle: {
  117. width: 1
  118. },
  119. opacity: 0.2
  120. },
  121. emphasis: { // 高亮时的样式
  122. lineStyle: {
  123. width: 5
  124. },
  125. opacity: 1
  126. }
  127. },
  128. data: [{ // 雷达图的数据是多变量(维度)的
  129. name: '女', // 数据项名称
  130. value: [ 11035, 6013, 5067, 1520, 184], // 其中的value项数组是具体的数据,每个值跟 radar.indicator 一一对应。
  131. symbol: 'circle', // 单个数据标记的图形。
  132. symbolSize: 5, // 单个数据标记的大小,可以设置成诸如 10 这样单一的数字,也可以用数组分开表示宽和高,例如 [20, 10] 表示标记宽为20,高为10。
  133. label: { // 单个拐点文本的样式设置
  134. normal: {
  135. show: true, // 单个拐点文本的样式设置。[ default: false ]
  136. position: 'top', // 标签的位置。[ default: top ]
  137. distance: 5, // 距离图形元素的距离。当 position 为字符描述值(如 'top'、'insideRight')时候有效。[ default: 5 ]
  138. color: 'rgba(255,0,0,1)', // 文字的颜色。如果设置为 'auto',则为视觉映射得到的颜色,如系列色。[ default: "#fff" ]
  139. fontSize: 14, // 文字的字体大小
  140. formatter: function(params) {
  141. return params.value;
  142. }
  143. }
  144. },
  145. itemStyle: { // 单个拐点标志的样式设置。
  146. normal: {
  147. borderColor: 'rgba(255,0,0,1)', // 拐点的描边颜色。[ default: '#000' ]
  148. borderWidth: 3, // 拐点的描边宽度,默认不描边。[ default: 0 ]
  149. }
  150. },
  151. lineStyle: { // 单项线条样式。
  152. normal: {
  153. opacity: 0.5 // 图形透明度
  154. }
  155. },
  156. areaStyle: { // 单项区域填充样式
  157. normal: {
  158. color: 'rgba(255,0,0,0.6)' // 填充的颜色。[ default: "#000" ]
  159. }
  160. }
  161. }, {
  162. name: '男',
  163. value: [ 13408, 5065, 5947, 856, 302],
  164. symbol: 'circle',
  165. symbolSize: 5,
  166. label: {
  167. normal: {
  168. show: true,
  169. position: 'top',
  170. distance: 5,
  171. color: 'rgba(51,0,255,1)',
  172. fontSize: 14,
  173. formatter: function(params) {
  174. return params.value;
  175. }
  176. }
  177. },
  178. itemStyle: {
  179. normal: {
  180. borderColor: 'rgba(51,0,255,1)',
  181. borderWidth: 3,
  182. }
  183. },
  184. lineStyle: {
  185. normal: {
  186. opacity: 0.5
  187. }
  188. },
  189. areaStyle: {
  190. normal: {
  191. color: 'rgba(51,0,255,0.5)'
  192. }
  193. }
  194. }]
  195. }, ]
  196. };
  197. // 使用刚指定的配置项和数据显示图表
  198. chart1.setOption(option)
  199. </script>

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

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

猜你喜欢

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