프로젝트 타임라인을 시각화하면 팀이 정렬되고 마감일을 맞출 수 있습니다. Conholdate.Total for Java는 몇 줄의 코드만으로 Java에서 간트 차트를 쉽게 만들 수 있는 강력한 SDK를 제공합니다. 이 가이드에서는 라이브러리를 설정하고, 워크시트에 작업 데이터를 채우고, 누적 막대 차트를 간트 스타일 타임라인으로 변환하고, 결과를 Excel로 내보내는 방법을 보여줍니다.

Conholdate.Total for Java 설정

코딩을 시작하기 전에 Java 17 이상 및 Maven 호환 IDE가 설치되어 있는지 확인하십시오. Conholdate Maven 저장소와 SDK 종속성을 pom.xml에 추가하십시오:

<repositories>
    <repository>
        <id>conholdate-repo</id>
        <name>Conholdate Maven Repository</name>
        <url>https://repository.conholdate.com/repo/</url>
    </repository>
</repositories>
<dependency>
    <groupId>com.conholdate</groupId>
    <artifactId>conholdate-total</artifactId>
    <version>24.9</version>
    <type>pom</type>
</dependency>

최신 JAR 파일은 다운로드 페이지에서 직접 다운로드할 수 있습니다. SDK가 클래스패스에 추가되면 차트 작성을 시작할 준비가 된 것입니다.

단계별 구축: Java에서 간트 차트 만들기

1단계: 워크북을 만들고 작업 데이터를 채우기

이와 같이 만든 Gantt 차트는 실제로 워크시트 데이터 위에 겹쳐진 스택형 막대 차트이며, 따라서 첫 번째 단계는 Workbook을 생성하고 첫 번째 Worksheet를 가져온 다음 차트가 읽을 작업 이름, 시작 오프셋 및 기간을 채우는 것입니다.

com.aspose.cells.Workbook workbook = new com.aspose.cells.Workbook();
com.aspose.cells.Worksheet sheet = workbook.getWorksheets().get(0);

com.aspose.cells.Cells cells = sheet.getCells();
cells.get("A1").putValue("Task");
cells.get("C1").putValue("Duration (Days)");
cells.get("D1").putValue("Start Offset (Days)");

cells.get("A2").putValue("Requirement Analysis");
cells.get("C2").putValue(5);
cells.get("D2").putValue(0);

cells.get("A3").putValue("Design");
cells.get("C3").putValue(7);
cells.get("D3").putValue(5);

cells.get("A4").putValue("Implementation");
cells.get("C4").putValue(24);
cells.get("D4").putValue(12);

cells.get("A5").putValue("Testing");
cells.get("C5").putValue(15);
cells.get("D5").putValue(36);

cells.get("A6").putValue("Deployment");
cells.get("C6").putValue(2);
cells.get("D6").putValue(51);

Column A는 작업 이름을 보관하고, 열 C는 각 작업이 걸리는 일수를 보관하며, 열 D는 프로젝트 시작 후 각 작업이 시작되는 일수를 보관합니다. 차트의 두 시리즈(시작 오프셋 및 기간)는 열 D와 C에서 직접 읽어옵니다.

2단계: 누적 막대 차트 추가 및 시리즈 구성

데이터가 준비되면 워크시트에 BAR_STACKED 차트를 추가하고 해당 시리즈를 연결합니다. 시작 오프셋 시리즈는 각 작업 막대를 오른쪽으로 이동시키고, 지속 시간 시리즈는 그 위에 보이는 작업 막대를 그립니다.

int chartIndex = sheet.getCharts().add(com.aspose.cells.ChartType.BAR_STACKED, 7, 0, 30, 10);
com.aspose.cells.Chart chart = sheet.getCharts().get(chartIndex);
chart.getTitle().setText("Gantt Chart");

// Add offset and duration as series
chart.getNSeries().add("D2:D6", true); // Start Offset
chart.getNSeries().add("C2:C6", true); // Duration

// Set task names as categories
chart.getNSeries().setCategoryData("A2:A6");

