MarketLineChart.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <div class="market-line-chart">
  3. <LineChart :options="options" :datas="chartData" :extend="extend" />
  4. </div>
  5. </template>
  6. <script>
  7. import LineChart from '@/components/chart/LineChart'
  8. export default {
  9. name: 'market-line-chart',
  10. components: {
  11. LineChart
  12. },
  13. props: {
  14. chartData: {
  15. type: Object,
  16. default () {
  17. return {
  18. columns: [],
  19. rows: []
  20. }
  21. }
  22. }
  23. },
  24. data () {
  25. return {
  26. extend: {
  27. yAxis: {
  28. axisLabel: {
  29. formatter: p => p + '%'
  30. }
  31. }
  32. },
  33. options: {
  34. height: '326px',
  35. colors: ['#05A6F3', '#FF9F40'],
  36. config: this.configOptions
  37. }
  38. }
  39. },
  40. methods: {
  41. configOptions (options) {
  42. // 面积颜色-渐变
  43. Object.assign(options.series[0], {
  44. areaStyle: {
  45. normal: {
  46. color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
  47. {
  48. offset: 0,
  49. color: 'rgba(42, 190, 209, 0.12)'
  50. },
  51. {
  52. offset: 1,
  53. color: 'rgba(42, 190, 209, 0)'
  54. }
  55. ], false)
  56. }
  57. }
  58. })
  59. Object.assign(options.series[1], {
  60. areaStyle: {
  61. normal: {
  62. color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
  63. {
  64. offset: 0,
  65. color: 'rgba(255, 159, 63, 0.12)'
  66. },
  67. {
  68. offset: 1,
  69. color: 'rgba(255, 159, 63, 0)'
  70. }
  71. ], false)
  72. }
  73. }
  74. })
  75. Object.assign(options.legend, {
  76. icon: 'rect'
  77. })
  78. options.tooltip.formatter = params => {
  79. let tip = `<div style="padding-top:2px;color:#9B9CA3;">${params[0].name}</div>`
  80. for (let i = 0; i < params.length; i++) {
  81. params[i].marker = '<span style="display:inline-block;margin-right:5px;border-radius:8px;width:8px;height:8px;background-color:' + params[i].color + ';"></span>'
  82. tip += params[i].marker + params[i].seriesName + ':' + params[i].value[1].toString().replace(/,/, '') + '%' + '<br/>'
  83. }
  84. return tip
  85. }
  86. return options
  87. }
  88. }
  89. }
  90. </script>