Android에서 PowerPoint 프레젠테이션 차트 만들기 또는 업데이트
개요
이 문서에서는 Aspose.Slides for Android via Java를 사용하여 차트를 만들고 사용자 지정하는 포괄적인 가이드를 제공합니다. 프로그래밍 방식으로 슬라이드에 차트를 추가하고 데이터를 채우며 특정 디자인 요구 사항에 맞게 다양한 형식 옵션을 적용하는 방법을 배울 수 있습니다. 문서 전반에 걸쳐 자세한 코드 예제가 각 단계를 설명합니다. 프레젠테이션 및 차트 개체 초기화부터 시리즈, 축, 범례 구성까지. 이 가이드를 따르면 Android 애플리케이션에 동적 차트 생성을 통합하는 방법을 확실히 이해하게 되어 데이터 기반 프레젠테이션을 만드는 과정을 간소화할 수 있습니다.
차트 만들기
차트는 사용자가 데이터를 빠르게 시각화하고 표나 스프레드시트에서 바로 알기 어려운 인사이트를 얻을 수 있도록 돕습니다.
왜 차트를 만들까요?
- 프레젠테이션의 하나의 슬라이드에 대량의 데이터를 집계, 압축 또는 요약합니다;
- 데이터의 패턴과 추세를 드러냅니다;
- 시간에 따른 또는 특정 측정 단위와 관련된 데이터의 방향과 모멘텀을 추론합니다;
- 이상값, 변칙, 편차, 오류 및 비논리적인 데이터를 식별합니다;
- 복잡한 데이터를 전달하거나 프레젠테이션합니다.
PowerPoint에서는 삽입 기능을 통해 차트를 만들 수 있으며, 다양한 차트 유형을 설계할 수 있는 템플릿을 제공합니다. Aspose.Slides를 사용하면 일반 차트(인기 차트 유형 기반)와 사용자 정의 차트를 모두 만들 수 있습니다.
군집 컬럼 차트 만들기
이 예제는 addChart을 사용하여 세 개의 카테고리에서 두 개의 시리즈를 비교하는 군집 컬럼 차트를 만듭니다. 시리즈는 빨간색 및 녹색 채우기를 사용하고, 개별 레이블은 카테고리 이름, 시리즈 이름 및 값을 표시합니다. 워크시트 인덱스 0은 포함된 차트 워크북의 첫 번째 시트를 나타냅니다.
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try
{
ISlide slide = presentation.getSlides().get_Item(0);
IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 20, 20, 500, 300);
chart.getChartTitle().addTextFrameForOverriding("Sample Title");
chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat().setCenterText(NullableBool.True);
chart.getChartTitle().setHeight(20);
chart.setTitle(true);
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
int worksheetIndex = 0;
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
IChartDataCell seriesNameCell = workbook.getCell(worksheetIndex, 0, 1, "Series 1");
chart.getChartData().getSeries().add(seriesNameCell, chart.getType());
seriesNameCell = workbook.getCell(worksheetIndex, 0, 2, "Series 2");
chart.getChartData().getSeries().add(seriesNameCell, chart.getType());
IChartDataCell categoryCell = workbook.getCell(worksheetIndex, 1, 0, "Category 1");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(worksheetIndex, 2, 0, "Category 2");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(worksheetIndex, 3, 0, "Category 3");
chart.getChartData().getCategories().add(categoryCell);
IChartSeries series = chart.getChartData().getSeries().get_Item(0);
IChartDataCell valueCell = workbook.getCell(worksheetIndex, 1, 1, 20);
series.getDataPoints().addDataPointForBarSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, 2, 1, 50);
series.getDataPoints().addDataPointForBarSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, 3, 1, 30);
series.getDataPoints().addDataPointForBarSeries(valueCell);
series.getFormat().getFill().setFillType(FillType.Solid);
series.getFormat().getFill().getSolidFillColor().setColor(Color.RED);
series = chart.getChartData().getSeries().get_Item(1);
valueCell = workbook.getCell(worksheetIndex, 1, 2, 30);
series.getDataPoints().addDataPointForBarSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, 2, 2, 10);
series.getDataPoints().addDataPointForBarSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, 3, 2, 60);
series.getDataPoints().addDataPointForBarSeries(valueCell);
series.getFormat().getFill().setFillType(FillType.Solid);
series.getFormat().getFill().getSolidFillColor().setColor(Color.rgb(0, 128, 0));
IDataLabel label = series.getDataPoints().get_Item(0).getLabel();
label.getDataLabelFormat().setShowCategoryName(true);
label = series.getDataPoints().get_Item(1).getLabel();
label.getDataLabelFormat().setShowSeriesName(true);
label = series.getDataPoints().get_Item(2).getLabel();
label.getDataLabelFormat().setShowValue(true);
label.getDataLabelFormat().setShowSeriesName(true);
label.getDataLabelFormat().setSeparator("/");
presentation.save("AsposeChart.pptx", SaveFormat.Pptx);
}
finally
{
presentation.dispose();
}
결과:

산점도 차트 만들기
산점도 차트(산점도 플롯 또는 x‑y 그래프라고도 함)는 두 변수 간의 패턴을 확인하거나 상관 관계를 보여줄 때 자주 사용됩니다.
산점도 차트를 사용할 때:
- 쌍을 이루는 숫자 데이터가 있습니다;
- 서로 잘 짝을 이루는 두 변수가 있습니다;
- 두 변수가 연관되어 있는지 판단하고 싶습니다;
- 종속 변수에 대해 여러 값을 갖는 독립 변수가 있습니다.
이 예제는 두 개의 x‑y 값 세트를 플롯합니다. 첫 번째 시리즈는 별 마커가 있는 직선, 두 번째는 원 마커가 있는 부드러운 선을 사용합니다; 두 시리즈 모두 마커 크기를 10으로 설정하고 setSize으로 구성됩니다. setSymbol 메서드는 마커 모양을 제어합니다.
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try
{
ISlide slide = presentation.getSlides().get_Item(0);
IChart chart = slide.getShapes().addChart(ChartType.ScatterWithSmoothLines, 20, 20, 500, 300);
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
int worksheetIndex = 0;
chart.getChartData().getSeries().clear();
IChartDataCell seriesNameCell = workbook.getCell(worksheetIndex, 1, 1, "Series 1");
chart.getChartData().getSeries().add(seriesNameCell, chart.getType());
seriesNameCell = workbook.getCell(worksheetIndex, 1, 3, "Series 2");
chart.getChartData().getSeries().add(seriesNameCell, chart.getType());
IChartSeries series = chart.getChartData().getSeries().get_Item(0);
IChartDataCell xValueCell = workbook.getCell(worksheetIndex, 2, 1, 1);
IChartDataCell yValueCell = workbook.getCell(worksheetIndex, 2, 2, 3);
series.getDataPoints().addDataPointForScatterSeries(xValueCell, yValueCell);
xValueCell = workbook.getCell(worksheetIndex, 3, 1, 2);
yValueCell = workbook.getCell(worksheetIndex, 3, 2, 10);
series.getDataPoints().addDataPointForScatterSeries(xValueCell, yValueCell);
series.setType(ChartType.ScatterWithStraightLinesAndMarkers);
series.getMarker().setSize(10);
series.getMarker().setSymbol(MarkerStyleType.Star);
series = chart.getChartData().getSeries().get_Item(1);
xValueCell = workbook.getCell(worksheetIndex, 2, 3, 5);
yValueCell = workbook.getCell(worksheetIndex, 2, 4, 2);
series.getDataPoints().addDataPointForScatterSeries(xValueCell, yValueCell);
xValueCell = workbook.getCell(worksheetIndex, 3, 3, 3);
yValueCell = workbook.getCell(worksheetIndex, 3, 4, 1);
series.getDataPoints().addDataPointForScatterSeries(xValueCell, yValueCell);
xValueCell = workbook.getCell(worksheetIndex, 4, 3, 2);
yValueCell = workbook.getCell(worksheetIndex, 4, 4, 2);
series.getDataPoints().addDataPointForScatterSeries(xValueCell, yValueCell);
xValueCell = workbook.getCell(worksheetIndex, 5, 3, 5);
yValueCell = workbook.getCell(worksheetIndex, 5, 4, 1);
series.getDataPoints().addDataPointForScatterSeries(xValueCell, yValueCell);
series.getMarker().setSize(10);
series.getMarker().setSymbol(MarkerStyleType.Circle);
presentation.save("AsposeChart.pptx", SaveFormat.Pptx);
}
finally
{
presentation.dispose();
}
결과:

