image.png

timelineOption

  1. import * as echarts from 'echarts';
  2. import {chinaJson} from '@/components/ECharts/Map';
  3. import { getData, colors, provinces } from './_data';
  4. const cities = ['北京', '上海', '广州', '深圳', '杭州', '南京'];
  5. const mapData = cities.map((it, i) => []);
  6. const series = {
  7. data1: getData(10, 6000),
  8. data2: getData(10, 7000),
  9. data3: getData(10, 8000),
  10. data4: getData(10, 9000),
  11. data5: getData(100, 6000),
  12. data6: getData(100, 3000),
  13. }
  14. function chinaOption() {
  15. echarts.registerMap('china', chinaJson);
  16. // 时间轴
  17. const timeline = {
  18. data: cities,
  19. axisType: 'category', // 坐标轴类型
  20. realtime: true, // 拖动时是否实时渲染视图
  21. rewind: false, // 是否启动反向播放,需要将loop置为true
  22. // loop: false, // 是否循环播放
  23. autoPlay: false, // 是否自动播放
  24. currentIndex: 0, // 起始位置
  25. // playInterval:3000, // 播放间隔
  26. left: 40, // timeline的位置
  27. bottom: 24,
  28. width: '80%',
  29. label: { // 文字样式控制
  30. normal: {
  31. textStyle: { color: '#ddd'}
  32. },
  33. emphasis: {
  34. textStyle: { color: '#fff'}
  35. }
  36. },
  37. // 以下都是 timeline的样式
  38. symbolSize: 16,
  39. lineStyle: { color: '#555' },
  40. checkpointStyle: { // 选中的样式
  41. borderColor: '#fff',
  42. borderWidth: 2
  43. },
  44. controlStyle: { // 左右箭头控制
  45. showNextBtn: true,
  46. showPrevBtn: true,
  47. normal: {
  48. color: '#666',
  49. borderColor: '#666'
  50. },
  51. emphasis: {
  52. color: '#fff',
  53. borderColor: '#fff'
  54. }
  55. }
  56. };
  57. // 柱图数据 [[], [], [], [], [], []]
  58. provinces.forEach((item, index) => {
  59. const key = item.name;
  60. mapData.forEach((child, i) => {
  61. const {value} = series[`data${i+1}`].find(it => it.name === key) || {};
  62. child.push({ name: key, value })
  63. child.sort((a,b) => a.value - b.value)
  64. })
  65. });
  66. // 柱图 X轴数据 [[], [], [], [], [], []]
  67. const xdata = cities.map((it, i) => {
  68. return mapData[i].map(it => it.name);
  69. });
  70. const barData = cities.map((it, i) => {
  71. return mapData[i].map(it => it.value);
  72. });
  73. const config = {
  74. timeline,
  75. baseOption: {
  76. backgroundColor: '#424446',
  77. // 动画设置
  78. animation: true,
  79. animationDuration: 500,
  80. animationDurationUpdate: 500,
  81. animationEasing: 'linear',
  82. animationEasingUpdate: 'linear',
  83. universalTransition: true,
  84. grid: {
  85. right: 24,
  86. top: 48,
  87. // bottom: 24,
  88. width: '20%',
  89. // containLabel: true,
  90. },
  91. tooltip: {
  92. trigger: 'axis', // hover触发器
  93. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  94. type: 'shadow', // 默认为直线,可选为:'line' | 'shadow'
  95. shadowStyle: {
  96. color: 'rgba(150,150,150,0.1)' // hover颜色
  97. }
  98. }
  99. },
  100. xAxis: {
  101. type: 'value',
  102. // scale: true,
  103. position: 'top',
  104. splitNumber: 3,
  105. boundaryGap: false,
  106. splitLine: {
  107. interval: 1,
  108. lineStyle: {
  109. type: [4, 8],
  110. // dashOffset: 5,
  111. color: 'rgba(170,170,170,0.08)',
  112. }
  113. },
  114. axisLine: { show: false },
  115. axisTick: { show: false },
  116. axisLabel: {
  117. // show: false,
  118. margin: 2,
  119. interval: 1,
  120. textStyle: {
  121. color: '#aaa'
  122. }
  123. }
  124. },
  125. yAxis: {
  126. type: 'category',
  127. // name: 'TOP 20',
  128. nameGap: 16,
  129. axisLine: {
  130. show: true,
  131. lineStyle: {
  132. color: '#ddd'
  133. }
  134. },
  135. axisTick: {
  136. show: false,
  137. lineStyle: {
  138. color: '#ddd'
  139. }
  140. },
  141. axisLabel: {
  142. interval: 0,
  143. textStyle: {
  144. color: '#ddd'
  145. }
  146. },
  147. data: provinces.map(it => it.name)
  148. },
  149. // 地图设置
  150. geo: {
  151. map: "china",
  152. roam: true,
  153. zoom: 1.35,
  154. scaleLimit: { min: 1, max: 2 },
  155. top: '10%', // 地图的位置
  156. left: '16%',
  157. center: [107.032858,33.079788],
  158. tooltip: {show: false},
  159. label: {
  160. normal: {
  161. show: false,
  162. fontSize: 12,
  163. color: "rgba(0,0,0,0.65)"
  164. }
  165. },
  166. itemStyle: {
  167. normal: {
  168. borderColor: "rgba(0, 0, 0, 0.08)",
  169. borderWidth: 1, // 默认 0
  170. // https://echarts.apache.org/zh/option.html#color
  171. areaColor: {
  172. type: 'radial',
  173. x: 1.13,
  174. y: 1.5,
  175. r: 0.8,
  176. colorStops: [{
  177. offset: 0,
  178. color: 'rgba(147, 235, 248, 0.005)' // 0% 的颜色
  179. }, {
  180. offset: 1,
  181. color: 'rgba(147, 235, 248, 0.13)' // 100% 的颜色
  182. }],
  183. globalCoord: false // 缺省为 false
  184. },
  185. shadowColor: 'rgba(128, 217, 248, .65)',
  186. // shadowColor: 'rgba(255, 255, 255, 1)',
  187. shadowOffsetX: -2,
  188. shadowOffsetY: 2,
  189. shadowBlur: 10
  190. },
  191. emphasis: {
  192. areaColor: '#389BB7', // 鼠标选择区域颜色
  193. color: '#fff',
  194. shadowOffsetX: 0,
  195. shadowOffsetY: 0,
  196. borderWidth: 0
  197. }
  198. },
  199. },
  200. },
  201. options: [],
  202. }
  203. // options[] 里面的每一项会合并 baseOption
  204. cities.forEach((item, i) => {
  205. const rowData = {
  206. title: [
  207. {
  208. text: '区域销售大盘',
  209. left: 16,
  210. top: 16,
  211. textStyle: {
  212. color: '#fff',
  213. fontSize: 12,
  214. }
  215. },
  216. {
  217. id: 'statistic',
  218. text: `${item}销售额统计情况`,
  219. top: 8,
  220. right: 4,
  221. textStyle: {
  222. color: '#fff',
  223. fontSize: 12
  224. }
  225. }
  226. ],
  227. yAxis: {
  228. data: xdata[i],
  229. // data: provinces.map(it => it.name), // Y轴不变,柱图会平滑过渡
  230. },
  231. series: [
  232. {
  233. zlevel: 1.5,
  234. type: 'bar',
  235. data: barData[i],
  236. itemStyle: {
  237. normal: {
  238. color: colors[3][i]
  239. }
  240. },
  241. }
  242. ]
  243. }
  244. config.options.push(rowData);
  245. });
  246. return config;
  247. }
  248. export default chinaOption;

