チャートのレンダリング
チャートの作成
Aspose.Cells API は、トピックで詳述されているように、Excel チャートの真正性を作成することをサポートしますExcel チャートの作成とカスタマイズAspose.Cells API を使用して画像と PDF 形式でグラフをレンダリングする方法を示すために、次のスニペットに従って列タイプのグラフを作成します。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CreateChart.class) + "charts/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Obtaining the reference of the first worksheet | |
WorksheetCollection worksheets = workbook.getWorksheets(); | |
Worksheet sheet = worksheets.get(0); | |
// Adding some sample value to cells | |
Cells cells = sheet.getCells(); | |
Cell cell = cells.get("A1"); | |
cell.setValue(50); | |
cell = cells.get("A2"); | |
cell.setValue(100); | |
cell = cells.get("A3"); | |
cell.setValue(150); | |
cell = cells.get("B1"); | |
cell.setValue(4); | |
cell = cells.get("B2"); | |
cell.setValue(20); | |
cell = cells.get("B3"); | |
cell.setValue(50); | |
ChartCollection charts = sheet.getCharts(); | |
// Adding a chart to the worksheet | |
int chartIndex = charts.add(ChartType.PYRAMID, 5, 0, 15, 5); | |
Chart chart = charts.get(chartIndex); | |
// Adding NSeries (chart data source) to the chart ranging from "A1" | |
// cell to "B3" | |
SeriesCollection serieses = chart.getNSeries(); | |
serieses.add("A1:B3", true); | |
// Saving the Excel file | |
workbook.save(dataDir + "CreateChart_out.xls"); | |
// Print message | |
System.out.println("Workbook with chart is successfully created."); |
チャートのレンダリング
Aspose.Cells API は、Excel チャートを画像や PDF 形式に変換することをサポートしており、追加のツールやアプリケーションは必要ありません。レンダリングのサポートを提供するために、チャートクラスが暴露したtoImage & [PDFへ](https://reference.aspose.com/cells/java/com.aspose.cells/chart#toPdf(java.io.OutputStream)アプリケーションの要件に最適なオーバーロードの真正性を備えたメソッド。
グラフを画像にレンダリングする
のChart.toImage メソッドには、単純なレンダリングだけでなく高度なレンダリングもサポートするためのオーバーロードが多数あります。アプリケーション要件がグラフをデフォルトの寸法でレンダリングすることである場合は、Chart.toImage 方法は次のとおりです。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
//Converting chart to image | |
chart.toImage(dataDir + "chart.emf", ImageFormat.getEmf()); |
詳細設定を使用して、グラフを画像にレンダリングすることもできます。 Aspose.Cells API がオーバーロード バージョンを公開しました[Chart.toImage](https://reference.aspose.com/cells/java/com.aspose.cells/chart#toImage(java.io.OutputStream,%20com.aspose.cells.ImageOrPrintOptions) のインスタンスを受け入れることができるメソッドImageOrPrintOptions解像度、レンダリングのヒント、画像形式などのパラメータを指定できます。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CreateChart.class) + "charts/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Obtaining the reference of the first worksheet | |
WorksheetCollection worksheets = workbook.getWorksheets(); | |
Worksheet sheet = worksheets.get(0); | |
ChartCollection charts = sheet.getCharts(); | |
// Adding a chart to the worksheet | |
int chartIndex = charts.add(ChartType.PYRAMID, 5, 0, 15, 5); | |
Chart chart = charts.get(chartIndex); | |
// Create an instance of ImageOrPrintOptions and set a few properties | |
ImageOrPrintOptions options = new ImageOrPrintOptions(); | |
options.setVerticalResolution(300); | |
options.setHorizontalResolution(300); | |
options.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); | |
options.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); | |
// Convert chart to image with additional settings | |
chart.toImage(dataDir + "chart.png", options); |
PDF へのレンダリング チャート
グラフを PDF 形式でレンダリングするために、Aspose.Cells API はChart.toPdf メソッドを使用して、結果の PDF をディスク パスまたは OutputStream のインスタンスに格納できます。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
//Converting chart to PDF | |
chart.toPdf(dataDir + "chart.pdf"); |
レンダリングでサポートされているグラフの種類
現在、レンダリングがサポートされていないチャート タイプがいくつかあります。このようなチャート タイプには、次のものが含まれます。** N** の**下表の**列をサポート。
グラフの種類 | チャートのサブタイプ | 対応 |
---|---|---|
桁 | 桁 | はい |
積み上げ列 | はい | |
Column100PercentStacked | はい | |
列 3DClustered | はい | |
Column3D積み上げ | はい | |
Column3D100PercentStacked | はい | |
列 3D | はい | |
バー | バー | はい |
棒積み上げ | はい | |
Bar100Percent積み上げ | はい | |
Bar3DClustered | はい | |
Bar3D積み上げ | はい | |
Bar3D100PercentStacked | はい | |
ライン | ライン | はい |
LineStacked | はい | |
Line100PercentStacked | はい | |
LineWithDataMarkers | はい | |
LineStackedWithDataMarkers | はい | |
Line100PercentStackedWithDataMarkers | はい | |
Line3D | はい | |
パイ | パイ | はい |
Pie3D | はい | |
パイパイ | はい | |
パイ爆発 | はい | |
Pie3DExploded | はい | |
パイバー | はい | |
散布 | 散布 | はい |
ScatterConnectedByCurvesWithDataMarker | はい | |
ScatterConnectedByCurvesWithoutDataMarker | はい | |
ScatterConnectedByLinesWithDataMarker | はい | |
ScatterConnectedByLinesWithoutDataMarker | はい | |
範囲 | 範囲 | はい |
エリア積み上げ | はい | |
Area100PercentStacked | はい | |
エリア3D | はい | |
Area3D積み上げ | はい | |
Area3D100PercentStacked | はい | |
ドーナツ | ドーナツ | はい |
ドーナツ爆発 | はい | |
レーダー | レーダー | はい |
RadarWithDataMarkers | はい | |
レーダーいっぱい | はい | |
水面 | Surface3D | N |
SurfaceWireframe3D | N | |
表面輪郭 | N | |
SurfaceContourWireframe | N | |
バブル | バブル | はい |
バブル3D | N | |
ストック | 株価高低終値 | はい |
株式オープン高低クローズ | はい | |
在庫高低終値 | はい | |
在庫量OpenHighLowClose | はい | |
シリンダー | シリンダー | はい |
円柱積み上げ | はい | |
円柱 100%積み上げ | はい | |
円柱棒 | はい | |
円柱棒積み上げ | はい | |
CylindricalBar100PercentStacked | はい | |
円筒柱 3D | はい | |
円錐 | 円錐 | はい |
円錐積み上げ | はい | |
円錐 100% 積み上げ | はい | |
円錐バー | はい | |
円錐棒積み上げ | はい | |
ConicalBar100PercentStacked | はい | |
ConicalColumn3D | はい | |
ピラミッド | ピラミッド | はい |
ピラミッド積み上げ | はい | |
Pyramid100PercentStacked | はい | |
ピラミッドバー | はい | |
ピラミッド棒積み上げ | はい | |
PyramidBar100PercentStacked | はい | |
PyramidColumn3D | はい | |
箱ひげ | 箱ひげ | よ |
漏斗 | 漏斗 | はい |
パレートライン | パレートライン | はい |
サンバースト | サンバースト | はい |
ツリーマップ | ツリーマップ | はい |
滝 | 滝 | はい |
ヒストグラム | ヒストグラム | よ |
地図 | 地図 | な |