NetChart.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <apexchart type="area" height="200" :options="chartOptions" :series="series" ref="chart"/>
  3. </template>
  4. <script>
  5. import VueApexCharts from 'vue-apexcharts'
  6. import Vue from 'vue'
  7. Vue.use(VueApexCharts)
  8. Vue.component('apexchart', VueApexCharts)
  9. const fontColor = () => {
  10. return window.matchMedia('(prefers-color-scheme: dark)').matches ? '#b4b4b4' : undefined
  11. }
  12. export default {
  13. name: 'NetChart',
  14. props: {
  15. series: Array
  16. },
  17. watch: {
  18. series: {
  19. deep: true,
  20. handler() {
  21. this.$refs.chart.updateSeries(this.series)
  22. }
  23. }
  24. },
  25. mounted() {
  26. let media = window.matchMedia('(prefers-color-scheme: dark)')
  27. let callback = () => {
  28. this.chartOptions.xaxis = {
  29. type: 'datetime',
  30. labels: {
  31. datetimeUTC: false,
  32. style: {
  33. colors: fontColor()
  34. }
  35. }
  36. }
  37. this.chartOptions.yaxis = {
  38. tickAmount: 3,
  39. min: 0,
  40. labels: {
  41. style: {
  42. colors: fontColor()
  43. },
  44. formatter: (bytes) => {
  45. return this.bytesToSize(bytes) + '/s'
  46. }
  47. }
  48. }
  49. this.chartOptions.legend = {
  50. labels: {
  51. colors: fontColor()
  52. },
  53. onItemClick: {
  54. toggleDataSeries: false
  55. },
  56. onItemHover: {
  57. highlightDataSeries: false
  58. },
  59. }
  60. this.$refs.chart.updateOptions(this.chartOptions)
  61. }
  62. if (typeof media.addEventListener === 'function') {
  63. media.addEventListener('change', callback)
  64. } else if (typeof media.addListener === 'function') {
  65. media.addListener(callback)
  66. }
  67. },
  68. data() {
  69. return {
  70. chartOptions: {
  71. series: this.series,
  72. chart: {
  73. type: 'area',
  74. zoom: {
  75. enabled: false
  76. },
  77. animations: {
  78. enabled: false,
  79. },
  80. toolbar: {
  81. show: false
  82. },
  83. },
  84. colors: ['#ff6385', '#36a3eb'],
  85. fill: {
  86. // type: ['solid', 'gradient'],
  87. gradient: {
  88. shade: 'light'
  89. }
  90. //colors: ['#ff6385', '#36a3eb'],
  91. },
  92. dataLabels: {
  93. enabled: false
  94. },
  95. stroke: {
  96. curve: 'smooth',
  97. width: 0,
  98. },
  99. xaxis: {
  100. type: 'datetime',
  101. labels: {
  102. datetimeUTC: false,
  103. style: {
  104. colors: fontColor()
  105. }
  106. }
  107. },
  108. tooltip: {
  109. enabled: false
  110. },
  111. yaxis: {
  112. tickAmount: 3,
  113. min: 0,
  114. labels: {
  115. style: {
  116. colors: fontColor()
  117. },
  118. formatter: (bytes) => {
  119. return this.bytesToSize(bytes) + '/s'
  120. }
  121. }
  122. },
  123. legend: {
  124. labels: {
  125. colors: fontColor()
  126. },
  127. onItemClick: {
  128. toggleDataSeries: false
  129. },
  130. onItemHover: {
  131. highlightDataSeries: false
  132. },
  133. }
  134. },
  135. }
  136. },
  137. }
  138. </script>
  139. <style scoped>
  140. </style>