| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <template>
- <div>
- <Bar
- :options="chartOptions"
- :data="myData"
- />
- </div>
- </template>
- <script setup>
- import { Bar } from "vue-chartjs"
- import {
- Chart as ChartJS,
- Title,
- Tooltip,
- Legend,
- BarElement,
- LineController,
- LineElement,
- PointElement,
- CategoryScale,
- ArcElement,
- LinearScale,
- Filler,
- } from "chart.js"
- ChartJS.register(
- Title,
- Tooltip,
- Legend,
- BarElement,
- LineController,
- LineElement,
- PointElement,
- CategoryScale,
- ArcElement,
- LinearScale,
- Filler
- )
- // props
- const props = defineProps({
- height: {
- type: Number,
- //default: 250,
- },
- objChartData: {
- type: Object,
- default: function () {
- return {}
- }
- },
- })
- // 차트 높이 유동 계산
- //const h = ref((document.querySelector("body").clientWidth / 100) * (470 / 19.2))
- const clientW = ref((document.querySelector("body").clientWidth))
- const chartData = ref({
- labels: [],
- datasets: [
- {
- label: "CUR",
- borderWidth : 1,
- pointBackgroundColor:'#FF531E',
- borderColor:'#FF531E',
- //lineTension : 0.5,
- pointRadius : 6,
- hoverRadius : 8,
- //borderDash : [4,6],
- pointStyle : "circle",
- data: [
- 5,9,9,10,7,
- 5,9,9,10,7,
- 5,9,9,10,7,
- 5,9,9,10,7,
- 5,9,9,10,7,
- ],
- type: "line",
- fill : false,
- },
- {
- label: "AVG",
- borderWidth : 1,
- pointBackgroundColor:'#44C5FF',
- borderColor:'#44C5FF',
- //lineTension : 0.5,
- pointRadius : 6,
- hoverRadius : 8,
- //borderDash : [4,6],
- pointStyle : "circle",
- data: [
- 10,10,12,11,10,
- 10,10,12,11,10,
- 10,10,12,11,10,
- 10,10,12,11,10,
- 10,10,12,11,10,
- ],
- type: "line",
- fill : false,
- },
- {
- label: "PEAK",
- borderWidth : 1,
- pointBackgroundColor : '#E1473D',
- borderColor:'#E1473D',
- //lineTension : 0.5,
- pointRadius : 6,
- hoverRadius : 8,
- //borderDash : [4,6],
- pointStyle : "circle",
- data: [
- 10,10,11,10,12,
- 10,10,11,10,12,
- 10,10,11,10,12,
- 10,10,11,10,12,
- 10,10,11,10,12,
- ],
- type: "line",
- fill : false,
- },
- ],
- })
- const chartOptions = ref({
- layout: {
- padding: {
- top: 0,
- },
- },
- responsive: true,
- maintainAspectRatio: false,
- duration: 1000,
- plugins: {
- legend: {
- display: false,
- labels: {
- paddingLeft: 15,
- boxHeight: 12,
- boxWidth: 12,
- usePointStyle : true,
- pointStyle : 'line',
- font: {
- size: 14,
- color: "#646B74",
- weight: "400",
- },
- },
- position: "top",
- align: "center",
- },
- datalabels: {
- display: false,
- },
- tooltip: {
- interaction: {
- //intersect: false,
- //mode: "index",
- },
- displayColors : false,
- callbacks: {
- title : function(tooltipItem, data){
- return tooltipItem[0].label.substr(0,10) + " " + tooltipItem[0].label.substr(11)
- // tooltipItem[0].parsed.x
- },
- label: function(tooltipItem, data) {
- //return tooltipItem.dataset.label
- // tooltipItem.formattedValue
- // tooltipItem.datasetIndex
- },
- titleFont: { // 타이틀 영역 폰트 스타일
- size: 10,
- weight:500,
- family:'Inter',
- },
- titleColor : '#f00', // 타이틀 영역 폰트 컬러
- titleAlign : 'right', // 타이틀 영역 align (left, center, right)
- titleMarginBottom : 3,
- },
- },
- },
- scales: {
- x: {
- beginAtZero: true,
- stacked: true,
- title: {
- text: "",
- align: "end",
- display: false,
- font: {
- color: "#666",
- size: 12,
- weight: "500",
- },
- },
- grid: {
- display: false,
- drawTicks: false,
- drawBorder: false,
- color: "transparent",
- },
- ticks: {
- padding: 20,
- font: {
- size: function(context){
- let clientW = document.querySelector("body").clientWidth;
- if(clientW <= 1930){
- return 11
- }else if(clientW >= 2550 && clientW < 3840){
- return 17
- }else if(clientW >= 3840){
- return 22
- }
- },
- weight: "400",
- },
- color: "#838FAC",
- align:'center',
- },
- },
- y: {
- border: {
- display: false,
- },
- beginAtZero: true,
- stacked: false,
- title: {
- display: false,
- text: "",
- },
- ticks: {
- display: true,
- padding: 10,
- font: {
- size: function(context){
- let clientW = document.querySelector("body").clientWidth;
- if(clientW <= 1930){
- return 11
- }else if(clientW >= 2550 && clientW < 3840){
- return 17
- }else if(clientW >= 3840){
- return 22
- }
- },
- weight: "400",
- },
- color: "#b1b1b1",
- },
- min:0
- },
- },
- animation: {
- duration: 0,
- },
- })
-
- let myData = computed(()=>{
- // 차트데이터 속성 반응형으로 복사한 후 값 설정
- let tempData = ref(_cloneDeep(chartData.value))
- tempData.value.labels = props.objChartData.labels
- tempData.value.datasets[0].data = props.objChartData.data[0]
- tempData.value.datasets[1].data = props.objChartData.data[1]
- tempData.value.datasets[2].data = props.objChartData.data[2]
- //tempData.value.datasets[0].data = props.objChartData.data1
- //tempData.value.datasets[1].data = props.objChartData.data2
-
- return tempData.value
- })
- </script>
|