차트는 워크시트의 7번째 행, 0번째 열에 고정되어 있으며, 30행 10열에 걸쳐 있습니다.

3단계: 차트를 간트 차트처럼 보이게 스타일링

스택형 막대 차트를 간트 차트처럼 읽게 하는 요령은 오프셋 시리즈를 보이지 않게 만들어서 지속 시간 막대만 표시되도록 하고, 올바른 시작 위치에 떠 있도록 하는 것입니다.

// Make offset bars invisible
chart.getNSeries().get(0).getArea().setFormatting(com.aspose.cells.FormattingType.NONE);

// Style duration bars
chart.getNSeries().get(1).getArea().setFormatting(com.aspose.cells.FormattingType.CUSTOM);
chart.getNSeries().get(1).getArea().setForegroundColor(com.aspose.cells.Color.getSteelBlue());
chart.getNSeries().get(1).getDataLabels().setShowValue(true);

4단계: 축, 범례 및 크기 구성

카테고리 축을 반전시켜 첫 번째 작업이 위에 표시되도록 하고, 두 축에 레이블을 지정한 다음, 의미 있는 시리즈가 하나뿐이므로 범례를 끕니다.

// Axis settings
chart.getCategoryAxis().setPlotOrderReversed(true);
chart.getCategoryAxis().getTitle().setText("Tasks");
chart.getValueAxis().getTitle().setText("Days from Start");
chart.getValueAxis().getMajorGridLines().setVisible(true);

// Hide legend
chart.setShowLegend(false);

// Resize chart
chart.getChartObject().setWidth(700);
chart.getChartObject().setHeight(400);

5단계: 워크북 저장

마지막으로, 워크북을 저장합니다. SDK는 XLSX, XLS 및 SaveFormat 열거형에 나열된 기타 형식을 지원합니다.

// Save the result
workbook.save("GanttChartResult.xlsx", com.aspose.cells.SaveFormat.XLSX);

Excel(또는 호환되는 스프레드시트 앱)에서 GanttChartResult.xlsx 파일을 열어 워크시트에 삽입된 완성된 간트 차트를 확인하세요.

전체 코드 예제: Gantt 차트 Java 예제

다음 예제는 Java에서 시작부터 끝까지 Gantt 차트를 만드는 방법을 보여줍니다.

public class GanttChartDemo {
    public static void main(String[] args) {
        // Create the workbook and get the first worksheet
        com.aspose.cells.Workbook workbook = new com.aspose.cells.Workbook();
        com.aspose.cells.Worksheet sheet = workbook.getWorksheets().get(0);

// Populate task names, durations, and start offsets
        com.aspose.cells.Cells cells = sheet.getCells();
        cells.get("A1").putValue("Task");
        cells.get("C1").putValue("Duration (Days)");
        cells.get("D1").putValue("Start Offset (Days)");

cells.get("A2").putValue("Requirement Analysis");
        cells.get("C2").putValue(5);
        cells.get("D2").putValue(0);

cells.get("A3").putValue("Design");
        cells.get("C3").putValue(7);
        cells.get("D3").putValue(5);

cells.get("A4").putValue("Implementation");
        cells.get("C4").putValue(24);
        cells.get("D4").putValue(12);

cells.get("A5").putValue("Testing");
        cells.get("C5").putValue(15);
        cells.get("D5").putValue(36);

cells.get("A6").putValue("Deployment");
        cells.get("C6").putValue(2);
        cells.get("D6").putValue(51);

// Add a stacked bar chart that will act as the Gantt chart
        int chartIndex = sheet.getCharts().add(com.aspose.cells.ChartType.BAR_STACKED, 7, 0, 30, 10);
        com.aspose.cells.Chart chart = sheet.getCharts().get(chartIndex);
        chart.getTitle().setText("Gantt Chart");

// Add offset and duration as series
        chart.getNSeries().add("D2:D6", true); // Start Offset
        chart.getNSeries().add("C2:C6", true); // Duration

// Set task names as categories
        chart.getNSeries().setCategoryData("A2:A6");

// Make offset bars invisible
        chart.getNSeries().get(0).getArea().setFormatting(com.aspose.cells.FormattingType.NONE);

// Style duration bars
        chart.getNSeries().get(1).getArea().setFormatting(com.aspose.cells.FormattingType.CUSTOM);
        chart.getNSeries().get(1).getArea().setForegroundColor(com.aspose.cells.Color.getSteelBlue());
        chart.getNSeries().get(1).getDataLabels().setShowValue(true);

// Axis settings
        chart.getCategoryAxis().setPlotOrderReversed(true);
        chart.getCategoryAxis().getTitle().setText("Tasks");
        chart.getValueAxis().getTitle().setText("Days from Start");
        chart.getValueAxis().getMajorGridLines().setVisible(true);

// Hide legend
        chart.setShowLegend(false);

// Resize chart
        chart.getChartObject().setWidth(700);
        chart.getChartObject().setHeight(400);

// Save the result
        workbook.save("GanttChartResult.xlsx", com.aspose.cells.SaveFormat.XLSX);
    }
}

