Grafik Rendeleme
Grafikler Oluşturma
Aspose.Cells API’leri, Excel Grafikleri Oluşturma ve Özelleştirme başlığı altında detaylı olarak açıklanan çeşitli Excel grafiklerini oluşturmayı destekler. Aspose.Cells API’lerinin kullanımını göstermek için, resim ve PDF formatında grafikleri oluşturacak olan bir sütun tipinde bir grafik oluşturacağız.
// 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."); |
Grafikleri Oluşturma
Aspose.Cells API’leri, ek araç veya uygulamalar gerekmeden Excel Grafiklerini görüntü ve PDF formatına dönüştürmeyi destekler. Rendeleme desteği sağlamak için, Chart sınıfı çeşitli aşırı yüklemelerle toImage ve toPdf yöntemlerini sunmuştur bu, uygulama gereksinimlerine en uygun hale getirebilmek için.
Grafikleri Görüntüye Dönüştürme
Chart.toImage yöntemi, basit ve gelişmiş renderelemeyi desteklemek için çeşitli aşırı yüklemelere sahiptir. Uygulama gereksinimi grafikleri varsayılan boyutlarında rendere etmekse, aşağıdaki Chart.toImage yöntemini kullanmanızı öneririz.
// 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()); |
Ayrıca, gelişmiş ayarlarla grafikleri görüntülemek de mümkündür. Aspose.Cells API’leri, aşırı yüklemeli bir Chart.toImage yöntemini sunmuştur ve bu yöntem, çözünürlük, rendereleme ipuçları, görüntü formatı vb. gibi parametreleri belirtmenizi sağlayan bir ImageOrPrintOptions örneğini kabul edebilir.
// 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); |
Grafiği PDF’ye Dönüştürme
Grafiğin PDF formatına rendeleme yapmak için Aspose.Cells API’leri, sonucu diske veya OutputStream örneğine kaydetme yeteneğine sahip Chart.toPdf yöntemi sunmuştur.
// 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"); |
Görüntüleme için Desteklenen Grafik Türleri
Şu anda desteklenmeyen birkaç grafik türü bulunmaktadır. Bu tür grafik tipleri aşağıdaki tablonun Desteklenen sütununda N içerir.
Grafik türü | Grafik alt türü | Desteklenen |
---|---|---|
Column | Column | Y |
ColumnStacked | Y | |
Column100PercentStacked | Y | |
Column3DClustered | Y | |
Column3DStacked | Y | |
Column3D100PercentStacked | Y | |
Column3D | Y | |
Bar | Bar | Y |
BarStacked | Y | |
Bar100PercentStacked | Y | |
Bar3DClustered | Y | |
Bar3DStacked | Y | |
Bar3D100PercentStacked | Y | |
Line | Line | Y |
LineStacked | Y | |
Line100PercentStacked | Y | |
LineWithDataMarkers | Y | |
LineStackedWithDataMarkers | Y | |
Line100PercentStackedWithDataMarkers | Y | |
Line3D | Y | |
Pie | Pie | Y |
Pie3D | Y | |
PiePie | Y | |
PieExploded | Y | |
Pie3DExploded | Y | |
PieBar | Y | |
Scatter | Scatter | Y |
ScatterConnectedByCurvesWithDataMarker | Y | |
ScatterConnectedByCurvesWithoutDataMarker | Y | |
ScatterConnectedByLinesWithDataMarker | Y | |
ScatterConnectedByLinesWithoutDataMarker | Y | |
Area | Area | Y |
AreaStacked | Y | |
Area100PercentStacked | Y | |
Area3D | Y | |
Area3DStacked | Y | |
Area3D100PercentStacked | Y | |
Doughnut | Doughnut | Y |
DoughnutExploded | Y | |
Radar | Radar | Y |
RadarWithDataMarkers | Y | |
RadarFilled | Y | |
Surface | Surface3D | N |
SurfaceWireframe3D | N | |
SurfaceContour | N | |
SurfaceContourWireframe | N | |
Bubble | Bubble | Y |
Bubble3D | N | |
Stock | StockHighLowClose | Y |
StockOpenHighLowClose | Y | |
StockVolumeHighLowClose | Y | |
StockVolumeOpenHighLowClose | Y | |
Cylinder | Cylinder | Y |
CylinderStacked | Y | |
Cylinder100PercentStacked | Y | |
CylindricalBar | Y | |
CylindricalBarStacked | Y | |
CylindricalBar100PercentStacked | Y | |
CylindricalColumn3D | Y | |
Cone | Cone | Y |
ConeStacked | Y | |
Cone100PercentStacked | Y | |
ConicalBar | Y | |
ConicalBarStacked | Y | |
ConicalBar100PercentStacked | Y | |
ConicalColumn3D | Y | |
Pyramid | Pyramid | Y |
PyramidStacked | Y | |
Pyramid100PercentStacked | Y | |
PyramidBar | Y | |
PyramidBarStacked | Y | |
PyramidBar100PercentStacked | Y | |
PyramidColumn3D | Y | |
BoxWhisker | BoxWhisker | Y |
Funnel | Funnel | Y |
ParetoLine | ParetoLine | Y |
Sunburst | Sunburst | Y |
Treemap | Treemap | Y |
Waterfall | Waterfall | Y |
Histogram | Histogram | Y |
Map | Map | N |