Diagrammdarstellung
Diagramme rendern
Aspose.Cells-APIs unterstützen die Konvertierung der Excel-Diagramme in Bilder und PDF-Formate, ohne dass zusätzliche Tools oder Anwendungen erforderlich sind. Um Rendering-Unterstützung bereitzustellen, wird dieDiagramm Klasse hat ausgesetztVorstellen & ZuPdfMethoden mit einer Vielzahl von Überladungen, um den Anwendungsanforderungen am besten zu entsprechen.
Rendern von Diagrammen in Bilder
DasChart.ToImage & ZuPdf -Methode verfügt über eine Vielzahl von Überladungen, um sowohl einfaches als auch erweitertes Rendern zu unterstützen. Wenn die Anforderung der Anwendung darin besteht, das Diagramm in seinen Standardabmessungen zu rendern, empfehlen wir Ihnen, die zu verwendenChart.ToImageMethode wie folgt.
// 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); |
Es ist auch möglich, die Diagramme mit erweiterten Einstellungen in Bilder zu rendern. Aspose.Cells APIs haben eine überladene Version von verfügbar gemachtChart.ToImage Methode, die eine Instanz von akzeptieren könnteImageOrPrintOptions, während Parameter wie Auflösung, Glättungsmodus, Bildformat usw. festgelegt werden können.
// 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); |
Rendering-Diagramm bis PDF
Um das Diagramm in das PDF-Format zu rendern, haben die Aspose.Cells-APIs dieChart.ToPdfMethode mit der Möglichkeit, das Ergebnis PDF auf dem Disc-Pfad oder Stream zu speichern.
// 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"); |
Unterstützte Diagrammtypen für das Rendern
Es gibt einige Diagrammtypen, die derzeit nicht für das Rendern unterstützt werden. Solche Diagrammtypen enthalten** N** im**Spalte „Unterstützt**“ der folgenden Tabelle.
Diagramm Typ | Diagrammuntertyp | Unterstützt |
---|---|---|
Spalte | Spalte | Y |
Spalte gestapelt | Y | |
Spalte 100 Prozent gestapelt | Y | |
Column3DClustered | Y | |
Column3DStacked | Y | |
Column3D100PercentStacked | Y | |
Spalte3D | Y | |
Bar | Bar | Y |
BarStacked | Y | |
Balken 100 Prozent gestapelt | Y | |
Bar3DClustered | Y | |
Bar3DStacked | Y | |
Bar3D100PercentStacked | Y | |
Linie | Linie | Y |
LineStacked | Y | |
Zeile 100 Prozent gestapelt | Y | |
LineWithDataMarkers | Y | |
LineStackedWithDataMarkers | Y | |
Line100PercentStackedWithDataMarkers | Y | |
Line3D | Y | |
Kuchen | Kuchen | Y |
Pie3D | Y | |
PiePie | Y | |
Kuchenexplodiert | Y | |
Pie3D Explodiert | Y | |
PieBar | Y | |
Streuen | Streuen | Y |
ScatterConnectedByCurvesWithDataMarker | Y | |
ScatterConnectedByCurvesWithoutDataMarker | Y | |
ScatterConnectedByLinesWithDataMarker | Y | |
ScatterConnectedByLinesWithoutDataMarker | Y | |
Bereich | Bereich | Y |
BereichStacked | Y | |
Area100ProcentStacked | Y | |
Bereich3D | Y | |
Area3DStacked | Y | |
Area3D100ProzentStacked | Y | |
Krapfen | Krapfen | Y |
Donut Explodiert | Y | |
Radar | Radar | Y |
RadarWithDataMarkers | Y | |
Radargefüllt | Y | |
Oberfläche | Surface3D | N |
SurfaceWireframe3D | N | |
Oberflächenkontur | N | |
SurfaceContourWireframe | N | |
Blase | Blase | Y |
Bubble3D | N | |
Aktie | StockHighLowClose | Y |
StockOpenHighLowClose | Y | |
StockVolumeHighLowClose | Y | |
StockVolumeOpenHighLowClose | Y | |
Zylinder | Zylinder | Y |
Zylinder gestapelt | Y | |
Zylinder 100 Prozent gestapelt | Y | |
Zylindrischer Stab | Y | |
ZylindrischBarStacked | Y | |
ZylindrischBar100ProzentGestapelt | Y | |
ZylindrischeSäule3D | Y | |
Kegel | Kegel | Y |
Kegelgestapelt | Y | |
Kegel 100 Prozent gestapelt | Y | |
Konische Stange | Y | |
ConicalBarStacked | Y | |
ConicalBar100ProcentStacked | Y | |
KonischeSäule3D | Y | |
Pyramide | Pyramide | Y |
PyramidStacked | Y | |
Pyramid100Prozent gestapelt | Y | |
PyramidBar | Y | |
PyramidBarStacked | Y | |
PyramidBar100PercentStacked | Y | |
PyramidColumn3D | Y | |
BoxWhisker | BoxWhisker | Y |
Trichter | Trichter | Y |
ParetoLine | ParetoLine | Y |
Sonnendurchbruch | Sonnendurchbruch | Y |
Baumkarte | Baumkarte | Y |
Wasserfall | Wasserfall | Y |
Histogramm | Histogramm | Y |
Karte | Karte | N |