randomValue

  1. import provinces from './provinces.json';
  2. export function randomValue(min=0, max=100) {
  3. return Math.floor(Math.random() * (max - min)) + min
  4. }
  5. export { provinces }
  6. export const colors = [
  7. ['#1DE9B6', '#1DE9B6', '#FFDB5C', '#FFDB5C', '#04B9FF', '#04B9FF'],
  8. ['#1DE9B6', '#F46E36', '#04B9FF', '#5DBD32', '#FFC809', '#FB95D5', '#BDA29A', '#6E7074', '#546570', '#C4CCD3'],
  9. ['#37A2DA', '#67E0E3', '#32C5E9', '#9FE6B8', '#FFDB5C', '#FF9F7F', '#FB7293', '#E062AE', '#E690D1', '#E7BCF3', '#9D96F5', '#8378EA', '#8378EA'],
  10. ['#DD6B66', '#759AA0', '#E69D87', '#8DC1A9', '#EA7E53', '#EEDD78', '#73A373', '#73B9BC', '#7289AB', '#91CA8C', '#F49F42']
  11. ]
  12. export function getData(min, max) {
  13. return provinces
  14. .map((item) => {
  15. return {...item, value: randomValue(min, max)}
  16. })
  17. .sort((a, b) => a.value - b.value);
  18. }