blazor-devexpress-dot-blazor-dot-dxsparkline-dot-exporttoasync-x28-system-dot-string-devexpress-dot-blazor-dot-dataexportformat-x29.md
Exports sparkline data to a file in the specified format.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
public ValueTask ExportToAsync(
string fileName,
DataExportFormat format = DataExportFormat.Png
)
| Name | Type | Description |
|---|---|---|
| fileName | String |
The name of the exported file.
|
| Name | Type | Default | Description |
|---|---|---|---|
| format | DataExportFormat | Png |
The format of the exported file.
|
| Type | Description |
|---|---|
| ValueTask |
A structure that stores an awaitable result of an asynchronous operation.
|
Call the ExportToAsync() method to export sparkline data to a file in the specified format: PNG, PDF, JPEG, or SVG.
The following code snippet displays a custom Export to PDF button that exports component data to a PDF file. The button appears after the Sparkline is completely loaded. For demo purposes, the example imitates a time-consuming operation.
<DxSparkline Data="@DataSource"
@ref=@Sparkline
ArgumentFieldName="Month"
ValueFieldName="VisitorCount"
Rendered="@SparklineRendered"
Height="50px"
Width="200px">
</DxSparkline>
<DxButton Text="Export to PDF" Visible="@buttonVisible" Click="ExportToPdf" />
@code {
bool buttonVisible;
DxSparkline Sparkline;
IEnumerable<SparklineDataPoint> DataSource = Enumerable.Empty<SparklineDataPoint>();
protected override void OnInitialized() {
DataSource = GenerateData();
}
async Task SparklineRendered() {
await Task.Delay(2000);
buttonVisible = true;
}
async Task ExportToPdf () {
await Sparkline.ExportToAsync("Custom file", DataExportFormat.Pdf);
}
}
public List<SparklineDataPoint> GenerateData() {
return new List<SparklineDataPoint>() {
new SparklineDataPoint( 01, 2132),
new SparklineDataPoint( 02, 2103),
new SparklineDataPoint( 03, 2210),
new SparklineDataPoint( 04, 2152),
new SparklineDataPoint( 05, 2062),
new SparklineDataPoint( 06, 1954),
new SparklineDataPoint( 07, 2112),
new SparklineDataPoint( 08, 1967),
new SparklineDataPoint( 09, 2009),
new SparklineDataPoint( 10, 2087),
new SparklineDataPoint( 11, 2112),
new SparklineDataPoint( 12, 2038),
};
}
public class SparklineDataPoint {
public int Month { get; set; }
public int? VisitorCount { get; set; }
public SparklineDataPoint(int month, int? visitorCount) {
Month = month;
VisitorCount = visitorCount;
}
}
See Also