원형 차트 만들기
원형 차트는 데이터의 부분‑전체 관계를 보여줄 때 가장 적합합니다. 특히 데이터에 카테고리 레이블과 수치 값이 포함된 경우에 유용합니다. 그러나 데이터에 많은 부분이나 레이블이 포함된 경우에는 막대 차트를 고려하는 것이 좋습니다.
이 예제는 세 개의 분기값으로 원형 차트를 만듭니다. 각 조각은 사용자 지정 채우기와 테두리를 가지고 있으며, 레이블은 값, 백분율 및 시리즈 정보를 조합해서 표시합니다. setFirstSliceAngle 메서드는 첫 조각을 180도에서 시작하도록 설정합니다.
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try
{
ISlide slide = presentation.getSlides().get_Item(0);
IChart chart = slide.getShapes().addChart(ChartType.Pie, 20, 20, 500, 300);
chart.getChartTitle().addTextFrameForOverriding("Sample Title");
chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat().setCenterText(NullableBool.True);
chart.getChartTitle().setHeight(20);
chart.setTitle(true);
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true);
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
int worksheetIndex = 0;
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
IChartDataCell categoryCell = workbook.getCell(0, 1, 0, "1st Qtr");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(0, 2, 0, "2nd Qtr");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(0, 3, 0, "3rd Qtr");
chart.getChartData().getCategories().add(categoryCell);
IChartDataCell seriesNameCell = workbook.getCell(0, 0, 1, "Series 1");
IChartSeries series = chart.getChartData().getSeries().add(seriesNameCell, chart.getType());
IChartDataCell valueCell = workbook.getCell(worksheetIndex, 1, 1, 20);
series.getDataPoints().addDataPointForPieSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, 2, 1, 50);
series.getDataPoints().addDataPointForPieSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, 3, 1, 30);
series.getDataPoints().addDataPointForPieSeries(valueCell);
chart.getChartData().getSeriesGroups().get_Item(0).setColorVaried(true);
IChartDataPoint firstSlice = series.getDataPoints().get_Item(0);
firstSlice.getFormat().getFill().setFillType(FillType.Solid);
firstSlice.getFormat().getFill().getSolidFillColor().setColor(Color.CYAN);
firstSlice.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
firstSlice.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.rgb(128, 128, 128));
firstSlice.getFormat().getLine().setWidth(3.0);
firstSlice.getFormat().getLine().setStyle(LineStyle.ThinThick);
firstSlice.getFormat().getLine().setDashStyle(LineDashStyle.LargeDash);
IChartDataPoint secondSlice = series.getDataPoints().get_Item(1);
secondSlice.getFormat().getFill().setFillType(FillType.Solid);
secondSlice.getFormat().getFill().getSolidFillColor().setColor(Color.rgb(165, 42, 42));
secondSlice.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
secondSlice.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
secondSlice.getFormat().getLine().setWidth(3.0);
secondSlice.getFormat().getLine().setStyle(LineStyle.Single);
secondSlice.getFormat().getLine().setDashStyle(LineDashStyle.LargeDashDot);
IChartDataPoint thirdSlice = series.getDataPoints().get_Item(2);
thirdSlice.getFormat().getFill().setFillType(FillType.Solid);
thirdSlice.getFormat().getFill().getSolidFillColor().setColor(Color.rgb(255, 127, 80));
thirdSlice.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
thirdSlice.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.RED);
thirdSlice.getFormat().getLine().setWidth(2.0);
thirdSlice.getFormat().getLine().setStyle(LineStyle.ThinThin);
thirdSlice.getFormat().getLine().setDashStyle(LineDashStyle.LargeDashDotDot);
IDataLabel firstLabel = series.getDataPoints().get_Item(0).getLabel();
firstLabel.getDataLabelFormat().setShowValue(true);
IDataLabel secondLabel = series.getDataPoints().get_Item(1).getLabel();
secondLabel.getDataLabelFormat().setShowValue(true);
secondLabel.getDataLabelFormat().setShowLegendKey(true);
secondLabel.getDataLabelFormat().setShowPercentage(true);
IDataLabel thirdLabel = series.getDataPoints().get_Item(2).getLabel();
thirdLabel.getDataLabelFormat().setShowSeriesName(true);
thirdLabel.getDataLabelFormat().setShowPercentage(true);
series.getLabels().getDefaultDataLabelFormat().setShowLeaderLines(true);
chart.getChartData().getSeriesGroups().get_Item(0).setFirstSliceAngle(180);
presentation.save("PieChart.pptx", SaveFormat.Pptx);
}
finally
{
presentation.dispose();
}
결과:

라벨이 차트 외부에 표시될 때 가독성을 높이려면 형식 리더 라인 예제를 참조하여 레이블 위치 및 선 색상, 너비, 투명도, 대시 스타일을 지정하세요.
선 차트 만들기
선 차트(선 그래프라고도 함)는 시간에 따른 값 변화를 보여줄 때 가장 적합합니다. 선 차트를 사용하면 한 번에 많은 데이터를 비교하고, 시간에 따른 변화와 추세를 추적하며, 데이터 시리즈의 이상 현상을 강조 표시할 수 있습니다.
이 예제는 addChart을 사용하여 기본 시리즈와 카테고리로 선 차트를 만든 뒤 프레젠테이션을 PPTX로 저장합니다.
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try
{
ISlide slide = presentation.getSlides().get_Item(0);
IChart lineChart = slide.getShapes().addChart(ChartType.Line, 20, 20, 500, 300);
presentation.save("lineChart.pptx", SaveFormat.Pptx);
}
finally
{
presentation.dispose();
}
기본적으로 선 차트의 점은 직선으로 연결됩니다. 점을 대시로 연결하고 싶다면 setDashStyle에 LineDashStyle 중 하나의 값을 전달하세요:
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try
{
ISlide slide = presentation.getSlides().get_Item(0);
IChart lineChart = slide.getShapes().addChart(ChartType.Line, 20, 20, 500, 300);
for (IChartSeries series : lineChart.getChartData().getSeries())
{
series.getFormat().getLine().setDashStyle(LineDashStyle.Dash);
}
}
finally
{
presentation.dispose();
}
결과:

