Android で PowerPoint プレゼンテーションのチャートを作成または更新
概要
この記事では、Aspose.Slides for Android via Java を使用してチャートを作成およびカスタマイズする方法について包括的に解説します。スライドにプログラムでチャートを追加し、データを設定し、特定のデザイン要件に合わせてさまざまな書式設定オプションを適用する方法を学びます。記事全体で、プレゼンテーションとチャートオブジェクトの初期化からシリーズ、軸、凡例の構成まで、各手順を示す詳細なコード例が示されています。このガイドに従うことで、Android アプリケーションに動的なチャート生成を統合し、データ駆動型プレゼンテーションの作成プロセスを効率化する方法をしっかりと理解できます。
チャートの作成
チャートはデータをすばやく可視化し、表やスプレッドシートだけではすぐに分からない洞察を得るのに役立ちます。
チャートを作成する理由
チャートを使用すると、次のことが可能です。
- 大量のデータをプレゼンテーションの 1 つのスライドに集約、要約、または凝縮できる。
- データのパターンやトレンドを明らかにできる。
- 時間の経過や特定の測定単位に対するデータの方向性と勢いを推測できる。
- 外れ値、異常、誤差、意味のないデータを発見できる。
- 複雑なデータを伝達または提示できる。
PowerPoint では Insert 機能を使ってチャートを作成でき、さまざまな種類のチャート用テンプレートが用意されています。Aspose.Slides を使用すれば、一般的なチャートタイプに基づく通常のチャートとカスタムチャートの両方を作成できます。
クラスター化縦棒チャートの作成
この例は addChart を使用して、3 つのカテゴリにわたる 2 系列を比較するクラスター化縦棒チャートを作成します。系列は赤と緑の塗りつぶしを使用し、個別のラベルでカテゴリ名、系列名、値を示します。ワークシート インデックス 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 グラフとも呼ばれる)は、2 つの変数間のパターンや相関関係を確認するために頻繁に使用されます。
散布図を使用する場面:
- ペアになった数値データがあるとき。
- 2 つの変数が相互に関連付けられるとき。
- 2 つの変数が関係しているかどうかを判断したいとき。
- 従属変数に対して複数の値を持つ独立変数があるとき。
この例は 2 つの x‑y 値のセットをプロットします。最初の系列はスター マーカー付きの直線、2 番目の系列はサークル マーカー付きの滑らかな線を使用し、どちらもサイズ 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();
}
結果:

円グラフの作成
円グラフは、特にカテゴリ ラベルに数値が割り当てられているデータの全体に対する部分の関係を示すのに最適です。ただし、項目やラベルが多数ある場合は、棒グラフの使用を検討してください。
この例は 3 つの四半期の値で円グラフを作成します。各スライスはカスタム塗りつぶしと枠線を持ち、ラベルは値、パーセンテージ、系列情報の組み合わせを表示します。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();
}
結果:

ラベルを円の外側に配置して可読性を向上させる方法は、Format Leader Lines の例をご覧ください。ラベル位置や線の色、幅、透明度、破線スタイルをカスタマイズできます。
折れ線グラフの作成
折れ線グラフ(線グラフ)は、時間経過による値の変化を示したい場合に最適です。折れ線グラフを使用すると、膨大なデータを一度に比較したり、時間軸での変化やトレンドを追跡したり、系列の異常をハイライトしたりできます。
この例は 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();
}
結果:

ツリーマップチャートの作成
ツリーマップチャートは、各カテゴリ内で大きな寄与を持つ項目に注目させながら、データカテゴリの相対的なサイズを示すのに最適です。
この例は、8 つのリーフを 4 つのステムと 2 つのブランチに分けたツリーマップを作成します。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 から累積値まで伸びます。
以下の例は米ドル千単位の金額を使用します:
| Category | Workbook value | Column type |
|---|---|---|
| Revenue | 1000 | Increase |
| Cost of sales | -400 | Decrease |
| Gross profit | 600 | Intermediate total |
| Operating expenses | -200 | Decrease |
| Other income | 50 | Increase |
| Net profit | 450 | Final total |
ポイントを中間合計または最終合計としてマークするには、setSetAsTotal に true を渡します。そのポイントのワークブック セルには実際の累積金額を入れます(例: 粗利益は 600、純利益は 450)。このメソッドは列を合計としてマークするだけで、セルの値を計算したり入力したりはしません。ゼロをプレースホルダーとして使用したり、合計ポイントに別の変化値を設定したりしないでください。合計列は累積値を表示しますが、再度加算は行いません。
この完全な 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);
}
// 3番目と6番目のポイントは、追加の変化ではなく合計を表しています。
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); に置き換えて保存してください。この変更は線の可視性のみを影響し、データや合計には影響しません。
保存されたプレゼンテーションは、粗利益 600 と純利益 450 を 0 から描画したものです:

