スパークラインと設定 3D 形式の使用
スパークラインの使用
Microsoft Excel 2010 では、これまで以上にさまざまな方法で情報を分析できます。ユーザーは、新しいデータ分析および視覚化ツールを使用して、重要なデータの傾向を追跡および強調できます。スパークラインは、同じテーブルでデータとグラフを表示できるように、セル内に配置できるミニ グラフです。スパークラインを適切に使用すると、データ分析がより迅速になり、より的確になります。また、情報のシンプルなビューを提供し、多くのビジーなチャートでワークシートが過密になるのを防ぎます。
Aspose.Cells は、スプレッドシートでスパークラインを操作するための API を提供します。
Microsoft Excel のスパークライン
Microsoft Excel 2010 でスパークラインを挿入するには:
- スパークラインを表示するセルを選択します。見やすくするには、データの横にあるセルを選択します。
- クリック入れるリボンで選択します桁の中にスパークライングループ。
- ソース データを含むワークシートのセル範囲を選択または入力します。チャートが表示されます。
スパークラインは、ソフトボール リーグの勝敗記録など、傾向を確認するのに役立ちます。スパークラインは、リーグの各チームのシーズン全体を合計することもできます。
Aspose.Cells を使用したスパークライン
開発者は、Aspose.Cells によって提供される API を使用して、(テンプレート ファイル内の) スパークラインを作成、削除、または読み取ることができます。スパークラインを管理するクラスは、Aspose.Cells.Chartsこれらの機能を使用する前に、この名前空間をインポートする必要があります。
特定のデータ範囲にカスタム グラフィックを追加することにより、開発者は選択したセル領域にさまざまな種類の小さなグラフを自由に追加できます。
以下の例は、スパークライン機能を示しています。この例は、次の方法を示しています。
- シンプルなテンプレート ファイルを開きます。
- ワークシートのスパークライン情報を読み取ります。
- 特定のデータ範囲の新しいスパークラインをセル領域に追加します。
- Excel ファイルをディスクに保存します。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// Instantiate a Workbook | |
// Open a template file | |
Workbook book = new Workbook("Source.xlsx"); | |
// Get the first worksheet | |
Worksheet sheet = book.getWorksheets().get(0); | |
// Use the following lines if you need to read the Sparklines | |
// Read the Sparklines from the template file (if it has) | |
for(SparklineGroup g : (Iterable<SparklineGroup>)sheet.getSparklineGroupCollection()) | |
{ | |
// Display the Sparklines group information e.g type, number of sparklines items | |
System.out.println("sparkline group: type:" + g.getType() + ", sparkline items count:" + g.getSparklineCollection().getCount()); | |
for (Sparkline s: (Iterable<Sparkline>)g.getSparklineCollection()) | |
{ | |
// Display the individual Sparkines and the data ranges | |
System.out.println("sparkline: row:" + s.getRow() + ", col:" + s.getColumn() + ", dataRange:" + s.getDataRange()); | |
} | |
} | |
// Add Sparklines | |
// Define the CellArea D2:D10 | |
CellArea ca = new CellArea(); | |
ca.StartColumn = 4; | |
ca.EndColumn = 4; | |
ca.StartRow = 1; | |
ca.EndRow = 7; | |
// Add new Sparklines for a data range to a cell area | |
int idx = sheet.getSparklineGroupCollection().add(SparklineType.COLUMN, "Sheet1!B2:D8", false, ca); | |
SparklineGroup group = sheet.getSparklineGroupCollection().get(idx); | |
// Create CellsColor | |
CellsColor clr = book.createCellsColor(); | |
clr.setColor(Color.getOrange()); | |
group.setSeriesColor (clr); | |
// Save the workbook | |
book.save("output.xlsx"); |
3D フォーマットの設定
シナリオの結果だけを取得できるように、3D チャート スタイルが必要になる場合があります。 Aspose.Cells は、Microsoft Excel 2007 3D フォーマットを適用するための関連する API を提供します。
グラフを作成して Microsoft Excel 2007 3D フォーマットを適用する方法を示す完全な例を以下に示します。サンプル コードを実行すると、縦棒グラフ (3D 効果付き) がワークシートに追加されます。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// Instantiate a new Workbook | |
Workbook book = new Workbook(); | |
// Add a Data Worksheet | |
Worksheet dataSheet = book.getWorksheets().add("DataSheet"); | |
// Add Chart Worksheet | |
Worksheet sheet = book.getWorksheets().add("MyChart"); | |
// Put some values into the cells in the data worksheet | |
dataSheet.getCells().get("B1").putValue(1); | |
dataSheet.getCells().get("B2").putValue(2); | |
dataSheet.getCells().get("B3").putValue(3); | |
dataSheet.getCells().get("A1").putValue("A"); | |
dataSheet.getCells().get("A2").putValue("B"); | |
dataSheet.getCells().get("A3").putValue("C"); | |
// Define the Chart Collection | |
ChartCollection charts = sheet.getCharts(); | |
// Add a Column chart to the Chart Worksheet | |
int chartSheetIdx = charts.add(ChartType.COLUMN, 5, 0, 25, 15); | |
// Get the newly added Chart | |
Chart chart = book.getWorksheets().get(2).getCharts().get(0); | |
// Set the background/foreground color for PlotArea/ChartArea | |
chart.getPlotArea().getArea().setBackgroundColor(Color.getWhite()); | |
chart.getChartArea().getArea().setBackgroundColor(Color.getWhite()); | |
chart.getPlotArea().getArea().setForegroundColor(Color.getWhite()); | |
chart.getChartArea().getArea().setForegroundColor(Color.getWhite()); | |
// Hide the Legend | |
chart.setShowLegend (false); | |
// Add Data Series for the Chart | |
chart.getNSeries().add("DataSheet!B1:B3", true); | |
// Specify the Category Data | |
chart.getNSeries().setCategoryData("DataSheet!A1:A3"); | |
// Get the Data Series | |
Series ser = chart.getNSeries().get(0); | |
// Apply the 3-D formatting | |
ShapePropertyCollection spPr = ser.getShapeProperties(); | |
Format3D fmt3d = spPr.getFormat3D(); | |
// Specify Bevel with its height/width | |
Bevel bevel = fmt3d.getTopBevel(); | |
bevel.setType(BevelPresetType.CIRCLE); | |
bevel.setHeight(2); | |
bevel.setWidth(5); | |
// Specify Surface material type | |
fmt3d.setSurfaceMaterialType (PresetMaterialType.WARM_MATTE); | |
// Specify surface lighting type | |
fmt3d.setSurfaceLightingType(LightRigType.THREE_POINT); | |
// Specify lighting angle | |
fmt3d.setLightingAngle(0); | |
// Specify Series background/foreground and line color | |
ser.getArea().setBackgroundColor(Color.getMaroon()); | |
ser.getArea().setForegroundColor(Color.getMaroon()); | |
ser.getBorder().setColor(Color.getMaroon()); | |
// Save the Excel file | |
book.save("3d_format.out.xlsx"); |