diff --git a/src/Blazor-ApexCharts/ApexChart.razor.cs b/src/Blazor-ApexCharts/ApexChart.razor.cs index be6b8433..98b09d52 100644 --- a/src/Blazor-ApexCharts/ApexChart.razor.cs +++ b/src/Blazor-ApexCharts/ApexChart.razor.cs @@ -711,6 +711,45 @@ public virtual async Task AppendDataAsync(IEnumerable items) await InvokeVoidJsAsync("blazor_apexchart.appendData", Options.Chart.Id, json); } + /// + /// This method allows you to append new data to the series arrays, referencing each series by name + /// + /// The dictinoary with the data array to append the existing series datasets, using the key as the series name. + /// + /// Links: + /// + /// Blazor Example, + /// JavaScript Documentation + /// + public virtual async Task AppendDataBySeriesNameAsync(Dictionary> items) + { + if (IsNoAxisChart) + { + throw new Exception($"{typeof(ApexChart)}.{nameof(AppendDataBySeriesNameAsync)}: Operation not valid for no axis charts."); + } + + var seriesList = new List>(); + + foreach (var apxSeries in Options.Series) + { + if(items.ContainsKey(apxSeries.Name)) + { + var data = apxSeries.ApexSeries.GenerateDataPoints(items[apxSeries.Name]); + var updatedData = apxSeries.Data.ToList(); + updatedData.AddRange(data); + apxSeries.Data = updatedData; + + seriesList.Add(new AppendData + { + Data = data + }); ; + } + } + + var json = Serialize(seriesList); + await InvokeVoidJsAsync("blazor_apexchart.appendData", Options.Chart.Id, json); + } + /// /// Manually zoom into the chart with the start and end X values. ///