株価チャートの作成
株価チャートは、始値・高値・安値・終値といった金融データを表示し、市場のトレンドやボラティリティを分析するのに役立ちます。投資家やアナリストが情報に基づいた意思決定を行うための重要な洞察を提供します。
この例は、4 系列(開‑高‑低‑終)の順序で 3 カテゴリを持つ OHLC(オープン・ハイ・ロー・クローズ)チャートを作成します。setUpDownBars で上下バーを有効化し、getHiLowLinesFormat で価格帯を示す高低線を制御します。個別シリーズの線と小さな水平グリッドラインは非表示にしています。
getUpDownBars が返すマネージャは、getUpBarsFormat と getDownBarsFormat を通じて別々の書式オブジェクトを公開します。各オブジェクトの getFill と getLine で塗りつぶしとアウトラインを個別に設定できます。この例では、上昇区間に暗い緑のアウトラインを持つ緑色バー、下降区間に暗い赤のアウトラインを持つオレンジ‑レッド バーを使用しています。
各カテゴリで 4 系列すべてに数值を設定し、高値と安値が開値と終値を包みます。バーは 同じカテゴリ内 で終値と開値を比較し、前のカテゴリとは比較しません。たとえば A は 72→25 で下落し、B は 25→38、C は 38→50 で上昇します。開値と終値が同じ場合は塗りつぶしの区間は表示されません。上下バーは開‑終の範囲、上下線は安‑高の範囲を示します。これらのバーはシリーズ グループに属し、通常の棒グラフ系列ではありません。
この書式は、少なくとも 2 系列が同一グループに属し、各カテゴリに対応する数値がある Line と LineWithMarkers 系列でも機能します。非スタック line 系列では、最初と最後の系列を比較して上下バーを作成します:最後の値が大きければ上バー、低ければ下バーです。系列の順序を入れ替えると分類も逆転します。以下の例は OpenHighLowClose を使用していますが、他の株価、スタック line、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 からエクスポート):

箱ひげ図の作成
箱ひげ図は、中央値、四分位数、外れ値などの主要統計指標を要約してデータ分布を示すのに使用されます。探索的データ分析や統計調査で、データの変動性を迅速に把握し、異常を特定するのに便利です。
この例は 6 つの値から箱ひげ図を作成します。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 の値に置き換え、更新されたプレゼンテーションを保存します。入力プレゼンテーションは少なくとも 1 スライドを含んでいる必要があります。
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();
}
結果:

サンバーストチャートの作成
サンバーストチャートは階層データを同心円状に表示し、部分と全体の関係を示します。入れ子になったカテゴリやサブカテゴリをコンパクトに表現するのに最適です。
この例は、8 つのリーフを 4 つのステムと 2 つのブランチにグループ化したサンバーストチャートを作成します。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 のモードで呼び出します。setBinWidth は ByBinWidth のみ、setNumberOfBins は ByNumberOfBins のみ適用されます。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 は前のビンに残ります。内部ビンは下限より大きく上限以下の値を含みます。

ビン数の指定
固定間隔ではなく一定の詳細度を求める場合は、同じデータでビンを 5 個に指定します。この例はアンダーフローとオーバーフローのビンを無効にしています。チャートはデータ範囲から幅を計算するため、レポートごとに境界が変わる可能性があります。
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();
}
5 ビンの個数は 4、4、4、4、1 です。上記の固定幅結果と比較してください:入力値は同じですが境界が異なります。

レーダーチャートの作成
レーダーチャートは多変量データを二次元で表示し、複数変数を同時に比較できるようにします。パフォーマンス指標や属性のパターン、強み、弱みを特定するのに特に役立ちます。
この例は 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();
}
結果:

マルチカテゴリチャートの作成
マルチカテゴリチャートは、複数のカテゴリ グループが絡むデータを表示し、複数の次元で値を比較できるようにします。複雑で多層的なデータセットのトレンドや関係性を分析する際に特に有用です。
この例は 4 ペアに配置された 8 カテゴリのクラスター化縦棒チャートを作成します。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 月のグルーピング レベルにアクセスし、deleteGroupingItem をレベル 1 で呼び出して四半期ラベルを削除します。レベル 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)が同じ順序で出力されます。quarters-updated.pptx を PowerPoint で比較すると、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 に変換したりすると、チャート領域は空白になります。同一スライドの他の形状には影響しません。コンビネーションチャートの作成
コンビネーション(コンボ)チャートは、1 つのグラフに 2 つ以上のチャートタイプを組み合わせます。このチャートを使えば、複数のデータセット間の差異や関係性をハイライト、比較、検証でき、相互の関係を把握しやすくなります。

この例は 4 カテゴリに対して 2 系列のクラスター化縦棒と 1 系列の折れ線を組み合わせます。縦棒はプライマリ 垂直軸を使用し、折れ線は 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」という名前のチャートを更新します。各系列は 3 つのデータ ポイントを持ち、カテゴリ ラベルは列 A、系列名は最初のシートの最初の行に配置されている必要があります。例では getCell を使ってワークブック セルを変更し、系列の値を更新し、3 番目の系列を追加し、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();
}
チャートのデータ範囲の設定
既存チャートで使用されている範囲を確認するには、Retrieve a Chart’s Data Range を参照してください。
Aspose.Slides for Android via Java は、ワークシートの特定範囲をチャート データのソースとして定義する柔軟性を提供します。これにより、ワークシートの一部をチャートに直接マッピングでき、どのセルが系列やカテゴリに寄与するかを制御できます。その結果、ワークシートの最新データ変更とチャートを簡単に同期でき、PowerPoint のプレゼンテーションが常に正確な情報を反映します。
この例は setRange を使用して、既存プレゼンテーションの最初のスライドにある「My chart」という名前のチャートのデータ ソースを Sheet1!A1:B4 に設定します。チャート ブックにはそのシートが存在し、1 行目に系列ヘッダー、列 A にカテゴリ ラベル、列 B に 3 つの値が入力された範囲が必要です。
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 を使用して、2 系列の折れ線と凡例を持つチャートを作成します。getMarker で取得したマーカー設定は、自動で割り当てられたマーカー記号を保持します。最初の系列は負の値と null の欠損値を含み、2 番目の系列はすべてのカテゴリに値を持ちます。
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 は豊富なカスタマイズ オプションを提供します。色、フォント、ラベル、凡例、その他の書式要素を変更して、チャートの外観を特定のデザイン要件に合わせて調整できます。