Rappresentazione del grafico
Creazione di grafici
Aspose.Cells Le API supportano la creazione di una verità di grafici Excel come dettagliato nell’argomentoCreazione e personalizzazione di grafici Excel. Per dimostrare l’utilizzo delle API Aspose.Cells per il rendering dei grafici in formato immagine e PDF, creeremo un grafico di tipo Colonna come da seguente frammento.
// 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."); |
Grafici di rendering
Le API Aspose.Cells supportano la conversione dei grafici Excel in immagini e formati PDF senza richiedere strumenti o applicazioni aggiuntivi. Al fine di fornire supporto per il rendering, ilGraficoclasse ha espostoimmaginare & toPdf metodi con una verità di sovraccarichi per soddisfare al meglio i requisiti dell’applicazione.
Rendering di grafici in immagini
IlChart.toImage ha una verità di sovraccarichi per supportare il rendering semplice e avanzato. Se il requisito dell’applicazione è quello di visualizzare il grafico nelle sue dimensioni predefinite, ti suggeriamo di utilizzare il fileChart.toImage metodo come segue.
// 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()); |
È anche possibile eseguire il rendering dei grafici in immagini con impostazioni avanzate. Aspose.Cells Le API hanno esposto una versione di sovraccarico diChart.toImage metodo che potrebbe accettare un’istanza diImageOrPrintOptionspur consentendo di specificare parametri come risoluzione, suggerimenti di rendering, formato immagine e così via.
// 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); |
Grafico di rendering a PDF
Per eseguire il rendering del grafico nel formato PDF, le API Aspose.Cells hanno esposto ilGrafico.toPdf con la possibilità di memorizzare il risultante PDF sul percorso del disco o un’istanza di 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"); |
Tipi di grafici supportati per il rendering
Esistono alcuni tipi di grafici che attualmente non sono supportati per il rendering. Tali tipi di grafici contengono** Ni** nel**Supportato** colonna della tabella sottostante.
Tipo di grafico | Sottotipo grafico | Supportato |
---|---|---|
Colonna | Colonna | S |
ColonnaImpilato | S | |
Column100PercentStacked | S | |
Column3DClustered | S | |
Column3DStacked | S | |
Column3D100Percent Stacked | S | |
Colonna 3D | S | |
Sbarra | Sbarra | S |
Bar Stacked | S | |
Bar100Percent Stacked | S | |
Bar3DClustered | S | |
Bar3DSimpilato | S | |
Bar3D100Percent Stacked | S | |
Linea | Linea | S |
LineImpilato | S | |
Riga100Percent Stacked | S | |
LineWithDataMarkers | S | |
LineStackedWithDataMarkers | S | |
Line100PercentStackedWithDataMarkers | S | |
Linea3D | S | |
Torta | Torta | S |
Pie3D | S | |
PiePie | S | |
Torta Esplosa | S | |
Pie3DEsploso | S | |
PieBar | S | |
Disperdere | Disperdere | S |
ScatterConnectedByCurvesWithDataMarker | S | |
ScatterConnectedByCurvesWithoutDataMarker | S | |
ScatterConnectedByLinesWithDataMarker | S | |
ScatterConnectedByLinesWithoutDataMarker | S | |
La zona | La zona | S |
Area Stacked | S | |
Area100Percent Stacked | S | |
Area3D | S | |
Area3DSimpilato | S | |
Area3D100Percentuale impilata | S | |
Ciambella | Ciambella | S |
Ciambella Esploso | S | |
Radar | Radar | S |
RadarConMarcatoriDati | S | |
RadarRiempito | S | |
Superficie | Superficie3D | N |
SuperficieWireframe3D | N | |
SuperficieContorno | N | |
SuperficieContornoWireframe | N | |
Bolla | Bolla | S |
Bolla3D | N | |
Azione | MagazzinoAltoBassoChiudi | S |
StockOpenHighLowClose | S | |
MagazzinoVolumeAltoBassoChiudi | S | |
MagazzinoVolumeApriAltoBassoChiudi | S | |
Cilindro | Cilindro | S |
CilindroImpilato | S | |
Cilindro impilato al 100%. | S | |
Barra cilindrica | S | |
Barra Cilindrica Impilata | S | |
Barra cilindrica100% impilata | S | |
Colonna cilindrica 3D | S | |
Cono | Cono | S |
ConoImpilato | S | |
Cono100Percent Stacked | S | |
Barra conica | S | |
ConicalBarImpilato | S | |
ConicalBar100PercentStacked | S | |
Colonna conica 3D | S | |
Piramide | Piramide | S |
Piramide Impilata | S | |
Pyramid100Percent Stacked | S | |
PyramidBar | S | |
PyramidBar Impilato | S | |
PyramidBar100Percent Stacked | S | |
Piramide Colonna 3D | S | |
BoxWhisker | BoxWhisker | Y |
Imbuto | Imbuto | S |
Linea di Pareto | Linea di Pareto | S |
Sprazzo di sole | Sprazzo di sole | S |
Mappa ad albero | Mappa ad albero | S |
Cascata | Cascata | S |
Istogramma | Istogramma | Y |
Carta geografica | Carta geografica | N |