11<template >
2- <CChart
3- type =" line"
4- :data =" data"
5- :options =" options"
6- @get-dataset-at-event =" aa"
7- @get-element-at-event =" aa"
8- @get-elements-at-event =" aa"
9- />
2+ <CChart type =" line" :data =" data" :options =" options" ref =" mainChartRef" />
103</template >
114
125<script >
6+ import { onMounted , ref } from ' vue'
137import { CChart } from ' @coreui/vue-chartjs'
14- import { getStyle , hexToRgba } from ' @coreui/utils/src '
8+ import { getStyle } from ' @coreui/utils'
159
16- function random (min , max ) {
17- return Math .floor (Math .random () * (max - min + 1 ) + min)
18- }
10+ const random = (min , max ) => Math .floor (Math .random () * (max - min + 1 ) + min)
1911
2012export default {
2113 name: ' MainChartExample' ,
2214 components: {
2315 CChart,
2416 },
2517 setup () {
18+ const mainChartRef = ref ()
2619 const data = {
2720 labels: [' January' , ' February' , ' March' , ' April' , ' May' , ' June' , ' July' ],
2821 datasets: [
2922 {
3023 label: ' My First dataset' ,
31- backgroundColor: hexToRgba ( getStyle (' --cui-info' ), 10 ) ,
24+ backgroundColor: ` rgba( ${ getStyle (' --cui-info-rgb ' ) } , .1) ` ,
3225 borderColor: getStyle (' --cui-info' ),
3326 pointHoverBackgroundColor: getStyle (' --cui-info' ),
3427 borderWidth: 2 ,
@@ -81,15 +74,26 @@ export default {
8174 scales: {
8275 x: {
8376 grid: {
77+ color: getStyle (' --cui-border-color-translucent' ),
8478 drawOnChartArea: false ,
8579 },
80+ ticks: {
81+ color: getStyle (' --cui-body-color' ),
82+ },
8683 },
8784 y: {
85+ border: {
86+ color: getStyle (' --cui-border-color-translucent' ),
87+ },
88+ grid: {
89+ color: getStyle (' --cui-border-color-translucent' ),
90+ },
8891 ticks: {
8992 beginAtZero: true ,
93+ color: getStyle (' --cui-body-color' ),
94+ max: 250 ,
9095 maxTicksLimit: 5 ,
9196 stepSize: Math .ceil (250 / 5 ),
92- max: 250 ,
9397 },
9498 },
9599 },
@@ -106,16 +110,39 @@ export default {
106110 },
107111 }
108112
113+ onMounted (() => {
114+ document .documentElement .addEventListener (' ColorSchemeChange' , () => {
115+ if (mainChartRef .value ) {
116+ mainChartRef .value .chart ,
117+ (options .scales .x .grid .borderColor = getStyle (
118+ ' --cui-border-color-translucent' ,
119+ ))
120+ mainChartRef .value .chart ,
121+ (options .scales .x .grid .color = getStyle (
122+ ' --cui-border-color-translucent' ,
123+ ))
124+ mainChartRef .value .chart ,
125+ (options .scales .x .ticks .color = getStyle (' --cui-body-color' ))
126+ mainChartRef .value .chart ,
127+ (options .scales .y .grid .borderColor = getStyle (
128+ ' --cui-border-color-translucent' ,
129+ ))
130+ mainChartRef .value .chart ,
131+ (options .scales .y .grid .color = getStyle (
132+ ' --cui-border-color-translucent' ,
133+ ))
134+ mainChartRef .value .chart ,
135+ (options .scales .y .ticks .color = getStyle (' --cui-body-color' ))
136+ mainChartRef .value .chart .update ()
137+ }
138+ })
139+ })
140+
109141 return {
110142 data,
143+ mainChartRef,
111144 options,
112145 }
113146 },
114- methods: {
115- aa (value , value2 ) {
116- console .log (value)
117- console .log (value2)
118- },
119- },
120147}
121148 </script >
0 commit comments