Representación de gráficos
Creación de gráficos
Aspose.Cells Compatibilidad con API para crear gráficos de Excel como se detalla en el temaCreación y personalización de gráficos de Excel. Para demostrar el uso de las API Aspose.Cells para representar los gráficos en formato de imagen y PDF, crearemos un gráfico de tipo Columna según el siguiente fragmento.
// 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."); |
Representación de gráficos
Aspose.Cells Compatibilidad con API para convertir los gráficos de Excel en imágenes y PDF formatos sin necesidad de herramientas o aplicaciones adicionales. Para proporcionar soporte de renderizado, elGráficola clase ha expuestoa la imagen & aPdf métodos con una gran cantidad de sobrecargas para adaptarse mejor a los requisitos de la aplicación.
Representación de gráficos en imágenes
ÉlChart.toImage tiene una gran cantidad de sobrecargas para admitir renderizado simple y avanzado. Si el requisito de la aplicación es representar el gráfico en sus dimensiones predeterminadas, le sugerimos que utilice elChart.toImage método de la siguiente manera.
// 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()); |
También es posible representar los gráficos en imágenes con configuraciones avanzadas. Aspose.Cells Las API han expuesto una versión sobrecargada deChart.toImage método que podría aceptar una instancia deImageOrPrintOptionsal tiempo que permite especificar parámetros como resolución, sugerencias de representación, formato de imagen, 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); |
Tabla de renderizado al PDF
Para representar el gráfico en el formato PDF, las API Aspose.Cells han expuesto elGráfico.aPdf con la capacidad de almacenar el PDF resultante en la ruta del disco o una instancia 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"); |
Tipos de gráficos admitidos para la representación
Hay algunos tipos de gráficos que actualmente no son compatibles con la representación. Dichos tipos de gráficos contienen** N** en el**Columna admitida** de la siguiente tabla.
Tipo de gráfico | Subtipo de gráfico | Soportado |
---|---|---|
Columna | Columna | Y |
Columna apilada | Y | |
Columna100PorcentajeApilado | Y | |
Columna 3D agrupada | Y | |
Columna3Dapilada | Y | |
Columna3D100PorcentajeApilado | Y | |
Columna3D | Y | |
Bar | Bar | Y |
Barra apilada | Y | |
Bar100Por CientoApilado | Y | |
Bar3D Agrupado | Y | |
Bar3DSapilado | Y | |
Bar3D100Por CientoApilado | Y | |
Línea | Línea | Y |
línea apilada | Y | |
Línea100PorcentajeApilado | Y | |
LíneaConMarcadoresDeDatos | Y | |
Línea apilada con marcadores de datos | Y | |
Línea100PorcentajeApiladoConMarcadoresDeDatos | Y | |
Línea3D | Y | |
Tarta | Tarta | Y |
Pie3D | Y | |
Pastel Pastel | Y | |
PastelExplotado | Y | |
Pie3DExplotado | Y | |
PieBar | Y | |
Dispersión | Dispersión | Y |
ScatterConnectedByCurvesWithDataMarker | Y | |
DispersiónConectadoPorCurvasSinMarcador de datos | Y | |
ScatterConnectedByLinesWithDataMarker | Y | |
ScatterConnectedByLinesWithoutDataMarker | Y | |
Zona | Zona | Y |
Área apilada | Y | |
Área100PorcentajeApilado | Y | |
Área3D | Y | |
Area3DSapilado | Y | |
Área3D100PorcentajeApilado | Y | |
Rosquilla | Rosquilla | Y |
RosquillaExplotó | Y | |
Radar | Radar | Y |
RadarConMarcadoresDeDatos | Y | |
Lleno de radar | Y | |
Superficie | Superficie3D | norte |
SuperficieAlambrado3D | norte | |
SuperficieContorno | norte | |
SuperficieContornoEstructura metálica | norte | |
Burbuja | Burbuja | Y |
Burbuja3D | norte | |
Existencias | InventarioAltoBajoCerrar | Y |
InventarioAbiertoAltoBajoCerrar | Y | |
InventarioVolumenAltoBajoCerrar | Y | |
StockVolumenAbiertoAltoBajoCerrar | Y | |
Cilindro | Cilindro | Y |
CilindroApilado | Y | |
Cilindro100PorcentajeApilado | Y | |
CilíndricoBar | Y | |
CilíndricoBarApilado | Y | |
CilíndricoBar100PorcentajeApilado | Y | |
CilíndricoColumna3D | Y | |
Cono | Cono | Y |
ConoApilado | Y | |
Cono100Por CientoApilado | Y | |
Barracónica | Y | |
Barra CónicaApilada | Y | |
CónicoBar100PorcentajeApilado | Y | |
ColumnaCónica3D | Y | |
Pirámide | Pirámide | Y |
Pirámide apilada | Y | |
Pirámide100Por CientoApilado | Y | |
PirámideBar | Y | |
PirámideBarApilado | Y | |
PirámideBar100PorcentajeApilado | Y | |
PirámideColumna3D | Y | |
cajabigotes | cajabigotes | Y |
Embudo | Embudo | Y |
Línea de Pareto | Línea de Pareto | Y |
rayos de sol | rayos de sol | Y |
Mapa de árbol | Mapa de árbol | Y |
Cascada | Cascada | Y |
Histograma | Histograma | Y |
Mapa | Mapa | NORTE |