123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <template>
- <apexchart type="area" height="200" :options="chartOptions" :series="series" ref="chart"/>
- </template>
- <script>
- import VueApexCharts from 'vue-apexcharts'
- import Vue from 'vue'
- Vue.use(VueApexCharts)
- Vue.component('apexchart', VueApexCharts)
- const fontColor = () => {
- return window.matchMedia('(prefers-color-scheme: dark)').matches ? '#b4b4b4' : undefined
- }
- export default {
- name: 'CPUChart',
- props: {
- series: Array
- },
- watch: {
- series: {
- deep: true,
- handler() {
- this.$refs.chart.updateSeries(this.series)
- }
- }
- },
- mounted() {
- let media = window.matchMedia('(prefers-color-scheme: dark)')
- let callback = () => {
- this.chartOptions.xaxis = {
- type: 'datetime',
- labels: {
- datetimeUTC: false,
- style: {
- colors: fontColor()
- }
- }
- }
- this.chartOptions.yaxis = {
- max: 100,
- tickAmount: 4,
- min: 0,
- labels: {
- style: {
- colors: fontColor()
- }
- }
- }
- this.chartOptions.legend = {
- labels: {
- colors: fontColor()
- },
- onItemClick: {
- toggleDataSeries: false
- },
- onItemHover: {
- highlightDataSeries: false
- },
- }
- this.$refs.chart.updateOptions(this.chartOptions)
- }
- if (typeof media.addEventListener === 'function') {
- media.addEventListener('change', callback)
- } else if (typeof media.addListener === 'function') {
- media.addListener(callback)
- }
- },
- data() {
- return {
- chartOptions: {
- series: this.series,
- chart: {
- type: 'area',
- zoom: {
- enabled: false
- },
- animations: {
- enabled: false,
- },
- toolbar: {
- show: false
- },
- },
- colors: ['#ff6385', '#36a3eb'],
- fill: {
- // type: ['solid', 'gradient'],
- gradient: {
- shade: 'light'
- }
- //colors: ['#ff6385', '#36a3eb'],
- },
- dataLabels: {
- enabled: false
- },
- stroke: {
- curve: 'smooth',
- width: 0,
- },
- xaxis: {
- type: 'datetime',
- labels: {
- datetimeUTC: false,
- style: {
- colors: fontColor()
- }
- }
- },
- tooltip: {
- enabled: false
- },
- yaxis: {
- max: 100,
- tickAmount: 4,
- min: 0,
- labels: {
- style: {
- colors: fontColor()
- }
- }
- },
- legend: {
- labels: {
- colors: fontColor()
- },
- onItemClick: {
- toggleDataSeries: false
- },
- onItemHover: {
- highlightDataSeries: false
- },
- }
- },
- }
- },
- }
- </script>
- <style scoped>
- </style>
|