Articles in this section
Category / Section

How to get the dataUrl for the chart image in Blazor Charts?

3 mins read

This article explains how to get the dataUrl for the chart image in Blazor Charts.

Getting chart image dataUrl using event

Blazor Charts provides an option to obtain the chart image dataUrl using OnExportComplete event. This can be achieved by specifying allowDownload parameter as false in ExportAsync method, so that image cannot be downloaded and we can get the image URL.

In OnExportComplete event, You can obtain the dataUrl from the argument for the chart. The below code example demonstrates how to get dataUrl.

Index.razor

@using Syncfusion.Blazor.Charts
@using Syncfusion.Blazor.Buttons
@inject IJSRuntime JsRuntime
<SfButton @onclick="ExportChart" Content="Export" IsToggle="true"></SfButton>
<SfChart @ref="chartInstance" Title="Olympic Medal Counts - RIO">
  <ChartEvents OnExportComplete="@GetExportedImage"></ChartEvents>
      <ChartArea><ChartAreaBorder Width="0"></ChartAreaBorder></ChartArea>
      <ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category" Interval="1">
          <ChartAxisMajorGridLines Width="0"></ChartAxisMajorGridLines>
      </ChartPrimaryXAxis>
      <ChartPrimaryYAxis>
          <ChartAxisLineStyle Width="0"></ChartAxisLineStyle>
          <ChartAxisLabelStyle Color="transparent"></ChartAxisLabelStyle>
          <ChartAxisMajorGridLines Width="0"></ChartAxisMajorGridLines>
          <ChartAxisMajorTickLines Width="0"></ChartAxisMajorTickLines>
      </ChartPrimaryYAxis>
      <ChartSeriesCollection>
          <ChartSeries DataSource="@ChartPoints" XName="Country" YName="GoldMedal" ColumnSpacing="0.1" Type="ChartSeriesType.Column">
           </ChartSeries>
       </ChartSeriesCollection>
      <ChartTooltipSettings Enable="true"></ChartTooltipSettings>
  </SfChart>
@code{
  SfChart chartInstance { get; set; }
  public class ColumnChartData
  {
      public string Country { get; set; }
      public double GoldMedal { get; set; }
      public double SilverMedal { get; set; }
      public double BronzeMedal { get; set; }
  }
  public List<ColumnChartData> ChartPoints { get; set; } = new List<ColumnChartData>
  {
      new ColumnChartData { Country = "USA", GoldMedal = 46, SilverMedal = 37, BronzeMedal = 38 },
      new ColumnChartData { Country = "GBR", GoldMedal = 27, SilverMedal = 23, BronzeMedal = 17 },
      new ColumnChartData { Country = "CHN", GoldMedal = 26, SilverMedal = 18, BronzeMedal = 26 }
  };
  public async Task ExportChart(Microsoft.AspNetCore.Components.Web.MouseEventArgs args)
  {
      await chartInstance.ExportAsync(Syncfusion.Blazor.Charts.ExportType.JPEG, "Charts", Syncfusion.PdfExport.PdfPageOrientation.Portrait, false);
  }
  void GetExportedImage(ExportEventArgs Args)
  {
      var url= Args.DataUrl;	
      JsRuntime.InvokeVoidAsync("alert", url);
  }
}

The following screenshot illustrates the output of the code snippet.

Output

image.png

Get Chart Image dataUrl

Conclusion

I hope you enjoyed learning how to get the image dataUrl in Blazor Chart Component.

You can refer to our Blazor Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Blazor Chart example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied