Rappresentazione del grafico

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, ilGrafico classe ha espostoImmaginare & ToPdfmetodi con una verità di sovraccarichi per soddisfare al meglio i requisiti dell’applicazione.

Rendering di grafici in immagini

IlChart.ToImage & ToPdf Il metodo 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.ToImagemetodo come segue.

// 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);

È 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 diImageOrPrintOptions, pur consentendo di specificare parametri come risoluzione, modalità di smoothing, formato dell’immagine e così via.

// 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);

Grafico di rendering a PDF

Per eseguire il rendering del grafico nel formato PDF, le API Aspose.Cells hanno esposto ilGrafico.ToPdfmetodo con la possibilità di memorizzare il risultante PDF sul percorso 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");

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**Colonna Supportato** 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

Argomenti avanzati