I am trying to see how I can convert a chart into an image that is in memory so that from a button click I can generate the content for an email.
The export function on the chart will download an image that looks correct but I cannot get access to this image from that method call.
@using Syncfusion.EJ2.Blazor.Charts
<div class="Row">
<div class="col-md-6">
<div class="control-section">
<EjsChart @ref="BurndownChart" Title="Sprint 2019.25 Burndown">
<ChartArea><ChartAreaBorder Width="0"></ChartAreaBorder></ChartArea>
<ChartPrimaryXAxis ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.DateTime" LabelFormat="dd-MM" IntervalType="IntervalType.Days" EdgeLabelPlacement="EdgeLabelPlacement.Shift">
<ChartAxisMajorGridLines Width="0"></ChartAxisMajorGridLines>
</ChartPrimaryXAxis>
<ChartPrimaryYAxis LabelFormat="{value}" RangePadding="ChartRangePadding.None" Minimum="0" Maximum="30" Interval="3">
<ChartAxisLineStyle Width="0"></ChartAxisLineStyle>
<ChartAxisMajorTickLines Width="0"></ChartAxisMajorTickLines>
</ChartPrimaryYAxis>
<ChartTooltipSettings Enable="true"></ChartTooltipSettings>
<ChartSeriesCollection>
<ChartSeries DataSource="@chartData" Name="Predicted" XName="xValue" Width="2"
Opacity="1" YName="PredictedBurndown" Type="ChartSeriesType.Line" Fill="Blue">
<ChartMarker Visible="true" Width="10" Height="10">
</ChartMarker>
</ChartSeries>
<ChartSeries DataSource="@chartData" Name="Actual" XName="xValue" Width="2" Fill="Orange"
Opacity="1" YName="ActualBurndown" Type="ChartSeriesType.Line">
<ChartMarker Visible="true" Width="10" Height="10">
</ChartMarker>
</ChartSeries>
<ChartSeries DataSource="@chartData" Name="Points Claimed" XName="xValue" Width="2"
Opacity="1" YName="PointsClaimed" Type="ChartSeriesType.Line" Fill="Black">
<ChartMarker Visible="true" Width="10" Height="10">
</ChartMarker>
</ChartSeries>
</ChartSeriesCollection>
</EjsChart>
</div>
</div>
<div class="col-md-6">
<button @onclick="Export">Export</button>
</div>
</div>
@code{
EjsChart BurndownChart;
public void Export()
{
BurndownChart.Export(ExportType.PNG, "pngImage");
}
public class LineChartData
{
public DateTime xValue { get; set; } //Date
public double PredictedBurndown { get; set; } // Predicted Burndown
public double? ActualBurndown { get; set; } //Actual Burndown
public double? PointsClaimed { get; set; } //Points Claimed
}
public List<LineChartData> chartData = new List<LineChartData>
{
new LineChartData { xValue = new DateTime(2020, 12, 09), PredictedBurndown = 27, ActualBurndown = 27, PointsClaimed = 0 },
new LineChartData { xValue = new DateTime(2020, 12, 10), PredictedBurndown = 24.5, ActualBurndown = 24, PointsClaimed = 0 },
new LineChartData { xValue = new DateTime(2020, 12, 11), PredictedBurndown = 21.4, ActualBurndown = 18.5, PointsClaimed = 0 },
new LineChartData { xValue = new DateTime(2020, 12, 12), PredictedBurndown = 18.7, ActualBurndown = 13.5, PointsClaimed = 0 },
new LineChartData { xValue = new DateTime(2020, 12, 13), PredictedBurndown = 17.1, ActualBurndown = 9, PointsClaimed = 0 },
new LineChartData { xValue = new DateTime(2020, 12, 16), PredictedBurndown = 15.1, ActualBurndown = 7, PointsClaimed = 0 },
new LineChartData { xValue = new DateTime(2020, 12, 17), PredictedBurndown = 12, ActualBurndown = 5.5, PointsClaimed = 2 },
new LineChartData { xValue = new DateTime(2020, 12, 18), PredictedBurndown = 8.8},
new LineChartData { xValue = new DateTime(2020, 12, 19), PredictedBurndown = 6.2},
new LineChartData { xValue = new DateTime(2020, 12, 20), PredictedBurndown = 0},
};
}