headerChart.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <div>
  3. <Bar
  4. :options="chartOptions"
  5. :data="myData"
  6. />
  7. </div>
  8. </template>
  9. <script setup>
  10. import { Bar } from "vue-chartjs"
  11. import {
  12. Chart as ChartJS,
  13. Title,
  14. Tooltip,
  15. Legend,
  16. BarElement,
  17. LineController,
  18. LineElement,
  19. PointElement,
  20. CategoryScale,
  21. ArcElement,
  22. LinearScale,
  23. Filler,
  24. } from "chart.js"
  25. ChartJS.register(
  26. Title,
  27. Tooltip,
  28. Legend,
  29. BarElement,
  30. LineController,
  31. LineElement,
  32. PointElement,
  33. CategoryScale,
  34. ArcElement,
  35. LinearScale,
  36. Filler
  37. )
  38. // props
  39. const props = defineProps({
  40. height: {
  41. type: Number,
  42. //default: 250,
  43. },
  44. objChartData: {
  45. type: Object,
  46. default: function () {
  47. return {}
  48. }
  49. },
  50. })
  51. // 차트 높이 유동 계산
  52. //const h = ref((document.querySelector("body").clientWidth / 100) * (470 / 19.2))
  53. const clientW = ref((document.querySelector("body").clientWidth))
  54. const chartData = ref({
  55. labels: [],
  56. datasets: [
  57. {
  58. label: "CUR",
  59. borderWidth : 1,
  60. pointBackgroundColor:'#FF531E',
  61. borderColor:'#FF531E',
  62. //lineTension : 0.5,
  63. pointRadius : 6,
  64. hoverRadius : 8,
  65. //borderDash : [4,6],
  66. pointStyle : "circle",
  67. data: [
  68. 5,9,9,10,7,
  69. 5,9,9,10,7,
  70. 5,9,9,10,7,
  71. 5,9,9,10,7,
  72. 5,9,9,10,7,
  73. ],
  74. type: "line",
  75. fill : false,
  76. },
  77. {
  78. label: "AVG",
  79. borderWidth : 1,
  80. pointBackgroundColor:'#44C5FF',
  81. borderColor:'#44C5FF',
  82. //lineTension : 0.5,
  83. pointRadius : 6,
  84. hoverRadius : 8,
  85. //borderDash : [4,6],
  86. pointStyle : "circle",
  87. data: [
  88. 10,10,12,11,10,
  89. 10,10,12,11,10,
  90. 10,10,12,11,10,
  91. 10,10,12,11,10,
  92. 10,10,12,11,10,
  93. ],
  94. type: "line",
  95. fill : false,
  96. },
  97. {
  98. label: "PEAK",
  99. borderWidth : 1,
  100. pointBackgroundColor : '#E1473D',
  101. borderColor:'#E1473D',
  102. //lineTension : 0.5,
  103. pointRadius : 6,
  104. hoverRadius : 8,
  105. //borderDash : [4,6],
  106. pointStyle : "circle",
  107. data: [
  108. 10,10,11,10,12,
  109. 10,10,11,10,12,
  110. 10,10,11,10,12,
  111. 10,10,11,10,12,
  112. 10,10,11,10,12,
  113. ],
  114. type: "line",
  115. fill : false,
  116. },
  117. ],
  118. })
  119. const chartOptions = ref({
  120. layout: {
  121. padding: {
  122. top: 0,
  123. },
  124. },
  125. responsive: true,
  126. maintainAspectRatio: false,
  127. duration: 1000,
  128. plugins: {
  129. legend: {
  130. display: false,
  131. labels: {
  132. paddingLeft: 15,
  133. boxHeight: 12,
  134. boxWidth: 12,
  135. usePointStyle : true,
  136. pointStyle : 'line',
  137. font: {
  138. size: 14,
  139. color: "#646B74",
  140. weight: "400",
  141. },
  142. },
  143. position: "top",
  144. align: "center",
  145. },
  146. datalabels: {
  147. display: false,
  148. },
  149. tooltip: {
  150. interaction: {
  151. //intersect: false,
  152. //mode: "index",
  153. },
  154. displayColors : false,
  155. callbacks: {
  156. title : function(tooltipItem, data){
  157. return tooltipItem[0].label.substr(0,10) + " " + tooltipItem[0].label.substr(11)
  158. // tooltipItem[0].parsed.x
  159. },
  160. label: function(tooltipItem, data) {
  161. //return tooltipItem.dataset.label
  162. // tooltipItem.formattedValue
  163. // tooltipItem.datasetIndex
  164. },
  165. titleFont: { // 타이틀 영역 폰트 스타일
  166. size: 10,
  167. weight:500,
  168. family:'Inter',
  169. },
  170. titleColor : '#f00', // 타이틀 영역 폰트 컬러
  171. titleAlign : 'right', // 타이틀 영역 align (left, center, right)
  172. titleMarginBottom : 3,
  173. },
  174. },
  175. },
  176. scales: {
  177. x: {
  178. beginAtZero: true,
  179. stacked: true,
  180. title: {
  181. text: "",
  182. align: "end",
  183. display: false,
  184. font: {
  185. color: "#666",
  186. size: 12,
  187. weight: "500",
  188. },
  189. },
  190. grid: {
  191. display: false,
  192. drawTicks: false,
  193. drawBorder: false,
  194. color: "transparent",
  195. },
  196. ticks: {
  197. padding: 20,
  198. font: {
  199. size: function(context){
  200. let clientW = document.querySelector("body").clientWidth;
  201. if(clientW <= 1930){
  202. return 11
  203. }else if(clientW >= 2550 && clientW < 3840){
  204. return 17
  205. }else if(clientW >= 3840){
  206. return 22
  207. }
  208. },
  209. weight: "400",
  210. },
  211. color: "#838FAC",
  212. align:'center',
  213. },
  214. },
  215. y: {
  216. border: {
  217. display: false,
  218. },
  219. beginAtZero: true,
  220. stacked: false,
  221. title: {
  222. display: false,
  223. text: "",
  224. },
  225. ticks: {
  226. display: true,
  227. padding: 10,
  228. font: {
  229. size: function(context){
  230. let clientW = document.querySelector("body").clientWidth;
  231. if(clientW <= 1930){
  232. return 11
  233. }else if(clientW >= 2550 && clientW < 3840){
  234. return 17
  235. }else if(clientW >= 3840){
  236. return 22
  237. }
  238. },
  239. weight: "400",
  240. },
  241. color: "#b1b1b1",
  242. },
  243. min:0
  244. },
  245. },
  246. animation: {
  247. duration: 0,
  248. },
  249. })
  250. let myData = computed(()=>{
  251. // 차트데이터 속성 반응형으로 복사한 후 값 설정
  252. let tempData = ref(_cloneDeep(chartData.value))
  253. tempData.value.labels = props.objChartData.labels
  254. tempData.value.datasets[0].data = props.objChartData.data[0]
  255. tempData.value.datasets[1].data = props.objChartData.data[1]
  256. tempData.value.datasets[2].data = props.objChartData.data[2]
  257. //tempData.value.datasets[0].data = props.objChartData.data1
  258. //tempData.value.datasets[1].data = props.objChartData.data2
  259. return tempData.value
  260. })
  261. </script>