트리맵 차트 만들기
트리맵 차트는 판매 데이터 등에서 데이터 카테고리의 상대 크기를 보여주고 각 카테고리 내에서 큰 기여자를 빠르게 강조할 때 가장 적합합니다.
이 예제는 네 개의 줄기와 두 개의 가지로 구성된 여덟 개의 잎을 가진 트리맵을 만듭니다. setGroupingItem 메서드는 1단계에서 줄기를, 2단계에서 가지를 지정합니다. 값은 사각형 크기의 상대 비율을 결정하고, 카테고리 레이블과 겹치는 상위 레이블이 계층 구조를 식별합니다.
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try
{
ISlide slide = presentation.getSlides().get_Item(0);
IChart chart = slide.getShapes().addChart(ChartType.Treemap, 20, 20, 500, 300);
chart.getChartData().getCategories().clear();
chart.getChartData().getSeries().clear();
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
workbook.clear(0);
// 브랜치 1
IChartDataCell categoryCell = workbook.getCell(0, "C1", "Leaf1");
IChartCategory leaf = chart.getChartData().getCategories().add(categoryCell);
leaf.getGroupingLevels().setGroupingItem(1, "Stem1");
leaf.getGroupingLevels().setGroupingItem(2, "Branch1");
categoryCell = workbook.getCell(0, "C2", "Leaf2");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(0, "C3", "Leaf3");
leaf = chart.getChartData().getCategories().add(categoryCell);
leaf.getGroupingLevels().setGroupingItem(1, "Stem2");
categoryCell = workbook.getCell(0, "C4", "Leaf4");
chart.getChartData().getCategories().add(categoryCell);
// 브랜치 2
categoryCell = workbook.getCell(0, "C5", "Leaf5");
leaf = chart.getChartData().getCategories().add(categoryCell);
leaf.getGroupingLevels().setGroupingItem(1, "Stem3");
leaf.getGroupingLevels().setGroupingItem(2, "Branch2");
categoryCell = workbook.getCell(0, "C6", "Leaf6");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(0, "C7", "Leaf7");
leaf = chart.getChartData().getCategories().add(categoryCell);
leaf.getGroupingLevels().setGroupingItem(1, "Stem4");
categoryCell = workbook.getCell(0, "C8", "Leaf8");
chart.getChartData().getCategories().add(categoryCell);
IChartSeries series = chart.getChartData().getSeries().add(ChartType.Treemap);
series.getLabels().getDefaultDataLabelFormat().setShowCategoryName(true);
IChartDataCell valueCell = workbook.getCell(0, "D1", 4);
series.getDataPoints().addDataPointForTreemapSeries(valueCell);
valueCell = workbook.getCell(0, "D2", 5);
series.getDataPoints().addDataPointForTreemapSeries(valueCell);
valueCell = workbook.getCell(0, "D3", 3);
series.getDataPoints().addDataPointForTreemapSeries(valueCell);
valueCell = workbook.getCell(0, "D4", 6);
series.getDataPoints().addDataPointForTreemapSeries(valueCell);
valueCell = workbook.getCell(0, "D5", 9);
series.getDataPoints().addDataPointForTreemapSeries(valueCell);
valueCell = workbook.getCell(0, "D6", 9);
series.getDataPoints().addDataPointForTreemapSeries(valueCell);
valueCell = workbook.getCell(0, "D7", 4);
series.getDataPoints().addDataPointForTreemapSeries(valueCell);
valueCell = workbook.getCell(0, "D8", 3);
series.getDataPoints().addDataPointForTreemapSeries(valueCell);
series.setParentLabelLayout(ParentLabelLayoutType.Overlapping);
presentation.save("Treemap.pptx", SaveFormat.Pptx);
}
finally
{
presentation.dispose();
}
결과:

워터폴 차트 만들기
워터폴 차트는 양의 변화와 음의 변화가 최종값에 어떻게 기여하는지를 보여줍니다. 예를 들어, 수익에서 시작해 비용을 차감하고 기타 수입을 더하는 방식으로 이익을 분해할 수 있습니다. 변화 열은 이전 값과 새로운 누적 값 사이에 떠 있고, 총계 열은 0에서 누적 값까지 확장됩니다.
| 카테고리 | 워크북 값 | 열 유형 |
|---|---|---|
| Revenue | 1000 | 증가 |
| Cost of sales | -400 | 감소 |
| Gross profit | 600 | 중간 합계 |
| Operating expenses | -200 | 감소 |
| Other income | 50 | 증가 |
| Net profit | 450 | 최종 합계 |
점이 중간 또는 최종 합계로 표시되도록 하려면 해당 점의 setSetAsTotal 메서드를 true 로 호출합니다. 해당 점의 워크북 셀에 실제 누적 금액을 입력하십시오: 총이익은 600 (1000 - 400), 순이익은 450 (600 - 200 + 50). 이 메서드는 열을 합계로 표시하도록 지정하지만 셀 값을 계산하거나 채우지는 않습니다. 0을 자리표시자로 사용하거나 다른 변화를 합계 점에 제공하지 마세요. 합계 열은 누적 값을 다시 더하지 않고 표시합니다.
이 전체 Java 예제는 ChartType의 Waterfall 멤버를 사용해 차트를 만들고, 기본 데이터를 지운 뒤 포함된 워크북을 채웁니다. 워크시트 인덱스 0은 첫 번째 워크시트를 선택하고, A 열은 카테고리 이름, B 열은 값을 포함합니다. 각 값 셀은 addDataPointForWaterfallSeries 로 추가합니다. 0 기반 점 인덱스 2와 5는 각각 중간 및 최종 합계를 식별합니다. setShowValue 를 true 로 호출하면 값이 열에 표시됩니다. 별도의 입력 프레젠테이션이나 워크북은 필요하지 않습니다.
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try
{
ISlide slide = presentation.getSlides().get_Item(0);
IChart chart = slide.getShapes().addChart(ChartType.Waterfall, 20, 20, 680, 200);
chart.setTitle(true);
chart.getChartTitle().addTextFrameForOverriding("Profit breakdown (USD thousands)");
chart.getChartTitle().setOverlay(false);
chart.setLegend(false);
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
int worksheetIndex = 0;
workbook.clear(worksheetIndex);
IChartDataCell seriesNameCell = workbook.getCell(worksheetIndex, 0, 1, "Profit");
IChartSeries series = chart.getChartData().getSeries().add(seriesNameCell, ChartType.Waterfall);
String[] categories = new String[] { "Revenue", "Cost of sales", "Gross profit", "Operating expenses", "Other income", "Net profit" };
double[] values = new double[] { 1000, -400, 600, -200, 50, 450 };
for (int i = 0; i < categories.length; i++)
{
IChartDataCell categoryCell = workbook.getCell(worksheetIndex, i + 1, 0, categories[i]);
chart.getChartData().getCategories().add(categoryCell);
IChartDataCell valueCell = workbook.getCell(worksheetIndex, i + 1, 1, values[i]);
series.getDataPoints().addDataPointForWaterfallSeries(valueCell);
}
// 세 번째와 여섯 번째 포인트는 총합을 나타내며, 추가 변화가 아닙니다.
series.getDataPoints().get_Item(2).setSetAsTotal(true);
series.getDataPoints().get_Item(5).setSetAsTotal(true);
series.setShowConnectorLines(true);
series.getLabels().getDefaultDataLabelFormat().setShowValue(true);
presentation.save("WaterfallChart.pptx", SaveFormat.Pptx);
}
finally
{
presentation.dispose();
}
시리즈 수준에서 setShowConnectorLines 메서드를 true 로 호출하면 연속된 열을 연결하는 선이 표시되어 누적 값을 파악하기 쉬워집니다. 이 선을 숨기려면 예제에서 해당 호출을 series.setShowConnectorLines(false); 로 바꾸고 저장하기 전에 적용하세요. 이는 라인 가시성만 변경하며 데이터나 합계에는 영향을 주지 않습니다.

