Representación de gráficos
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áfico la clase ha expuestoA la imagen & A PDFmé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 & A PDF El método 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.ToImagemétodo como sigue.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a new worksheet to the Workbook | |
int sheetIndex = workbook.Worksheets.Add(); | |
// Obtaining the reference of the newly added worksheet by passing its index to WorksheetCollection | |
Worksheet worksheet = workbook.Worksheets[sheetIndex]; | |
// Adding sample values to cells | |
worksheet.Cells["A1"].PutValue(50); | |
worksheet.Cells["A2"].PutValue(100); | |
worksheet.Cells["A3"].PutValue(150); | |
worksheet.Cells["B1"].PutValue(4); | |
worksheet.Cells["B2"].PutValue(20); | |
worksheet.Cells["B3"].PutValue(50); | |
// Adding a chart to the worksheet | |
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 5, 0, 15, 5); | |
// Accessing the instance of the newly added chart | |
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex]; | |
// Adding Series Collection (chart data source) to the chart ranging from "A1" cell to "B3" | |
chart.NSeries.Add("A1:B3", true); | |
// Converting chart to image | |
chart.ToImage(dataDir + "chartEMF_out.emf", ImageType.Emf); | |
// Converting chart to Bitmap | |
System.Drawing.Bitmap bitmap = chart.ToImage(); | |
bitmap.Save(dataDir + "chartBMP_out.bmp", System.Drawing.Imaging.ImageFormat.Bmp); |
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 deImageOrPrintOptions, al tiempo que permite especificar parámetros como resolución, modo de suavizado, formato de imagen, etc.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a new worksheet to the Workbook | |
int sheetIndex = workbook.Worksheets.Add(); | |
// Obtaining the reference of the newly added worksheet by passing its index to WorksheetCollection | |
Worksheet worksheet = workbook.Worksheets[sheetIndex]; | |
// Adding sample values to cells | |
worksheet.Cells["A1"].PutValue(50); | |
worksheet.Cells["A2"].PutValue(100); | |
worksheet.Cells["A3"].PutValue(150); | |
worksheet.Cells["B1"].PutValue(4); | |
worksheet.Cells["B2"].PutValue(20); | |
worksheet.Cells["B3"].PutValue(50); | |
// Adding a chart to the worksheet | |
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 5, 0, 15, 5); | |
// Accessing the instance of the newly added chart | |
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex]; | |
// Adding Series Collection (chart data source) to the chart ranging from "A1" cell to "B3" | |
chart.NSeries.Add("A1:B3", true); | |
// Create an instance of ImageOrPrintOptions and set a few properties | |
ImageOrPrintOptions options = new ImageOrPrintOptions() | |
{ | |
VerticalResolution = 300, | |
HorizontalResolution = 300, | |
SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias | |
}; | |
// Convert chart to image with additional settings | |
chart.ToImage(dataDir + "chartPNG_out.png", options); |
Tabla de renderizado al PDF
Para representar el gráfico en el formato PDF, las API Aspose.Cells han expuesto elGráfico.ToPdfmétodo con la capacidad de almacenar el PDF resultante en la ruta del disco o Stream.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a new worksheet to the Workbook | |
int sheetIndex = workbook.Worksheets.Add(); | |
// Obtaining the reference of the newly added worksheet by passing its index to WorksheetCollection | |
Worksheet worksheet = workbook.Worksheets[sheetIndex]; | |
// Adding sample values to cells | |
worksheet.Cells["A1"].PutValue(50); | |
worksheet.Cells["A2"].PutValue(100); | |
worksheet.Cells["A3"].PutValue(150); | |
worksheet.Cells["B1"].PutValue(4); | |
worksheet.Cells["B2"].PutValue(20); | |
worksheet.Cells["B3"].PutValue(50); | |
// Adding a chart to the worksheet | |
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 5, 0, 15, 5); | |
// Accessing the instance of the newly added chart | |
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex]; | |
// Adding Series Collection (chart data source) to the chart ranging from "A1" cell to "B3" | |
chart.NSeries.Add("A1:B3", true); | |
// Converting chart to PDF | |
chart.ToPdf(dataDir + "chartPDF_out.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 |