https://echarts.apache.org/examples/zh/editor.html?c=calendar-effectscatter
image.png

options

nameMap 设置多语言
https://echarts.apache.org/zh/option.html#calendar.dayLabel.nameMap

  1. import * as echarts from 'echarts/core';
  2. function getVirtualData(year) {
  3. const date = +echarts.number.parseDate(`${year}-06-01`)
  4. const end = +echarts.number.parseDate(`${year + 1}-12-31`)
  5. const dayTime = 3600 * 24 * 1000;
  6. const data = [];
  7. for (let time = date; time < end; time += dayTime) {
  8. data.push([
  9. echarts.format.formatTime('yyyy-MM-dd', time),
  10. Math.floor(Math.random() * 10000)
  11. ])
  12. }
  13. // 数据格式就是 calendarData.json 二维数组
  14. return data
  15. }
  16. export function getOption({data, length, theme}) {
  17. const yearData = getVirtualData(2020)
  18. return {
  19. calendar: [
  20. {
  21. top: 56,
  22. left: 56,
  23. right: 24,
  24. bottom: 24,
  25. range: ['2020-06-01', '2020-12-31'],
  26. splitLine: {
  27. show: true,
  28. lineStyle: {
  29. color: 'rgb(127, 127, 127)'
  30. }
  31. },
  32. yearLabel: {
  33. formatter: '{start}',
  34. nameMap: 'ZH',
  35. },
  36. dayLabel: {
  37. color: 'rgb(127, 127, 127)',
  38. fontSize: 18,
  39. nameMap: 'ZH',
  40. },
  41. monthLabel: {
  42. color: 'rgb(127, 127, 127)',
  43. fontSize: 18,
  44. nameMap: 'ZH',
  45. },
  46. itemStyle: {
  47. color: 'rgb(48, 48, 48)',
  48. borderWidth: 1,
  49. borderColor: 'rgb(48, 48, 48)'
  50. }
  51. }
  52. ],
  53. series: [
  54. {
  55. name: '步数',
  56. type: 'scatter',
  57. coordinateSystem: 'calendar',
  58. data: yearData,
  59. symbolSize: (val) => {
  60. return val[1] / 600
  61. },
  62. itemStyle: {
  63. color: 'rgb(208,248,138)'
  64. }
  65. },
  66. {
  67. name: 'Top 12',
  68. type: 'effectScatter',
  69. coordinateSystem: 'calendar',
  70. data: yearData.sort((a, b) => {
  71. return b[1] - a[1]
  72. }).slice(0, 12),
  73. symbolSize: (val) => {
  74. return val[1] / 500
  75. },
  76. showEffectOn: 'render',
  77. rippleEffect: {
  78. brushType: 'stroke'
  79. },
  80. hoverAnimation: true,
  81. itemStyle: {
  82. color: 'rgb(208,248,138)',
  83. shadowBlur: 10,
  84. shadowColor: '#333'
  85. },
  86. zlevel: 1
  87. }
  88. ],
  89. legend: {
  90. top: 8,
  91. right: 24,
  92. data: ['步数', 'Top 12'],
  93. textStyle: {
  94. color: 'rgba(0,0,0,.6)'
  95. }
  96. },
  97. tooltip: {
  98. trigger: 'item',
  99. backgroundColor: 'rgba(50,50,50, .8)',
  100. textStyle: {
  101. fontSize: 24, color: '#ccc',
  102. },
  103. enterable: true,
  104. extraCssText: 'max-height: 300px; overflow: auto;',
  105. },
  106. };
  107. }

locale 多语言

初始化设置多语言,默认为 ‘EN’,

  • 如果初始化没有设置,用到时,可以用 nameMap: ‘ZH’,

多语言参考 https://github.com/apache/echarts/tree/release/src/i18n

  1. echarts.init(current, null, {
  2. renderer: renderType,
  3. locale: 'ZH',
  4. });

image.png