주식 차트 만들기
주식 차트는 시가, 고가, 저가, 종가와 같은 금융 데이터를 표시하여 시장 추세와 변동성을 분석하는 데 사용됩니다. 주식 성과에 대한 핵심 인사이트를 제공해 투자자와 분석가가 정보에 입각한 결정을 내리도록 돕습니다.
이 예제는 순서대로 네 개의 시리즈와 세 개의 카테고리를 가진 시가‑고가‑저가‑종가(OHLC) 차트를 만듭니다. setUpDownBars 메서드는 상승/하락 막대를 활성화하고, getHiLowLinesFormat 메서드는 가격 범위를 나타내는 고‑저 선을 제어합니다. 개별 시리즈 라인과 작은 수평 그리드 라인은 숨겨져 있습니다.
getUpDownBars 가 반환하는 관리자는 getUpBarsFormat와 getDownBarsFormat 를 통해 각각 별도의 서식 객체를 제공합니다. 각 객체의 getFill 및 getLine 메서드를 사용해 채우기와 외곽선을 독립적으로 설정합니다. 이 예제는 상승 구간에 어두운 녹색 외곽선을 가진 녹색 막대를, 하락 구간에 어두운 빨강 외곽선을 가진 주황‑빨간색 막대를 사용합니다.
각 카테고리별로 네 개 시리즈 모두에 대한 수치를 제공하고, 고가와 저가가 시가와 종가를 감쌉니다. 막대는 동일 카테고리 내에서 종가와 시가를 비교하며 이전 카테고리와는 비교하지 않습니다: A는 72에서 25로 떨어지고, B는 25에서 38로 상승, C는 38에서 50으로 상승합니다. 시가와 종가가 동일하면 눈에 보이는 채워진 구간이 없습니다. 상승/하락 막대는 시가‑종가 구간을, 고‑저 선은 저‑고 구간을 표시합니다. 이러한 막대는 시리즈 그룹에 속하며 일반 막대형 차트 시리즈가 아닙니다.
이 서식은 동일 그룹에 두 개 이상의 시리즈와 각 카테고리별 숫자 값이 있는 Line 및 LineWithMarkers 차트에서도 작동합니다. 이러한 비스택 라인 차트에서는 첫 번째와 마지막 시리즈를 비교해 상승 막대와 하락 막대를 결정합니다: 마지막 값이 더 높으면 상승 막대, 더 낮으면 하락 막대가 생성됩니다. 시리즈 순서를 바꾸면 분류가 반전됩니다. 아래 예제는 OpenHighLowClose 를 사용했으며, 다른 주식, 스택형 라인 또는 3D 변형이 동일한 데이터 배열이나 구간 해석을 사용한다고 가정하지 마세요.
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try
{
ISlide slide = presentation.getSlides().get_Item(0);
IChart chart = slide.getShapes().addChart(ChartType.OpenHighLowClose, 20, 20, 500, 150, false);
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
IChartDataCell categoryCell = workbook.getCell(0, 1, 0, "A");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(0, 2, 0, "B");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(0, 3, 0, "C");
chart.getChartData().getCategories().add(categoryCell);
IChartDataCell seriesNameCell = workbook.getCell(0, 0, 1, "Open");
chart.getChartData().getSeries().add(seriesNameCell, ChartType.OpenHighLowClose);
seriesNameCell = workbook.getCell(0, 0, 2, "High");
chart.getChartData().getSeries().add(seriesNameCell, ChartType.OpenHighLowClose);
seriesNameCell = workbook.getCell(0, 0, 3, "Low");
chart.getChartData().getSeries().add(seriesNameCell, ChartType.OpenHighLowClose);
seriesNameCell = workbook.getCell(0, 0, 4, "Close");
chart.getChartData().getSeries().add(seriesNameCell, ChartType.OpenHighLowClose);
IChartSeries series = chart.getChartData().getSeries().get_Item(0);
IChartDataCell valueCell = workbook.getCell(0, 1, 1, 72);
series.getDataPoints().addDataPointForStockSeries(valueCell);
valueCell = workbook.getCell(0, 2, 1, 25);
series.getDataPoints().addDataPointForStockSeries(valueCell);
valueCell = workbook.getCell(0, 3, 1, 38);
series.getDataPoints().addDataPointForStockSeries(valueCell);
series = chart.getChartData().getSeries().get_Item(1);
valueCell = workbook.getCell(0, 1, 2, 172);
series.getDataPoints().addDataPointForStockSeries(valueCell);
valueCell = workbook.getCell(0, 2, 2, 57);
series.getDataPoints().addDataPointForStockSeries(valueCell);
valueCell = workbook.getCell(0, 3, 2, 57);
series.getDataPoints().addDataPointForStockSeries(valueCell);
series = chart.getChartData().getSeries().get_Item(2);
valueCell = workbook.getCell(0, 1, 3, 12);
series.getDataPoints().addDataPointForStockSeries(valueCell);
valueCell = workbook.getCell(0, 2, 3, 12);
series.getDataPoints().addDataPointForStockSeries(valueCell);
valueCell = workbook.getCell(0, 3, 3, 13);
series.getDataPoints().addDataPointForStockSeries(valueCell);
series = chart.getChartData().getSeries().get_Item(3);
valueCell = workbook.getCell(0, 1, 4, 25);
series.getDataPoints().addDataPointForStockSeries(valueCell);
valueCell = workbook.getCell(0, 2, 4, 38);
series.getDataPoints().addDataPointForStockSeries(valueCell);
valueCell = workbook.getCell(0, 3, 4, 50);
series.getDataPoints().addDataPointForStockSeries(valueCell);
IUpDownBarsManager upDownBars = chart.getChartData().getSeriesGroups().get_Item(0).getUpDownBars();
upDownBars.setUpDownBars(true);
upDownBars.getUpBarsFormat().getFill().setFillType(FillType.Solid);
upDownBars.getUpBarsFormat().getFill().getSolidFillColor().setColor(Color.rgb(50, 205, 50));
upDownBars.getUpBarsFormat().getLine().getFillFormat().setFillType(FillType.Solid);
upDownBars.getUpBarsFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.rgb(0, 100, 0));
upDownBars.getUpBarsFormat().getLine().setWidth(2);
upDownBars.getDownBarsFormat().getFill().setFillType(FillType.Solid);
upDownBars.getDownBarsFormat().getFill().getSolidFillColor().setColor(Color.rgb(255, 69, 0));
upDownBars.getDownBarsFormat().getLine().getFillFormat().setFillType(FillType.Solid);
upDownBars.getDownBarsFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.rgb(139, 0, 0));
upDownBars.getDownBarsFormat().getLine().setWidth(2);
chart.getChartData().getSeriesGroups().get_Item(0).getHiLowLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid);
for (IChartSeries stockSeries : chart.getChartData().getSeries())
{
stockSeries.getFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
}
chart.getAxes().getVerticalAxis().getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
presentation.save("Stock-chart.pptx", SaveFormat.Pptx);
}
finally
{
presentation.dispose();
}
결과(PowerPoint에서 내보낸 이미지):

박스 및 수염 차트 만들기
박스 및 수염 차트는 중앙값, 사분위수 및 잠재적 이상값과 같은 핵심 통계 측정값을 요약해 데이터 분포를 표시하는 데 사용됩니다. 탐색적 데이터 분석 및 통계 연구에서 데이터 변동성을 빠르게 이해하고 이상 현상을 식별하는 데 특히 유용합니다.
이 예제는 여섯 개 값으로 박스 및 수염 차트를 만듭니다. setQuartileMethod 메서드는 배타적 사분위수 계산을 선택합니다. 예제는 평균선, 평균 마커, 내부 점, 이상값 점도 활성화합니다.
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try
{
ISlide slide = presentation.getSlides().get_Item(0);
IChart chart = slide.getShapes().addChart(ChartType.BoxAndWhisker, 20, 20, 500, 300);
chart.getChartData().getCategories().clear();
chart.getChartData().getSeries().clear();
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
workbook.clear(0);
IChartDataCell categoryCell = workbook.getCell(0, "A1", "Category 1");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(0, "A2", "Category 2");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(0, "A3", "Category 3");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(0, "A4", "Category 4");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(0, "A5", "Category 5");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(0, "A6", "Category 6");
chart.getChartData().getCategories().add(categoryCell);
IChartSeries series = chart.getChartData().getSeries().add(ChartType.BoxAndWhisker);
series.setQuartileMethod(QuartileMethodType.Exclusive);
series.setShowMeanLine(true);
series.setShowMeanMarkers(true);
series.setShowInnerPoints(true);
series.setShowOutlierPoints(true);
IChartDataCell valueCell = workbook.getCell(0, "B1", 15);
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(valueCell);
valueCell = workbook.getCell(0, "B2", 41);
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(valueCell);
valueCell = workbook.getCell(0, "B3", 16);
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(valueCell);
valueCell = workbook.getCell(0, "B4", 10);
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(valueCell);
valueCell = workbook.getCell(0, "B5", 23);
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(valueCell);
valueCell = workbook.getCell(0, "B6", 16);
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(valueCell);
presentation.save("BoxAndWhisker.pptx", SaveFormat.Pptx);
}
finally
{
presentation.dispose();
}
퍼널 차트 만들기
퍼널 차트는 단계가 순차적으로 진행될수록 데이터 양이 감소하는 프로세스를 시각화하는 데 사용됩니다. 전환율 분석, 병목 현상 파악, 영업 또는 마케팅 프로세스 효율성 추적에 특히 도움이 됩니다.
이 예제는 addChart을 사용해 기존 프레젠테이션의 첫 번째 슬라이드에 퍼널 차트를 추가합니다. 기본 데이터를 6개의 카테고리와 값(50~500)으로 교체하고 업데이트된 프레젠테이션을 저장합니다. 입력 프레젠테이션에는 최소 하나의 슬라이드가 있어야 합니다.
import com.aspose.slides.*;
Presentation presentation = new Presentation("test.pptx");
try
{
ISlide slide = presentation.getSlides().get_Item(0);
IChart chart = slide.getShapes().addChart(ChartType.Funnel, 50, 50, 500, 400);
chart.getChartData().getCategories().clear();
chart.getChartData().getSeries().clear();
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
workbook.clear(0);
IChartDataCell categoryCell = workbook.getCell(0, "A1", "Category 1");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(0, "A2", "Category 2");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(0, "A3", "Category 3");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(0, "A4", "Category 4");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(0, "A5", "Category 5");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(0, "A6", "Category 6");
chart.getChartData().getCategories().add(categoryCell);
IChartSeries series = chart.getChartData().getSeries().add(ChartType.Funnel);
IChartDataCell valueCell = workbook.getCell(0, "B1", 50);
series.getDataPoints().addDataPointForFunnelSeries(valueCell);
valueCell = workbook.getCell(0, "B2", 100);
series.getDataPoints().addDataPointForFunnelSeries(valueCell);
valueCell = workbook.getCell(0, "B3", 200);
series.getDataPoints().addDataPointForFunnelSeries(valueCell);
valueCell = workbook.getCell(0, "B4", 300);
series.getDataPoints().addDataPointForFunnelSeries(valueCell);
valueCell = workbook.getCell(0, "B5", 400);
series.getDataPoints().addDataPointForFunnelSeries(valueCell);
valueCell = workbook.getCell(0, "B6", 500);
series.getDataPoints().addDataPointForFunnelSeries(valueCell);
presentation.save("Funnel.pptx", SaveFormat.Pptx);
}
finally
{
presentation.dispose();
}
결과:

