Rendu graphique
Création de graphiques
Aspose.Cells Prise en charge des API pour créer une vérité de graphiques Excel comme détaillé sous le sujetCréation et personnalisation de graphiques Excel. Afin de démontrer l’utilisation des API Aspose.Cells pour rendre les graphiques au format image et PDF, nous allons créer un graphique de type Colonne selon l’extrait suivant.
// 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."); |
Graphiques de rendu
Prise en charge des API Aspose.Cells pour convertir les graphiques Excel en images et formats PDF sans nécessiter d’outils ou d’applications supplémentaires. Afin de fournir un support de rendu, leGraphiquela classe a exposéàImage & versPdf méthodes avec une multitude de surcharges pour répondre au mieux aux exigences de l’application.
Rendu des graphiques en images
LeChart.toImage a une vérité de surcharges pour prendre en charge le rendu simple et avancé. Si l’exigence de l’application est de rendre le graphique dans ses dimensions par défaut, nous vous suggérons d’utiliser leChart.toImage méthode comme suit.
// 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()); |
Il est également possible de rendre les graphiques en images avec des paramètres avancés. Aspose.Cells Les API ont exposé une version de surcharge deChart.toImage méthode qui pourrait accepter une instance deOptions d’image ou d’impressiontout en permettant de spécifier des paramètres tels que la résolution, les astuces de rendu, le format d’image, etc.
// 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); |
Tableau de rendu au PDF
Afin de rendre le graphique au format PDF, les API Aspose.Cells ont exposé leGraphique.toPdf méthode avec la possibilité de stocker le PDF résultant sur le chemin du disque ou une instance de 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"); |
Types de graphiques pris en charge pour le rendu
Il existe quelques types de graphiques qui ne sont actuellement pas pris en charge pour le rendu. Ces types de graphiques contiennent** N ** dans le**Colonne prise en charge** du tableau ci-dessous.
Type de graphique | Sous-type de graphique | Prise en charge |
---|---|---|
Colonne | Colonne | O |
Colonneempilée | O | |
Colonne100PercentStacked | O | |
Colonne3DCluster | O | |
Colonne3DSempilé | O | |
Column3D100PercentStacked | O | |
Colonne3D | O | |
Bar | Bar | O |
Barreempilée | O | |
Barre100PercentStacked | O | |
Bar3DCluster | O | |
Bar3DStacked | O | |
Barre3D100Pourcentage empilé | O | |
La ligne | La ligne | O |
Ligneempilée | O | |
Line100PercentStacked | O | |
LineWithDataMarkers | O | |
LineStackedWithDataMarkers | O | |
Line100PercentStackedWithDataMarkers | O | |
Ligne3D | O | |
Tarte | Tarte | O |
Pie3D | O | |
TarteTarte | O | |
TarteExplosée | O | |
Tarte3DÉclaté | O | |
PieBar | O | |
Dispersion | Dispersion | O |
ScatterConnectedByCurvesWithDataMarker | O | |
ScatterConnectedByCurvesWithoutDataMarker | O | |
ScatterConnectedByLinesWithDataMarker | O | |
ScatterConnectedByLinesWithoutDataMarker | O | |
Surface | Surface | O |
Zoneempilée | O | |
Area100PercentStacked | O | |
Zone3D | O | |
Area3DStacked | O | |
Area3D100PercentStacked | O | |
Donut | Donut | O |
BeignetÉclaté | O | |
Radar | Radar | O |
RadarAvecMarqueursDeDonnées | O | |
Radar Rempli | O | |
Surface | Surface3D | N |
SurfaceWireframe3D | N | |
Contour de surface | N | |
SurfaceContourWireframe | N | |
Bulle | Bulle | O |
Bulle3D | N | |
Stocker | StockHautBasFermer | O |
StockOuvertHautBasFermer | O | |
StockVolumeHautBasFermer | O | |
StockVolumeOuvertHautBasFermer | O | |
Cylindre | Cylindre | O |
CylindreEmpilé | O | |
Cylindre100PercentStacked | O | |
CylindriqueBar | O | |
CylindriqueBarEmpilés | O | |
CylindriqueBar100PercentStacked | O | |
CylindriqueColonne3D | O | |
Cône | Cône | O |
ConeStacked | O | |
Cône100PercentStacked | O | |
Barre conique | O | |
ConiqueBarEmpilés | O | |
ConicalBar100PercentStacked | O | |
ConicalColumn3D | O | |
Pyramide | Pyramide | O |
PyramideEmpilés | O | |
Pyramid100PercentStacked | O | |
PyramidBar | O | |
PyramideBarEmpilés | O | |
PyramidBar100PercentStacked | O | |
PyramideColonne3D | O | |
BoxWhisker | BoxWhisker | Oui |
Entonnoir | Entonnoir | O |
Ligne de Pareto | Ligne de Pareto | O |
Coup de soleil | Coup de soleil | O |
Treemap | Treemap | O |
Cascade | Cascade | O |
Histogramme | Histogramme | Oui |
Carte | Carte | N |