|
| 1 | +<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 | + /> |
| 10 | +</template> |
| 11 | + |
| 12 | +<script> |
| 13 | +import { CChart } from "@coreui/vue-chartjs"; |
| 14 | +import { getStyle, hexToRgba } from "@coreui/utils/src"; |
| 15 | +
|
| 16 | +function random(min, max) { |
| 17 | + return Math.floor(Math.random() * (max - min + 1) + min); |
| 18 | +} |
| 19 | +
|
| 20 | +export default { |
| 21 | + name: "MainChartExample", |
| 22 | + components: { |
| 23 | + CChart, |
| 24 | + }, |
| 25 | + setup() { |
| 26 | + const data = { |
| 27 | + labels: ["January", "February", "March", "April", "May", "June", "July"], |
| 28 | + datasets: [ |
| 29 | + { |
| 30 | + label: "My First dataset", |
| 31 | + backgroundColor: hexToRgba(getStyle("--cui-info"), 10), |
| 32 | + borderColor: getStyle("--cui-info"), |
| 33 | + pointHoverBackgroundColor: getStyle("--cui-info"), |
| 34 | + borderWidth: 2, |
| 35 | + data: [ |
| 36 | + random(50, 200), |
| 37 | + random(50, 200), |
| 38 | + random(50, 200), |
| 39 | + random(50, 200), |
| 40 | + random(50, 200), |
| 41 | + random(50, 200), |
| 42 | + random(50, 200), |
| 43 | + ], |
| 44 | + fill: true, |
| 45 | + }, |
| 46 | + { |
| 47 | + label: "My Second dataset", |
| 48 | + backgroundColor: "transparent", |
| 49 | + borderColor: getStyle("--cui-success"), |
| 50 | + pointHoverBackgroundColor: getStyle("--cui-success"), |
| 51 | + borderWidth: 2, |
| 52 | + data: [ |
| 53 | + random(50, 200), |
| 54 | + random(50, 200), |
| 55 | + random(50, 200), |
| 56 | + random(50, 200), |
| 57 | + random(50, 200), |
| 58 | + random(50, 200), |
| 59 | + random(50, 200), |
| 60 | + ], |
| 61 | + }, |
| 62 | + { |
| 63 | + label: "My Third dataset", |
| 64 | + backgroundColor: "transparent", |
| 65 | + borderColor: getStyle("--cui-danger"), |
| 66 | + pointHoverBackgroundColor: getStyle("--cui-danger"), |
| 67 | + borderWidth: 1, |
| 68 | + borderDash: [8, 5], |
| 69 | + data: [65, 65, 65, 65, 65, 65, 65], |
| 70 | + }, |
| 71 | + ], |
| 72 | + }; |
| 73 | +
|
| 74 | + const options = { |
| 75 | + maintainAspectRatio: false, |
| 76 | + plugins: { |
| 77 | + legend: { |
| 78 | + display: false, |
| 79 | + }, |
| 80 | + }, |
| 81 | + scales: { |
| 82 | + x: { |
| 83 | + grid: { |
| 84 | + drawOnChartArea: false, |
| 85 | + }, |
| 86 | + }, |
| 87 | + y: { |
| 88 | + ticks: { |
| 89 | + beginAtZero: true, |
| 90 | + maxTicksLimit: 5, |
| 91 | + stepSize: Math.ceil(250 / 5), |
| 92 | + max: 250, |
| 93 | + }, |
| 94 | + }, |
| 95 | + }, |
| 96 | + elements: { |
| 97 | + line: { |
| 98 | + tension: 0.4, |
| 99 | + }, |
| 100 | + point: { |
| 101 | + radius: 0, |
| 102 | + hitRadius: 10, |
| 103 | + hoverRadius: 4, |
| 104 | + hoverBorderWidth: 3, |
| 105 | + }, |
| 106 | + }, |
| 107 | + }; |
| 108 | +
|
| 109 | + return { |
| 110 | + data, |
| 111 | + options, |
| 112 | + }; |
| 113 | + }, |
| 114 | + methods: { |
| 115 | + aa(value, value2) { |
| 116 | + console.log(value); |
| 117 | + console.log(value2); |
| 118 | + }, |
| 119 | + }, |
| 120 | +}; |
| 121 | +</script> |
0 commit comments