썬버스트 차트 만들기
썬버스트 차트는 계층 데이터를 시각화하며 레벨을 동심원 형태의 링으로 표시합니다. 부분‑전체 관계를 설명하고 중첩된 카테고리와 하위 카테고리를 명확하고 간결하게 표현하는 데 이상적입니다.
이 예제는 네 개의 줄기와 두 개의 가지로 구성된 여덟 개의 잎을 가진 썬버스트 차트를 만듭니다. setGroupingItem 메서드는 1단계에서 줄기를, 2단계에서 가지를 지정합니다. 카테고리 레이블이 세그먼트를 식별하고 값이 상대 크기를 결정합니다.
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try
{
ISlide slide = presentation.getSlides().get_Item(0);
IChart chart = slide.getShapes().addChart(ChartType.Sunburst, 20, 20, 500, 300);
chart.getChartData().getCategories().clear();
chart.getChartData().getSeries().clear();
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
workbook.clear(0);
// 브랜치 1
IChartDataCell categoryCell = workbook.getCell(0, "C1", "Leaf1");
IChartCategory leaf = chart.getChartData().getCategories().add(categoryCell);
leaf.getGroupingLevels().setGroupingItem(1, "Stem1");
leaf.getGroupingLevels().setGroupingItem(2, "Branch1");
categoryCell = workbook.getCell(0, "C2", "Leaf2");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(0, "C3", "Leaf3");
leaf = chart.getChartData().getCategories().add(categoryCell);
leaf.getGroupingLevels().setGroupingItem(1, "Stem2");
categoryCell = workbook.getCell(0, "C4", "Leaf4");
chart.getChartData().getCategories().add(categoryCell);
// 브랜치 2
categoryCell = workbook.getCell(0, "C5", "Leaf5");
leaf = chart.getChartData().getCategories().add(categoryCell);
leaf.getGroupingLevels().setGroupingItem(1, "Stem3");
leaf.getGroupingLevels().setGroupingItem(2, "Branch2");
categoryCell = workbook.getCell(0, "C6", "Leaf6");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(0, "C7", "Leaf7");
leaf = chart.getChartData().getCategories().add(categoryCell);
leaf.getGroupingLevels().setGroupingItem(1, "Stem4");
categoryCell = workbook.getCell(0, "C8", "Leaf8");
chart.getChartData().getCategories().add(categoryCell);
IChartSeries series = chart.getChartData().getSeries().add(ChartType.Sunburst);
series.getLabels().getDefaultDataLabelFormat().setShowCategoryName(true);
IChartDataCell valueCell = workbook.getCell(0, "D1", 4);
series.getDataPoints().addDataPointForSunburstSeries(valueCell);
valueCell = workbook.getCell(0, "D2", 5);
series.getDataPoints().addDataPointForSunburstSeries(valueCell);
valueCell = workbook.getCell(0, "D3", 3);
series.getDataPoints().addDataPointForSunburstSeries(valueCell);
valueCell = workbook.getCell(0, "D4", 6);
series.getDataPoints().addDataPointForSunburstSeries(valueCell);
valueCell = workbook.getCell(0, "D5", 9);
series.getDataPoints().addDataPointForSunburstSeries(valueCell);
valueCell = workbook.getCell(0, "D6", 9);
series.getDataPoints().addDataPointForSunburstSeries(valueCell);
valueCell = workbook.getCell(0, "D7", 4);
series.getDataPoints().addDataPointForSunburstSeries(valueCell);
valueCell = workbook.getCell(0, "D8", 3);
series.getDataPoints().addDataPointForSunburstSeries(valueCell);
presentation.save("Sunburst.pptx", SaveFormat.Pptx);
}
finally
{
presentation.dispose();
}
결과:

히스토그램 차트 만들기
히스토그램 차트는 숫자 값이 구간(빈)별로 어떻게 분포되는지 보여줍니다. 주문 처리 시간과 같은 월간 보고서에서는 동일한 빈 너비와 임계값을 사용해 구간을 일관되게 유지하고 분포를 비교하기 쉽게 합니다.
수평 축에 setAggregationType을 사용하고, AxisAggregationType 중 하나의 모드를 지정합니다. ByBinWidth인 경우에만 setBinWidth이 적용되고, ByNumberOfBins인 경우에만 setNumberOfBins이 적용됩니다. Automatic을 사용하면 차트가 자동으로 빈을 선택합니다.
고정 빈 너비 사용
이 예제는 처리 시간을 10분 간격으로 구분하고, 10분 이하와 40분 이상에 대해 별도의 빈을 제공합니다. setUnderflowBin와 setOverflowBin 로 이러한 빈을 활성화합니다. setUnderflowBin 및 setOverflowBin 로 명시적 임계값을 제공하는 경우 setAutomaticUnderflowBin 및 setAutomaticOverflowBin 을 false 로 설정합니다.
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try
{
ISlide slide = presentation.getSlides().get_Item(0);
IChart chart = slide.getShapes().addChart(ChartType.Histogram, 20, 20, 680, 200);
chart.setLegend(false);
chart.setTitle(false);
chart.getChartData().getCategories().clear();
chart.getChartData().getSeries().clear();
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
workbook.clear(0);
IChartSeries series = chart.getChartData().getSeries().add(ChartType.Histogram);
double[] values = { 5, 10, 10, 11, 15, 20, 20, 21, 25, 30, 30, 31, 35, 40, 40, 41, 50 };
for (int i = 0; i < values.length; i++)
{
IChartDataCell valueCell = workbook.getCell(0, i, 0, values[i]);
series.getDataPoints().addDataPointForHistogramSeries(valueCell);
}
IAxis axis = chart.getAxes().getHorizontalAxis();
axis.setAggregationType(AxisAggregationType.ByBinWidth);
axis.setBinWidth(10);
axis.setUnderflowBin(true);
axis.setAutomaticUnderflowBin(false);
axis.setUnderflowBin(10);
axis.setOverflowBin(true);
axis.setAutomaticOverflowBin(false);
axis.setOverflowBin(40);
presentation.save("Histogram-bin-width.pptx", SaveFormat.Pptx);
}
finally
{
presentation.dispose();
}
PowerPoint에서 표시되는 프레젠테이션은 3, 4, 4, 4, 2 의 빈 개수를 보여줍니다. 언더플로우 빈에는 5, 10, 10가 포함되며 임계값은 포함됩니다. 오버플로우 빈에는 41, 50만 포함되고 임계값은 제외됩니다; 40값은 이전 구간에 남아 있습니다. 내부 빈은 하한보다 크고 상한보다 작거나 같은 값을 포함합니다.

