Skip to content

Commit da77b9b

Browse files
authored
Merge pull request #404 from technyon/master
Add AppendDataBySeriesNameAsync() method
2 parents bef2c1c + 47c77ff commit da77b9b

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/Blazor-ApexCharts/ApexChart.razor.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,45 @@ public virtual async Task AppendDataAsync(IEnumerable<TItem> items)
711711
await InvokeVoidJsAsync("blazor_apexchart.appendData", Options.Chart.Id, json);
712712
}
713713

714+
/// <summary>
715+
/// This method allows you to append new data to the series arrays, referencing each series by name
716+
/// </summary>
717+
/// <param name="items">The dictinoary with the data array to append the existing series datasets, using the key as the series name.</param>
718+
/// <remarks>
719+
/// Links:
720+
///
721+
/// <see href="https://apexcharts.github.io/Blazor-ApexCharts/methods/append-data">Blazor Example</see>,
722+
/// <see href="https://apexcharts.com/docs/methods/#appendData">JavaScript Documentation</see>
723+
/// </remarks>
724+
public virtual async Task AppendDataBySeriesNameAsync(Dictionary<string, IEnumerable<TItem>> items)
725+
{
726+
if (IsNoAxisChart)
727+
{
728+
throw new Exception($"{typeof(ApexChart<TItem>)}.{nameof(AppendDataBySeriesNameAsync)}: Operation not valid for no axis charts.");
729+
}
730+
731+
var seriesList = new List<AppendData<TItem>>();
732+
733+
foreach (var apxSeries in Options.Series)
734+
{
735+
if(items.ContainsKey(apxSeries.Name))
736+
{
737+
var data = apxSeries.ApexSeries.GenerateDataPoints(items[apxSeries.Name]);
738+
var updatedData = apxSeries.Data.ToList();
739+
updatedData.AddRange(data);
740+
apxSeries.Data = updatedData;
741+
742+
seriesList.Add(new AppendData<TItem>
743+
{
744+
Data = data
745+
}); ;
746+
}
747+
}
748+
749+
var json = Serialize(seriesList);
750+
await InvokeVoidJsAsync("blazor_apexchart.appendData", Options.Chart.Id, json);
751+
}
752+
714753
/// <summary>
715754
/// Manually zoom into the chart with the start and end X values.
716755
/// </summary>

0 commit comments

Comments
 (0)