Diagramrendering
Återgivning av diagram
Aspose.Cells API:er stöder för att konvertera Excel-diagram till bilder och PDF-format utan att behöva några ytterligare verktyg eller applikationer. För att ge renderingsstöd,Diagram klass har avslöjatAtt föreställa sig & Till pdfmetoder med en sanning av överbelastningar för att bäst passa applikationskraven.
Återge diagram till bilder
DeChart.ToImage & Till pdf Metoden har en sanning av överbelastningar för att stödja enkel såväl som avancerad rendering. Om applikationskravet är att återge diagrammet i dess standarddimensioner, föreslår vi att du använderChart.ToImagemetod enligt följande.
// 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); |
Det är också möjligt att rendera diagrammen till bilder med avancerade inställningar. Aspose.Cells API:er har avslöjat en överbelastningsversion avChart.ToImage metod som skulle kunna acceptera en instans avImageOrPrintOptions, samtidigt som du tillåter att ange parametrar som upplösning, utjämningsläge, bildformat och så vidare.
// 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); |
Återgivningsdiagram till PDF
För att återge diagrammet till PDF-formatet har API:erna Aspose.Cells exponeratChart.ToPdfmetod med förmågan att lagra den resulterande PDF på skivväg eller 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"); |
Sjökortstyper som stöds för rendering
Det finns några diagramtyper som för närvarande inte stöds för rendering. Sådana diagramtyper innehåller** N** i**Stöds** kolumn i tabellen nedan.
Diagramtyp | Diagram undertyp | Stöds |
---|---|---|
Kolumn | Kolumn | Y |
KolumnStackad | Y | |
Kolumn100ProcentStackad | Y | |
Kolumn3DClustrerad | Y | |
Kolumn3DStackad | Y | |
Kolumn3D100PercentStacked | Y | |
Kolumn 3D | Y | |
Bar | Bar | Y |
BarStacked | Y | |
Bar100PercentStacked | Y | |
Bar3DClustered | Y | |
Bar3DStacked | Y | |
Bar3D100PercentStacked | Y | |
Linje | Linje | Y |
LineStacked | Y | |
Line100PercentStacked | Y | |
LineWithDataMarkers | Y | |
LineStackedWithDataMarkers | Y | |
Line100PercentStackedWithDataMarkers | Y | |
Line3D | Y | |
Paj | Paj | Y |
Pie3D | Y | |
PiePie | Y | |
PieExploderade | Y | |
Pie3DE exploderade | Y | |
PieBar | Y | |
Sprida ut | Sprida ut | Y |
ScatterConnectedByCurvesWithDataMarker | Y | |
ScatterConnectedByCurvesWithoutDataMarker | Y | |
ScatterConnectedByLinesWithDataMarker | Y | |
ScatterConnectedByLinesWithoutDataMarker | Y | |
Område | Område | Y |
AreaStacked | Y | |
Area100PercentStacked | Y | |
Area3D | Y | |
Area3DStacked | Y | |
Area3D100PercentStacked | Y | |
Munk | Munk | Y |
Doughnut Exploderade | Y | |
Radar | Radar | Y |
RadarWithDataMarkers | Y | |
Radarfylld | Y | |
Yta | Surface3D | N |
SurfaceWireframe3D | N | |
Ytkontur | N | |
SurfaceContourWireframe | N | |
Bubbla | Bubbla | Y |
Bubble3D | N | |
Stock | StockHighLowClose | Y |
LagerÖppnaHögLågStäng | Y | |
LagervolymHögLågStäng | Y | |
Lagervolym ÖppenHögLågStäng | Y | |
Cylinder | Cylinder | Y |
CylinderStacked | Y | |
Cylinder100PercentStacked | Y | |
Cylindrical Bar | Y | |
CylindricalBarStacked | Y | |
CylindricalBar100PercentStacked | Y | |
CylindricalColumn3D | Y | |
Kon | Kon | Y |
ConeStacked | Y | |
Cone100PercentStacked | Y | |
ConicalBar | Y | |
ConicalBarStacked | Y | |
ConicalBar100PercentStacked | Y | |
Konisk kolumn3D | Y | |
Pyramid | Pyramid | Y |
PyramidStackad | Y | |
Pyramid100ProcentStacked | Y | |
PyramidBar | Y | |
PyramidBarStacked | Y | |
PyramidBar100PercentStacked | Y | |
PyramidColumn3D | Y | |
BoxWhisker | BoxWhisker | Y |
Tratt | Tratt | Y |
ParetoLine | ParetoLine | Y |
Sunburst | Sunburst | Y |
Trädkarta | Trädkarta | Y |
Vattenfall | Vattenfall | Y |
Histogram | Histogram | Y |
Karta | Karta | N |