안녕하세요
실무에서 데이의 스펙들을 조회하고 값으로 차트를 만들고있습니다
항목이 많아 슬라이서를 추가해서 보는데
데이터 항목마다 스펙과 깂이제각각이라
차트의 축을 고정하지는 못하고 자동으로 보고있습니다
예로 항목 1,2의 스펙이 40~50으로 동일한 경우는
표에서 보이는 축이 동일해야 맞다고 생각되는데
항목 1은 축 값이 30 ~ 60으로 보기 편하게 보이는 반면
항목 2는 축값이 0 ~ 80으로 데이터가 납작하게 보이는데 원인을 모르겠습니다
이 뿐만 아니라 어떤 항목들은 예시 항목 1처럼 보기 좋게 차트기 나오는데
어떤 항목들은 보기가 불편하게 나옵니다
해결 방법 있을까요?
커뮤니티 전체
데이터, 차트의 축
📅 2025년 09월 22일 03:40
👁 조회 238
댓글을 작성하려면 로그인이 필요합니다.
게시글 목록
페이지 1 / 970게시글 제목
날짜
조회
추천
12시간 전
조회 57
0
답글 1
2일 전
조회 172
0
답글 7
2일 전
조회 113
0
답글 2
3일 전
조회 183
0
답글 1
3일 전
조회 171
0
답글 7
4일 전
조회 211
0
답글 3
해결
4일 전
조회 155
0
답글 1
4일 전
조회 187
0
답글 1
4일 전
조회 182
0
답글 6
해결
4일 전
조회 183
0
답글 2
5일 전
조회 264
0
답글 3
답변 완료
시트 복사했는데 에러가 나요ㅠㅠ
5일 전
조회 212
0
답글 8
해결
답변 완료
소수점 합계값 오류
5일 전
조회 190
0
답글 2
해결
답변 완료
날짜순대로 정렬하기
6일 전
조회 248
0
답글 3
해결
6일 전
조회 224
0
답글 1
6일 전
조회 202
0
답글 3
해결
6일 전
조회 281
0
답글 6
6일 전
조회 231
0
답글 4
2026.02.02
조회 246
0
답글 0
2026.02.01
조회 187
0
답글 2

