defaultOption.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. const defaultOptions = {
  2. title: {
  3. text: '',
  4. left: 'left',
  5. top: 0,
  6. textStyle: {
  7. fontSize: 17
  8. }
  9. },
  10. textStyle: {
  11. color: '#909090'
  12. },
  13. grid: {
  14. top: 37,
  15. left: 40,
  16. right: 20,
  17. bottom: 20
  18. },
  19. color: ["#17D2D2", "#738EFE"],
  20. legend: {
  21. left: 'right',
  22. itemWidth: 14,
  23. icon: 'roundRect',
  24. textStyle: {
  25. fontSize: 11
  26. }
  27. },
  28. tooltip: {
  29. show: true,
  30. trigger: 'axis'
  31. // formatter: "{c} {d}"
  32. },
  33. xAxis: {
  34. type: 'category',
  35. // boundaryGap: false,
  36. data: [],
  37. boundaryGap: false,
  38. axisTick: {
  39. show: false
  40. },
  41. axisLine: {
  42. show: true,
  43. lineStyle: {
  44. color: '#e5e5e5'
  45. }
  46. },
  47. splitLine: {
  48. lineStyle: {
  49. color: '#e5e5e5'
  50. }
  51. },
  52. axisLabel: {
  53. showMaxLabel: true
  54. }
  55. },
  56. yAxis: {
  57. type: 'value',
  58. minInterval: 1,
  59. axisTick: {
  60. show: false
  61. },
  62. axisLine: {
  63. show: true,
  64. lineStyle: {
  65. color: '#e5e5e5'
  66. }
  67. },
  68. axisLabel: {
  69. margin: 7,
  70. formatter (value) {
  71. return value.toString()
  72. }
  73. },
  74. splitLine: {
  75. lineStyle: {
  76. color: '#e5e5e5'
  77. }
  78. }
  79. }
  80. }
  81. function isObject (value) {
  82. return Object.prototype.toString.call(value) === '[object Object]'
  83. }
  84. export function mergeOptions (options, defaultOption=defaultOptions) {
  85. Object.keys(defaultOption).forEach(item => {
  86. if (!options[item]) {
  87. options[item] = defaultOption[item]
  88. } else {
  89. if (isObject(options[item])) {
  90. mergeOptions(options[item], defaultOption[item])
  91. }
  92. }
  93. })
  94. return options
  95. }