mini-echarts.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template id="mini-echarts">
  2. <div class="mini-echarts" ref='echarts'></div>
  3. </template>
  4. <script>
  5. // 组件变量传不出去
  6. Vue.component('mini-echarts', {
  7. name: "mini-echarts",
  8. template: '#mini-echarts',
  9. props: {
  10. options: {
  11. type: Object,
  12. default () {
  13. return {}
  14. }
  15. },
  16. data: {
  17. type: Object,
  18. default () {
  19. return {}
  20. }
  21. }
  22. },
  23. methods: {
  24. echarts() {
  25. var chartDom = this.$refs.echarts
  26. var myChart = echarts.init(chartDom);
  27. var option;
  28. option = {
  29. grid: {
  30. left: '-6px',
  31. right: '-6px',
  32. top: '0px',
  33. bottom: '0%'
  34. },
  35. xAxis: {
  36. show: false,
  37. data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri']
  38. },
  39. yAxis: {
  40. show: false,
  41. type: 'value'
  42. },
  43. series: [{
  44. data: [100, 200, 400, 100, 200],
  45. type: 'line',
  46. smooth: true,
  47. showSymbol: false,
  48. max: 1000,
  49. lineStyle: {
  50. width: 1,
  51. color: '#0034E4'
  52. },
  53. areaStyle: {
  54. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  55. offset: 0,
  56. color: 'rgba(0, 52, 228, 0)'
  57. },
  58. {
  59. offset: 1,
  60. color: 'rgba(0, 52, 228, 0.56)'
  61. }
  62. ])
  63. },
  64. }]
  65. };
  66. option && myChart.setOption(option);
  67. }
  68. },
  69. mounted() {
  70. this.echarts()
  71. }
  72. });
  73. </script>
  74. <style>
  75. .mini-echarts {
  76. width: 100%;
  77. height: 100%;
  78. }
  79. </style>