image.png

baselineOption

  1. import * as echarts from 'echarts';
  2. import {chinaJson} from '@/components/ECharts/Map';
  3. import {getData, colors, provinces, convertData} from './_data';
  4. import {geo, timeline, baseOption} from './config';
  5. const cities = ['北京', '上海', '广州', '深圳', '杭州', '南京'];
  6. const mapData = cities.map((it, i) => []);
  7. const series = {
  8. data1: getData(10, 6000),
  9. data2: getData(10, 7000),
  10. data3: getData(10, 8000),
  11. data4: getData(10, 9000),
  12. data5: getData(100, 6000),
  13. data6: getData(100, 3000),
  14. }
  15. function chinaOption() {
  16. echarts.registerMap('china', chinaJson);
  17. // 柱图数据 [[], [], [], [], [], []]
  18. provinces.forEach((item, index) => {
  19. const key = item.name;
  20. mapData.forEach((child, i) => {
  21. const {value} = series[`data${i + 1}`].find(it => it.name === key) || {};
  22. child.push({name: key, value})
  23. child.sort((a, b) => a.value - b.value)
  24. })
  25. });
  26. // 柱图 X轴数据 [[], [], [], [], [], []]
  27. // const xdata = cities.map((it, i) => {
  28. // return mapData[i].map(it => it.name);
  29. // });
  30. // 柱状图数据
  31. const barData = cities.map((it, i) => {
  32. return mapData[i].map(it => it.value);
  33. });
  34. const config = {
  35. timeline: timeline(cities),
  36. baseOption: {
  37. ...baseOption(provinces),
  38. geo,
  39. },
  40. options: [],
  41. }
  42. // options[] 里面的每一项会合并 baseOption
  43. cities.forEach((item, i) => {
  44. const color = colors[3][i];
  45. const rowData = {
  46. title: [
  47. {
  48. text: '区域销售大盘',
  49. left: 16,
  50. top: 16,
  51. textStyle: {
  52. color: '#fff',
  53. fontSize: 12,
  54. }
  55. },
  56. {
  57. id: 'statistic',
  58. text: `${item}销售额统计情况`,
  59. top: 8,
  60. right: 4,
  61. textStyle: {
  62. color: '#fff',
  63. fontSize: 12
  64. }
  65. }
  66. ],
  67. series: [
  68. // 2 散点图
  69. {
  70. type: 'effectScatter',
  71. coordinateSystem: 'geo',
  72. data: convertData(mapData[i]),
  73. symbolSize: arr => arr[2],
  74. showEffectOn: 'render',
  75. hoverAnimation: true,
  76. // 涟漪配置
  77. // https://echarts.apache.org/zh/option.html#series-effectScatter.rippleEffect
  78. rippleEffect: {
  79. brushType: 'stroke'
  80. },
  81. label: {
  82. normal: {
  83. formatter: '{b}',
  84. position: 'right',
  85. show: false // 全部显示,太拥挤了,高亮显示文字
  86. },
  87. emphasis: {
  88. show: true
  89. }
  90. },
  91. // 散点图颜色和柱图保持一致
  92. itemStyle: {
  93. normal: {
  94. color,
  95. shadowBlur: 8,
  96. shadowColor: color
  97. }
  98. },
  99. zlevel: 1
  100. },
  101. // 1 柱状图
  102. {
  103. zlevel: 1.5,
  104. type: 'bar',
  105. data: barData[i],
  106. itemStyle: {
  107. normal: {color}
  108. },
  109. }
  110. ]
  111. }
  112. config.options.push(rowData);
  113. });
  114. return config;
  115. }
  116. export default chinaOption;

convertData

  1. // 散点图的 value前2个值必须是坐标系,最后一个才是真实的数据
  2. export function convertData(data) {
  3. return data.map(item => {
  4. const {name} = item;
  5. const {geoCoordMap} = provinces.find(it => it.name === name) || {};
  6. const value = [...geoCoordMap, randomValue(4, 16)]
  7. return {
  8. name,
  9. value,
  10. }
  11. });
  12. }