참고: 이 코드 예제는 핵심 기능을 보여줍니다. 프로젝트에서 사용하기 전에 파일 경로와 구성 값을 실제 환경에 맞게 업데이트하고, 모든 필수 종속성이 올바르게 설치되었는지 확인하며, 개발 환경에서 충분히 테스트하십시오. 문제가 발생하면 공식 문서를 참조하거나 지원 팀에 문의하십시오.

결론

Java에서 Gantt 차트를 만드는 것은 Conholdate.Total for Java를 사용하면 간단합니다. 작업 데이터를 워크시트에 채우고, 스택형 막대 차트를 추가한 다음, 시리즈와 축을 스타일링하면 Excel 파일 내부에 바로 표시되는 전문가 수준의 타임라인을 생성할 수 있습니다. 시작 오프셋 시리즈를 숨기고 기간 시리즈를 스타일링하는 것이 일반 스택형 막대 차트를 Gantt 차트로 변환하는 핵심 기술입니다. 상용 라이선스가 프로덕션 배포에 필요함을 기억하세요; 임시 라이선스는 임시 라이선스 페이지에서 얻을 수 있으며, 가격 세부 정보는 가격 페이지에서 확인하세요. 오늘 바로 애플리케이션에 Gantt 차트를 통합하고 이해관계자에게 명확한 시각적 일정으로 정보를 제공하세요.

자주 묻는 질문

How do I create Gantt Chart in Java using Conholdate.Total?
Workbook을 생성하고, 워크시트에 BAR_STACKED 차트를 추가한 다음 두 개의 시리즈를 추가합니다: 숨겨진 시작 오프셋 시리즈와 표시되는 기간 시리즈. 작업 이름을 범주 데이터로 설정하고, 표시되는 시리즈의 스타일을 지정한 후 워크북을 저장합니다. 전체 코드 스니펫은 이 문서에 제공됩니다.

Excel 외의 형식으로 Gantt 차트를 내보낼 수 있나요?
예. 차트가 워크북에 포함되어 있기 때문에 SaveFormat 열거형의 값 중 XLSX, XLS, ODS와 같이 원하는 형식을 사용하여 파일을 저장할 수 있습니다. 전체 목록은 공식 문서를 참조하십시오.

프로덕션 사용에 필요한 라이선스는 무엇인가요?
상업용 라이선스가 필수입니다. 임시 라이선스를 임시 라이선스 페이지에서 요청하고, 가격 페이지에서 가격을 확인하세요.

대형 간트 차트의 성능을 어떻게 개선할 수 있나요?
각 시리즈가 참조하는 데이터 범위를 가능한 한 좁게 유지하고, 불필요한 워크북 재계산을 피하며, 실제로 필요한 시리즈와 축에만 서식 호출을 제한하세요. 차트당 작업 수를 적절히 유지하면 대형 프로젝트 파일에서도 렌더링 속도가 빨라집니다.

자세히 보기