차트에 사용되는 최소/최대값이나 데이터 전체 구간에 따라 매번 다르게 설정되니 편할때도 있고 불편할 때도 있는데, 만약 자동으로 설정돼서 불편하다면 축 서식에서 최소/최대를 직접 정하거는 방법(예상된 구간 안에서 변할 경우), VBA로 최소/최대 값 +/- n%의 축이 설정되도록 하는 방법이 있습니다.
말씀하신 상황 0~80으로 데이터가 납작하게 보인다면 구간을 0~20 정도로 최대값을 낮춰서 고정 구간으로 설정하는 것도 하나의 방법이 되겠습니다.
축 옵션에 대한 위 댓글의 좋은 설명을 참조하시고,
VBA로 코딩한 차트 활용을 한번 활용해 보세요~
매크로 파일에 대한 기본 설정은 첨부파일 다운 후,
1. 파일 → 마우스 오른쪽 클릭 → 속성 → “차단 해제” 체크 후 [확인]
2. Excel → [파일] → [옵션] → [보안 센터] → [보안 센터 설정] → "모든 매크로 사용"
Option Explicit Public Sub 차트생성() '// ---------------- 시트/마지막행 ---------------- Dim ws As Worksheet: Set ws = ActiveSheet Dim eRow As Long: eRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row If eRow < 2 Then MsgBox "데이터가 없습니다.", vbExclamation: Exit Sub '// ---------------- 기준 선택 ---------------- Dim rngSel As Range, 기준 As String, useAmt As Boolean On Error Resume Next Set rngSel = Application.InputBox( _ Prompt:="C1=판매량, D1=총판매금액 중 하나의 셀을 클릭하세요", _ Title:="기준 선택", Type:=8) On Error GoTo 0 If rngSel Is Nothing Then Exit Sub If Not Application.Intersect(rngSel, ws.Range("C1")) Is Nothing Then 기준 = "판매량": useAmt = False ElseIf Not Application.Intersect(rngSel, ws.Range("D1")) Is Nothing Then 기준 = "총판매금액": useAmt = True Else MsgBox "반드시 C1 또는 D1 셀을 선택해야 합니다.", vbExclamation Exit Sub End If '// 기준 선택에서 사용할 열 번호 결정 Dim mCol As Long If useAmt Then mCol = 4 '// 총판매금액: D열 Else mCol = 3 '// 판매량: C열 End If '// ---------------- 지점 범위(비연속 허용) 선택 ---------------- Dim rSel As Range On Error Resume Next Set rSel = Application.InputBox( _ Prompt:="지점명이 들어있는 셀 범위를 선택하세요." & vbCrLf & _ "Ctrl 키를 누른 채로 여러 범위를 클릭/드래그하면 다중 선택됩니다.", _ Title:="지점 다중 선택(비연속 허용)", Type:=8) On Error GoTo 0 If rSel Is Nothing Then Exit Sub '// ---------------- 선택범위 → 지점 고유목록 ---------------- Dim dBr As Object: Set dBr = CreateObject("Scripting.Dictionary") Dim ar As Range, c As Range, br As String For Each ar In rSel.Areas For Each c In ar.Cells br = Trim$(CStr(c.Value)) If Len(br) > 0 Then dBr(br) = 1 Next c Next ar If dBr.Count = 0 Then MsgBox "선택 범위에 지점명이 없습니다.", vbExclamation: Exit Sub '// ---------------- 원본에 실제 존재하는 지점만 남기기 ---------------- Dim dExist As Object: Set dExist = CreateObject("Scripting.Dictionary") Dim i As Long For i = 2 To eRow br = CStr(ws.Cells(i, 1).Value) If Len(br) > 0 Then dExist(br) = 1 Next Dim brs() As String, nBr As Long, k As Variant ReDim brs(1 To dBr.Count) For Each k In dBr.Keys If dExist.Exists(k) Then nBr = nBr + 1 brs(nBr) = CStr(k) End If Next If nBr = 0 Then MsgBox "선택한 지점이 원본 데이터에 없습니다.", vbExclamation: Exit Sub ReDim Preserve brs(1 To nBr) '// ---------------- 축 최소/최대 입력 ---------------- Dim tMin As String, tMax As String, minAuto As Boolean, maxAuto As Boolean Dim vMin As Double, vMax As Double tMin = Application.InputBox("Y축 최소값 (빈칸 또는 'auto' = 자동)", "축 최소값", Type:=2) tMax = Application.InputBox("Y축 최대값 (빈칸 또는 'auto' = 자동)", "축 최대값", Type:=2) minAuto = (Len(Trim$(tMin)) = 0 Or LCase$(Trim$(tMin)) = "auto") maxAuto = (Len(Trim$(tMax)) = 0 Or LCase$(Trim$(tMax)) = "auto") If Not minAuto Then If Not IsNumeric(tMin) Then MsgBox "최소값이 숫자가 아닙니다.", vbExclamation: Exit Sub vMin = CDbl(tMin) End If If Not maxAuto Then If Not IsNumeric(tMax) Then MsgBox "최대값이 숫자가 아닙니다.", vbExclamation: Exit Sub vMax = CDbl(tMax) End If If (Not minAuto And Not maxAuto) Then If vMax <= vMin Then MsgBox "최대값은 최소값보다 커야 합니다.", vbExclamation: Exit Sub End If '// ---------------- 차트 모드 선택: 0=개별차트, 1=전체차트 ---------------- Dim modeSel As Variant, isCombined As Boolean, modeVal As Long modeSel = Application.InputBox("차트 모드 선택: 0=개별차트, 1=전체차트", "차트 모드", 1, Type:=1) '// 취소 시 종료 If VarType(modeSel) = vbBoolean Then Exit Sub '// 숫자 보장 및 검증 modeVal = CLng(modeSel) If modeVal <> 0 And modeVal <> 1 Then MsgBox "0 또는 1만 입력하세요.", vbExclamation: Exit Sub End If isCombined = (modeVal = 1) '// ===== 성능옵션 ===== Dim sc As Boolean, ev As Boolean, calc As XlCalculation sc = Application.ScreenUpdating ev = Application.EnableEvents calc = Application.Calculation Application.ScreenUpdating = False Application.EnableEvents = False Application.Calculation = xlCalculationManual On Error GoTo XIT '// ---------------- 카테고리(모델) 목록: 등장순 유지 ---------------- Dim dItm As Object: Set dItm = CreateObject("Scripting.Dictionary") Dim itm As String For i = 2 To eRow If InArray(CStr(ws.Cells(i, 1).Value), brs) Then itm = CStr(ws.Cells(i, 2).Value) If Len(itm) > 0 Then If Not dItm.Exists(itm) Then dItm.Add itm, dItm.Count + 1 End If End If Next If dItm.Count = 0 Then MsgBox "선택 지점에 해당하는 항목이 없습니다.", vbExclamation: GoTo XIT Dim cats() As String, nCat As Long: nCat = dItm.Count ReDim cats(1 To nCat) For Each k In dItm.Keys cats(dItm(k)) = CStr(k) Next '// ---------------- 값 배열 구성 (지점 r, 항목 j) ---------------- Dim vals() As Variant, r As Long, j As Long, v As Variant ReDim vals(1 To nBr, 1 To nCat) For r = 1 To nBr For j = 1 To nCat: vals(r, j) = 0: Next j Next r For i = 2 To eRow br = CStr(ws.Cells(i, 1).Value) If InArray(br, brs) Then itm = CStr(ws.Cells(i, 2).Value) If dItm.Exists(itm) Then j = dItm(itm) r = FindIndex(brs, br) If r > 0 Then v = ws.Cells(i, mCol).Value '// 선택 열 원값 그대로 If IsNumeric(v) And Len(v) > 0 Then vals(r, j) = CDbl(v) '// 덮어쓰기 Else vals(r, j) = 0 End If End If End If End If Next i If isCombined Then '// ========== 전체차트(한 개) ========== Const CH_NAME As String = "매장차트" Dim co As ChartObject, ch As Chart On Error Resume Next Set co = ws.ChartObjects(CH_NAME) On Error GoTo XIT If co Is Nothing Then Set co = ws.ChartObjects.Add(Left:=400, Top:=60, Width:=820, Height:=380) co.Name = CH_NAME End If Set ch = co.Chart ch.ChartType = xlColumnClustered Do While ch.SeriesCollection.Count > 0 ch.SeriesCollection(1).Delete Loop For r = 1 To nBr With ch.SeriesCollection.NewSeries .Name = brs(r) .XValues = cats .Values = Application.Index(vals, r, 0) End With Next r ch.HasTitle = True ch.ChartTitle.Text = "지점별 " & 기준 & " 비교" With ch.Axes(xlValue) If minAuto Then .MinimumScaleIsAuto = True Else .MinimumScaleIsAuto = False: .MinimumScale = vMin If maxAuto Then .MaximumScaleIsAuto = True Else .MaximumScaleIsAuto = False: .MaximumScale = vMax .MajorGridlines.Format.Line.Visible = msoTrue If useAmt Then .TickLabels.NumberFormat = "\#,##0" Else .TickLabels.NumberFormat = "#,##0" End With Else '// ========== 개별차트(지점마다 1개씩) ========== Dim perW As Double, perH As Double, padX As Double, padY As Double Dim colCnt As Long, rIdx As Long, cIdx As Long Dim nameOne As String, co1 As ChartObject, ch1 As Chart '// 루프 밖으로 이동 perW = 380: perH = 300 '// 차트 크기 padX = 20: padY = 20 '// 간격 colCnt = 2 '// 한 줄에 2개 배치 (원하면 3으로 변경) For r = 1 To nBr nameOne = "매장차트_" & brs(r) Set co1 = Nothing '// 변수 초기화 Set ch1 = Nothing '// 변수 초기화 On Error Resume Next Set co1 = ws.ChartObjects(nameOne) On Error GoTo 0 If co1 Is Nothing Then Set co1 = ws.ChartObjects.Add(Left:=0, Top:=0, Width:=perW, Height:=perH) co1.Name = nameOne Else co1.Width = perW: co1.Height = perH End If Set ch1 = co1.Chart '// Chart 객체를 설정 '// 배치 rIdx = (r - 1) \ colCnt cIdx = (r - 1) Mod colCnt co1.Left = 20 + cIdx * (perW + padX) '// 시작 위치를 살짝 왼쪽으로 (겹침 방지) co1.Top = 60 + rIdx * (perH + padY) ws.Shapes(co1.Name).ZOrder 0 '// 차트 타입 설정 ch1.ChartType = xlColumnClustered '// 기존 시리즈 삭제 Do While ch1.SeriesCollection.Count > 0 ch1.SeriesCollection(1).Delete Loop With ch1.SeriesCollection.NewSeries .Name = brs(r) .XValues = cats .Values = Application.Index(vals, r, 0) End With ch1.HasTitle = True ch1.ChartTitle.Text = brs(r) & " - " & 기준 With ch1.Axes(xlValue) If minAuto Then .MinimumScaleIsAuto = True Else .MinimumScaleIsAuto = False: .MinimumScale = vMin If maxAuto Then .MaximumScaleIsAuto = True Else .MaximumScaleIsAuto = False: .MaximumScale = vMax .MajorGridlines.Format.Line.Visible = msoTrue If useAmt Then .TickLabels.NumberFormat = "\#,##0" Else .TickLabels.NumberFormat = "#,##0" End With Next r End If MsgBox IIf(isCombined, "전체차트 1개 생성/갱신 완료.", "개별차트 " & nBr & "개 생성/갱신 완료.") & vbCrLf & _ "기준: " & 기준 & vbCrLf & _ "Y축 최소: " & IIf(minAuto, "자동", CStr(vMin)) & ", 최대: " & IIf(maxAuto, "자동", CStr(vMax)), vbInformation XIT: On Error Resume Next Application.ScreenUpdating = sc Application.EnableEvents = ev Application.Calculation = calc End Sub '// --------- 유틸 ---------- Private Function InArray(ByVal s As String, a() As String) As Boolean Dim i As Long For i = LBound(a) To UBound(a) If s = a(i) Then InArray = True: Exit Function Next End Function Private Function FindIndex(a() As String, ByVal s As String) As Long Dim i As Long For i = LBound(a) To UBound(a) If a(i) = s Then FindIndex = i: Exit Function Next End Function