I'm using blazor server 19.3.0.43 and I need to export a charts in pdf (see attachment) which has two series as below, but regardless the number of bars, only one page is exported in pdf
How can I export all the pages of the complete chart ?
And how can I remove the margins of the pdf to use the whole A4 page space ?
<SfChart @ref="@chartInstance" Title="@Title" Width="650px">
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category" Title="Prodotti" />
<ChartTooltipSettings Enable="true"></ChartTooltipSettings>
<ChartSeriesCollection>
<ChartSeries DataSource="@DatiProdotti" XName="Descrizione" YName="Qta" Name="Quantità" ColumnWidth="1" Type="ChartSeriesType.Bar">
<ChartMarker>
<ChartDataLabel Visible="true" Position="Syncfusion.Blazor.Charts.LabelPosition.Outer">
<ChartDataLabelFont FontWeight="600" Color="#E73571"></ChartDataLabelFont>
</ChartDataLabel>
</ChartMarker>
</ChartSeries>
<ChartSeries DataSource="@DatiProdotti" XName="Descrizione" YName="ValorePesato" Name="Peso" ColumnWidth="1" Type="ChartSeriesType.Bar">
<ChartMarker>
<ChartDataLabel Visible="true" Position="Syncfusion.Blazor.Charts.LabelPosition.Outer">
<ChartDataLabelFont FontWeight="600" Color="#E73571"></ChartDataLabelFont>
</ChartDataLabel>
</ChartMarker>
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
|
<SfChart @ref="@chartInstance" Title="@Title" Width="680px" Height="1000px"></SfChart> |
Thanks for the answer
Using your width and height the export in pdf is now correct as you can see in the attachment, but the chart is resized to stay in only one page so it's almost unreadable
For this reason I tried to change the height value to have the increase the bar's height but in this way the chart is truncated.
Is there any option to split the chart in more than one pdf's page ?
Do you have any sample on how can I create a sfchart totally from code behind ?
If I have to split the data in several charts I need to create them from code behind and then export them in several pdf
I tried to create a sfchart unsuccessfully because I think it's necessary to specify the ChartPrimaryXAxis but I don't find the syntax to add it to the sfchart
I have about 160 items in my datasource so to have a "visible" chart, I have to keep about 15 items every page so this lead to export 160/15 = 11 pdf files
To do that, I tried to use a for loop to load in one only sfchart 15 items at a time and then export it
Something like...
DatiProdottiParziali = DatiProdotti;
int
enloop
= DatiProdotti.Count / 15;
for (int i = 0; i < enloop; i++)
{
DatiProdotti = DatiProdottiParziali.Skip(i * 15).Take(15).ToList();
chartInstance.Export(ExportType.PDF, "Grafico prodotti");
}
but this approach doesn't work because all the pdf pages exported have the first 15 items
It seems to be that the datasource of the chartInstance doesn't change before exporting it ... is there a way to force a refresh of chartInstance ?
chartInstance.Refresh() does nothing
|
public int Length = 5;
protected override void OnInitialized()
{
Data = ChartPoints.Take(Length).ToList();
}
public async void ExportChart(Microsoft.AspNetCore.Components.Web.MouseEventArgs args)
{
var count = ChartPoints.Count / Length;
for (int i = 0; i < count; i++)
{
Data = ChartPoints.Skip(i * Length).Take(Length).ToList();
this.StateHasChanged();
await Task.Delay(1000);
await chartInstance.ExportAsync(ExportType.PDF, "Chart");
}
} |
Thanks, it worls in this way
I hope the option to split the data in several pages but in one only pdf will be available one day
I have in my datasource 148 records to show in a chart
If I simply export them they are exported in one page of one pdf file and they're truncated so the bars are almost unreadable
Using your suggestion, I changed the chart height and I get only 15 records at a time to show them in a more readable way as in my attachment but of course I exported in this way 10 pdf files made up of one page only
I'd like to export instead the 148 records in 10 pages of one only pdf file
If I've well understood, this is not possible up to now.