빈 개수 지정
고정 구간 대신 상세 수준을 고정하고 싶다면 동일 데이터에 대해 다섯 개의 빈을 요청합니다. 이 예제는 언더플로우와 오버플로우 빈을 비활성화합니다. 차트는 데이터 범위에서 너비를 계산하므로 보고서마다 경계가 변할 수 있습니다.
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try
{
ISlide slide = presentation.getSlides().get_Item(0);
IChart chart = slide.getShapes().addChart(ChartType.Histogram, 20, 20, 680, 200);
chart.setLegend(false);
chart.setTitle(false);
chart.getChartData().getCategories().clear();
chart.getChartData().getSeries().clear();
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
workbook.clear(0);
IChartSeries series = chart.getChartData().getSeries().add(ChartType.Histogram);
double[] values = { 5, 10, 10, 11, 15, 20, 20, 21, 25, 30, 30, 31, 35, 40, 40, 41, 50 };
for (int i = 0; i < values.length; i++)
{
IChartDataCell valueCell = workbook.getCell(0, i, 0, values[i]);
series.getDataPoints().addDataPointForHistogramSeries(valueCell);
}
IAxis axis = chart.getAxes().getHorizontalAxis();
axis.setAggregationType(AxisAggregationType.ByNumberOfBins);
axis.setNumberOfBins(5);
presentation.save("Histogram-bin-count.pptx", SaveFormat.Pptx);
}
finally
{
presentation.dispose();
}
다섯 개 빈의 개수는 4, 4, 4, 4, 1 입니다. 위의 고정 너비 결과와 비교해 보세요: 입력값은 동일하지만 경계가 다릅니다.

레이더 차트 만들기
레이더 차트는 다변량 데이터를 2차원 형식으로 표시해 여러 변수를 동시에 쉽게 비교할 수 있게 해 줍니다. 여러 성능 지표나 속성을 평가할 때 패턴, 강점, 약점을 식별하는 데 특히 유용합니다.
이 예제는 addChart을 사용해 기본 시리즈와 카테고리로 레이더 차트를 만든 뒤 프레젠테이션을 PPTX로 저장합니다.
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try
{
ISlide slide = presentation.getSlides().get_Item(0);
slide.getShapes().addChart(ChartType.Radar, 20, 20, 500, 300);
presentation.save("Radar-chart.pptx", SaveFormat.Pptx);
}
finally
{
presentation.dispose();
}
결과:

다중 카테고리 차트 만들기
다중 카테고리 차트는 하나 이상의 카테고리 그룹을 포함하는 데이터를 표시해 여러 차원에서 값을 비교할 수 있게 해 줍니다. 복잡하고 다층적인 데이터 세트를 분석할 때 특히 도움이 됩니다.
이 예제는 네 쌍으로 배열된 여덟 개 카테고리를 가진 군집 컬럼 차트를 만듭니다. setGroupingItem 메서드는 각 쌍에 1단계 그룹 레이블을 부여해 개별 레이블과 그룹 레이블이 모두 있는 카테고리 축을 생성합니다.
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try
{
ISlide slide = presentation.getSlides().get_Item(0);
IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 20, 20, 500, 300);
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
workbook.clear(0);
int worksheetIndex = 0;
IChartDataCell categoryCell = workbook.getCell(0, "c2", "A");
IChartCategory category = chart.getChartData().getCategories().add(categoryCell);
category.getGroupingLevels().setGroupingItem(1, "Group1");
categoryCell = workbook.getCell(0, "c3", "B");
category = chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(0, "c4", "C");
category = chart.getChartData().getCategories().add(categoryCell);
category.getGroupingLevels().setGroupingItem(1, "Group2");
categoryCell = workbook.getCell(0, "c5", "D");
category = chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(0, "c6", "E");
category = chart.getChartData().getCategories().add(categoryCell);
category.getGroupingLevels().setGroupingItem(1, "Group3");
categoryCell = workbook.getCell(0, "c7", "F");
category = chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(0, "c8", "G");
category = chart.getChartData().getCategories().add(categoryCell);
category.getGroupingLevels().setGroupingItem(1, "Group4");
categoryCell = workbook.getCell(0, "c9", "H");
category = chart.getChartData().getCategories().add(categoryCell);
IChartDataCell seriesNameCell = workbook.getCell(0, "D1", "Series 1");
IChartSeries series = chart.getChartData().getSeries().add(seriesNameCell, ChartType.ClusteredColumn);
IChartDataCell valueCell = workbook.getCell(worksheetIndex, "D2", 10);
series.getDataPoints().addDataPointForBarSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, "D3", 20);
series.getDataPoints().addDataPointForBarSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, "D4", 30);
series.getDataPoints().addDataPointForBarSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, "D5", 40);
series.getDataPoints().addDataPointForBarSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, "D6", 50);
series.getDataPoints().addDataPointForBarSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, "D7", 60);
series.getDataPoints().addDataPointForBarSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, "D8", 70);
series.getDataPoints().addDataPointForBarSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, "D9", 80);
series.getDataPoints().addDataPointForBarSeries(valueCell);
presentation.save("AsposeChart.pptx", SaveFormat.Pptx);
}
finally
{
presentation.dispose();
}
결과:

분기 레이블 제거
quarters.pptx를 다운로드하고 작업 디렉터리에 배치합니다. 차트에는 9개월과 10~18값을 가진 단일 판매 시리즈가 있습니다. 카테고리 축에서 Q1은 1월‑3월, Q2는 4월‑6월, Q3는 7월‑9월을 차지합니다.
4번째 카테고리(인덱스 3)인 4월에 Q2 레이블이 있습니다. getGroupingLevels 로 4월의 그룹 레벨에 접근한 뒤, 레벨 1에 대해 deleteGroupingItem 를 호출해 해당 분기 레이블을 제거합니다. 레벨 0은 월 자체를 나타내며 이 메서드로 제거할 수 없습니다.
import com.aspose.slides.*;
import java.util.ArrayList;
import java.util.List;
import android.text.TextUtils;
Presentation presentation = new Presentation("quarters.pptx");
try {
IChart chart = (IChart) presentation.getSlides().get_Item(0).getShapes().get_Item(0);
IChartCategory april = chart.getChartData().getCategories().get_Item(3);
april.getGroupingLevels().deleteGroupingItem(1);
presentation.save("quarters-updated.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
Presentation reopened = new Presentation("quarters-updated.pptx");
try {
IChart updatedChart = (IChart) reopened.getSlides().get_Item(0).getShapes().get_Item(0);
IChartData data = updatedChart.getChartData();
List<String> months = new ArrayList<>();
for (IChartCategory month : data.getCategories()) {
months.add(String.valueOf(month.getAsCell().getValue()));
}
List<String> sales = new ArrayList<>();
for (IChartDataPoint point : data.getSeries().get_Item(0).getDataPoints()) {
sales.add(String.valueOf(point.getValue().getData()));
}
System.out.println(TextUtils.join(", ", months));
System.out.println(TextUtils.join(", ", sales));
} finally {
reopened.dispose();
}
차트를 다시 열면 예제는 원래 월(Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep)과 판매값(10, 11, 12, 13, 14, 15, 16, 17, 18)을 같은 순서로 출력합니다. PowerPoint에서 quarters-updated.pptx를 열어 축 레이블을 확인하세요. Q2 레이블과 4월 이전의 그룹 경계가 사라져 Q1이 1월‑6월을 차지합니다. Q3는 여전히 7월에 시작합니다.

지도 차트 만들기
지도 차트는 국가, 주, 도시 등 특정 위치에 정보를 매핑해 지리 데이터를 시각화합니다. 지역별 트렌드, 인구통계, 공간 분포 등을 명확하고 시각적으로 매력적인 형태로 분석할 때 특히 유용합니다.
이 예제는 addChart을 사용해 기본 지리 데이터를 가진 지도 차트를 만든 뒤 PowerPoint에서 보기 위해 저장합니다.
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try
{
ISlide slide = presentation.getSlides().get_Item(0);
IChart chart = slide.getShapes().addChart(ChartType.Map, 20, 20, 500, 300);
presentation.save("mapChart.pptx", SaveFormat.Pptx);
}
finally
{
presentation.dispose();
}
결과:

Note
위 그림은 PowerPoint에서 연 파일을 연 모습을 보여줍니다. Aspose.Slides는 지도 차트와 데이터를 올바르게 기록하지만 자체적으로 지도 차트를 그리지는 않습니다. 슬라이드에 포함된 차트를 이미지로 렌더링하거나 PDF·SVG로 변환하면 차트 영역이 비어 있게 됩니다. 동일 슬라이드의 다른 도형은 영향을 받지 않습니다.조합 차트 만들기
조합 차트(또는 콤보 차트)는 하나의 그래프에 두 개 이상의 차트 유형을 결합합니다. 이 차트를 사용하면 두 개 이상의 데이터 집합을 강조, 비교 또는 차이점을 검토해 서로 간의 관계를 파악할 수 있습니다.

이 예제는 네 개 카테고리에 대해 두 개의 군집 컬럼 시리즈와 하나의 라인 시리즈를 결합합니다. 컬럼은 기본 수직 축을 사용하고, setPlotOnSecondAxis 로 라인은 오른쪽 보조 수직 축에 배치합니다. 헬퍼 함수가 제목, 범례, 축 레이블 및 격자를 구성합니다.
import com.aspose.slides.*;
import android.graphics.Color;
class ComboChartExample
{
void createComboChart()
{
Presentation presentation = new Presentation();
try
{
IChart chart = createChartWithFirstSeries(presentation.getSlides().get_Item(0));
addSecondSeriesToChart(chart);
addThirdSeriesToChart(chart);
setPrimaryAxesFormat(chart);
setSecondaryAxesFormat(chart);
presentation.save("combo-chart.pptx", SaveFormat.Pptx);
}
finally
{
presentation.dispose();
}
}
IChart createChartWithFirstSeries(ISlide slide)
{
IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 600, 400);
chart.setTitle(true);
chart.getChartTitle().addTextFrameForOverriding("Chart Title");
chart.getChartTitle().setOverlay(false);
IPortionFormat portionFormat = chart.getChartTitle().getTextFrameForOverriding().getParagraphs().get_Item(0).getParagraphFormat().getDefaultPortionFormat();
portionFormat.setFontBold(NullableBool.False);
portionFormat.setFontHeight(18f);
chart.getLegend().setPosition(LegendPositionType.Bottom);
chart.getLegend().getTextFormat().getPortionFormat().setFontHeight(12f);
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
int worksheetIndex = 0;
IChartDataCell categoryCell = workbook.getCell(worksheetIndex, 1, 0, "Category 1");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(worksheetIndex, 2, 0, "Category 2");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(worksheetIndex, 3, 0, "Category 3");
chart.getChartData().getCategories().add(categoryCell);
categoryCell = workbook.getCell(worksheetIndex, 4, 0, "Category 4");
chart.getChartData().getCategories().add(categoryCell);
IChartDataCell seriesNameCell = workbook.getCell(worksheetIndex, 0, 1, "Series 1");
IChartSeries series = chart.getChartData().getSeries().add(seriesNameCell, chart.getType());
series.getParentSeriesGroup().setOverlap((byte) -25);
series.getParentSeriesGroup().setGapWidth(220);
IChartDataCell valueCell = workbook.getCell(worksheetIndex, 1, 1, 4.3);
series.getDataPoints().addDataPointForBarSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, 2, 1, 2.5);
series.getDataPoints().addDataPointForBarSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, 3, 1, 3.5);
series.getDataPoints().addDataPointForBarSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, 4, 1, 4.5);
series.getDataPoints().addDataPointForBarSeries(valueCell);
return chart;
}
void addSecondSeriesToChart(IChart chart)
{
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
final int worksheetIndex = 0;
IChartDataCell seriesNameCell = workbook.getCell(worksheetIndex, 0, 2, "Series 2");
IChartSeries series = chart.getChartData().getSeries().add(seriesNameCell, ChartType.ClusteredColumn);
series.getParentSeriesGroup().setOverlap((byte) -25);
series.getParentSeriesGroup().setGapWidth(220);
IChartDataCell valueCell = workbook.getCell(worksheetIndex, 1, 2, 2.4);
series.getDataPoints().addDataPointForBarSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, 2, 2, 4.4);
series.getDataPoints().addDataPointForBarSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, 3, 2, 1.8);
series.getDataPoints().addDataPointForBarSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, 4, 2, 2.8);
series.getDataPoints().addDataPointForBarSeries(valueCell);
}
void addThirdSeriesToChart(IChart chart)
{
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
final int worksheetIndex = 0;
IChartDataCell seriesNameCell = workbook.getCell(worksheetIndex, 0, 3, "Series 3");
IChartSeries series = chart.getChartData().getSeries().add(seriesNameCell, ChartType.Line);
IChartDataCell valueCell = workbook.getCell(worksheetIndex, 1, 3, 2.0);
series.getDataPoints().addDataPointForLineSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, 2, 3, 2.0);
series.getDataPoints().addDataPointForLineSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, 3, 3, 3.0);
series.getDataPoints().addDataPointForLineSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, 4, 3, 5.0);
series.getDataPoints().addDataPointForLineSeries(valueCell);
series.setPlotOnSecondAxis(true);
}
void setPrimaryAxesFormat(IChart chart)
{
IAxis horizontalAxis = chart.getAxes().getHorizontalAxis();
horizontalAxis.getTextFormat().getPortionFormat().setFontHeight(12f);
horizontalAxis.getFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
setAxisTitle(horizontalAxis, "X Axis");
IAxis verticalAxis = chart.getAxes().getVerticalAxis();
verticalAxis.getTextFormat().getPortionFormat().setFontHeight(12f);
verticalAxis.getFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
setAxisTitle(verticalAxis, "Y Axis 1");
ILineFillFormat majorGridLinesFormat = verticalAxis.getMajorGridLinesFormat().getLine().getFillFormat();
majorGridLinesFormat.setFillType(FillType.Solid);
majorGridLinesFormat.getSolidFillColor().setColor(Color.rgb(217, 217, 217));
}
void setSecondaryAxesFormat(IChart chart)
{
IAxis secondaryHorizontalAxis = chart.getAxes().getSecondaryHorizontalAxis();
secondaryHorizontalAxis.setPosition(AxisPositionType.Bottom);
secondaryHorizontalAxis.setCrossType(CrossesType.Maximum);
secondaryHorizontalAxis.setVisible(false);
secondaryHorizontalAxis.getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
secondaryHorizontalAxis.getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
IAxis secondaryVerticalAxis = chart.getAxes().getSecondaryVerticalAxis();
secondaryVerticalAxis.setPosition(AxisPositionType.Right);
secondaryVerticalAxis.getTextFormat().getPortionFormat().setFontHeight(12f);
secondaryVerticalAxis.getFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
secondaryVerticalAxis.getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
secondaryVerticalAxis.getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
setAxisTitle(secondaryVerticalAxis, "Y Axis 2");
}
void setAxisTitle(IAxis axis, String axisTitle)
{
axis.setTitle(true);
axis.getTitle().setOverlay(false);
IPortionFormat titlePortionFormat = axis.getTitle().addTextFrameForOverriding(axisTitle).getParagraphs().get_Item(0).getParagraphFormat().getDefaultPortionFormat();
titlePortionFormat.setFontBold(NullableBool.False);
titlePortionFormat.setFontHeight(12f);
}
}
ComboChartExample example = new ComboChartExample();
example.createComboChart();
차트 업데이트
Aspose.Slides for Android via Java를 사용하면 차트 데이터를 수정하고, 형식 및 스타일을 변경해 PowerPoint 차트를 업데이트할 수 있습니다. 이 기능을 통해 프레젠테이션을 동적 콘텐츠와 함께 최신 상태로 유지하고 차트가 현재 데이터와 시각적 표준을 정확히 반영하도록 할 수 있습니다.
이 예제는 기존 프레젠테이션의 첫 번째 슬라이드에 있는 “My chart"라는 차트를 업데이트합니다. 각 시리즈에 세 개의 데이터 포인트가 있는 두 개의 컬럼 시리즈가 필요하며, 카테고리 레이블은 A 열에, 시리즈 이름은 첫 번째 워크시트의 첫 행에 있습니다. 예제는 getCell 로 워크북 셀을 변경하고, 시리즈 값을 업데이트하고, 세 번째 시리즈를 추가하며, setType 로 차트를 군집 실린더형으로 변경합니다.
import com.aspose.slides.*;
final String chartName = "My chart";
Presentation presentation = new Presentation("ExistingChart.pptx");
try
{
ISlide slide = presentation.getSlides().get_Item(0);
for (IShape shape : slide.getShapes())
{
if (shape instanceof IChart && chartName.equals(shape.getName()))
{
IChart chart = (IChart) shape;
int worksheetIndex = 0;
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
workbook.getCell(worksheetIndex, 1, 0, "Modified Category 1");
workbook.getCell(worksheetIndex, 2, 0, "Modified Category 2");
IChartSeries series = chart.getChartData().getSeries().get_Item(0);
workbook.getCell(worksheetIndex, 0, 1, "New_Series 1");
series.getDataPoints().get_Item(0).getValue().setData(90);
series.getDataPoints().get_Item(1).getValue().setData(123);
series.getDataPoints().get_Item(2).getValue().setData(44);
series = chart.getChartData().getSeries().get_Item(1);
workbook.getCell(worksheetIndex, 0, 2, "New_Series 2");
series.getDataPoints().get_Item(0).getValue().setData(23);
series.getDataPoints().get_Item(1).getValue().setData(67);
series.getDataPoints().get_Item(2).getValue().setData(99);
IChartDataCell seriesNameCell = workbook.getCell(worksheetIndex, 0, 3, "Series 3");
series = chart.getChartData().getSeries().add(seriesNameCell, chart.getType());
IChartDataCell valueCell = workbook.getCell(worksheetIndex, 1, 3, 20);
series.getDataPoints().addDataPointForBarSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, 2, 3, 50);
series.getDataPoints().addDataPointForBarSeries(valueCell);
valueCell = workbook.getCell(worksheetIndex, 3, 3, 30);
series.getDataPoints().addDataPointForBarSeries(valueCell);
chart.setType(ChartType.ClusteredCylinder);
}
}
presentation.save("AsposeChartModified.pptx", SaveFormat.Pptx);
}
finally
{
presentation.dispose();
}
차트 데이터 범위 설정
기존 차트가 이미 사용하고 있는 범위를 확인하려면 차트 데이터 범위 검색 를 참고하세요.
Aspose.Slides for Android via Java는 워크시트의 특정 데이터 범위를 차트 데이터 원본으로 정의하는 유연성을 제공합니다. 즉, 워크시트의 일부를 차트에 직접 매핑해 차트 시리즈와 카테고리에 기여하는 셀을 제어할 수 있습니다. 이를 통해 워크시트의 최신 데이터 변경 사항을 차트에 쉽게 업데이트하고 동기화할 수 있어 PowerPoint 프레젠테이션이 최신 정확한 정보를 반영하도록 할 수 있습니다.
이 예제는 setRange 를 사용해 기존 프레젠테이션 첫 번째 슬라이드에 있는 “My chart” 차트의 데이터 원본을 Sheet1!A1:B4 로 설정합니다. 차트 워크북에 해당 워크시트가 있어야 하고, 첫 행에 시리즈 헤딩, A 열에 카테고리 레이블, B 열에 세 개 값이 채워진 범위가 있어야 합니다.
import com.aspose.slides.*;
final String chartName = "My chart";
Presentation presentation = new Presentation("ExistingChart.pptx");
try
{
ISlide slide = presentation.getSlides().get_Item(0);
for (IShape shape : slide.getShapes())
{
if (shape instanceof IChart && chartName.equals(shape.getName()))
{
IChart chart = (IChart) shape;
chart.getChartData().setRange("Sheet1!A1:B4");
}
}
presentation.save("SetDataRange.pptx", SaveFormat.Pptx);
}
finally
{
presentation.dispose();
}
차트에서 기본 마커 사용
차트에서 기본 마커를 사용하면 각 차트 시리즈에 자동으로 서로 다른 기본 마커 기호가 할당됩니다.
이 예제는 addChart을 사용해 두 개의 라인 시리즈와 범례가 있는 차트를 만들고, getMarker 로 접근한 마커 설정이 자동 할당된 마커 기호를 유지하도록 합니다. 첫 번째 시리즈에는 음수 값과 null 로 표시된 누락 값이 포함되고, 두 번째 시리즈는 모든 카테고리에 값을 가지고 있습니다.
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try
{
ISlide slide = presentation.getSlides().get_Item(0);
IChart chart = slide.getShapes().addChart(ChartType.LineWithMarkers, 10, 10, 400, 400);
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
IChartDataCell seriesNameCell = workbook.getCell(0, 0, 1, "Series 1");
IChartSeries series = chart.getChartData().getSeries().add(seriesNameCell, chart.getType());
IChartDataCell categoryCell = workbook.getCell(0, 1, 0, "C1");
chart.getChartData().getCategories().add(categoryCell);
IChartDataCell valueCell = workbook.getCell(0, 1, 1, 24);
series.getDataPoints().addDataPointForLineSeries(valueCell);
categoryCell = workbook.getCell(0, 2, 0, "C2");
chart.getChartData().getCategories().add(categoryCell);
valueCell = workbook.getCell(0, 2, 1, 23);
series.getDataPoints().addDataPointForLineSeries(valueCell);
categoryCell = workbook.getCell(0, 3, 0, "C3");
chart.getChartData().getCategories().add(categoryCell);
valueCell = workbook.getCell(0, 3, 1, -10);
series.getDataPoints().addDataPointForLineSeries(valueCell);
categoryCell = workbook.getCell(0, 4, 0, "C4");
chart.getChartData().getCategories().add(categoryCell);
valueCell = workbook.getCell(0, 4, 1, null);
series.getDataPoints().addDataPointForLineSeries(valueCell);
seriesNameCell = workbook.getCell(0, 0, 2, "Series 2");
IChartSeries secondSeries = chart.getChartData().getSeries().add(seriesNameCell, chart.getType());
valueCell = workbook.getCell(0, 1, 2, 30);
secondSeries.getDataPoints().addDataPointForLineSeries(valueCell);
valueCell = workbook.getCell(0, 2, 2, 10);
secondSeries.getDataPoints().addDataPointForLineSeries(valueCell);
valueCell = workbook.getCell(0, 3, 2, 60);
secondSeries.getDataPoints().addDataPointForLineSeries(valueCell);
valueCell = workbook.getCell(0, 4, 2, 40);
secondSeries.getDataPoints().addDataPointForLineSeries(valueCell);
chart.setLegend(true);
chart.getLegend().setOverlay(false);
presentation.save("DefaultMarkersInChart.pptx", SaveFormat.Pptx);
}
finally
{
presentation.dispose();
}
FAQ
Aspose.Slides for Android via Java가 지원하는 차트 유형은 무엇입니까?
Aspose.Slides for Android via Java는 막대, 선, 원형, 영역, 산점도, 히스토그램, 레이더 등 다양한 차트 유형을 지원합니다. 이 유연성을 통해 데이터 시각화 요구에 가장 적합한 차트 유형을 선택할 수 있습니다.
슬라이드에 새 차트를 추가하려면 어떻게 해야 합니까?
차트를 추가하려면 먼저 Presentation 클래스 인스턴스를 만든 뒤, 인덱스로 원하는 슬라이드를 가져오고, 차트 유형과 초기 데이터를 지정해 차트를 추가하는 메서드를 호출합니다. 이렇게 하면 차트가 프레젠테이션에 직접 삽입됩니다.
차트에 표시되는 데이터를 어떻게 업데이트할 수 있습니까?
차트의 데이터 워크북(IChartDataWorkbook)에 접근해 기본 시리즈와 카테고리를 지우고 사용자 정의 데이터를 추가하면 차트를 프로그래밍 방식으로 최신 데이터로 새로 고칠 수 있습니다.
차트의 외관을 사용자 지정할 수 있습니까?
네, Aspose.Slides for Android via Java는 색상, 글꼴, 레이블, 범례 및 기타 서식 요소를 광범위하게 사용자 지정할 수 있는 옵션을 제공합니다. 이를 통해 차트의 외관을 특정 디자인 요구 사항에 맞게 조정할 수 있습니다.