Unable to dynamically add ChartSeries with a DataSource set to ObservableCollection

I am using Blazor Web Assembly 3.2.1 and SF Blazor 18.2.0.55

I am unable to dynamically add ChartSeries to a Chart component where each ChartSeries.DataSource property is set to a unique ObservableCollection.

I add data to the several ObservableCollections over SignalR connections and call Chart.RefreshLiveData() but the Chart is not updated.


I use the code found in the StreamingChart.razor (was unable to paste code in this thread, so attached it as zip file).


But if I use a declarative approach (which is not dynamic) then it works, as seen in the DeclarativeSeriesCollection in StreamingChart.razor


Seems like the Chart.AddSeries() does not setup any event handlers to monitor the ObservableCollection, whereas the declarative approach does.

Is this a supported scenario, combining dynamic ChartSeries and ObservableCollections?


code (without semi-colons)

@using System.Collections.ObjectModel

@using Syncfusion.Blazor.Charts

// markup removed by editor, see attachment for full code sample

@code {

    SfChart Chart1

    SfChart Chart2


    Dictionary> DynamicSeriesCollection { get set } = new Dictionary>()

    Dictionary> DeclarativeSeriesCollection { get set } = new Dictionary>()

    {

        { "id1", new ObservableCollection() },

        { "id2", new ObservableCollection() },

        { "id3", new ObservableCollection() }

    }


    protected override void OnInitialized()

    {

        // setup signal connection to invoke NewDataStreamed when data arrives

    }


    // Called by SignalR, when new data arrives

    private async Task NewDataStreamed(MyData data)

    {

        DynamicSeriesCollection[data.Id].Add(data)

        await Chart1.RefreshLiveData()


        DeclarativeSeriesCollection[data.Id].Add(data)

        await Chart2.RefreshLiveData()

    }


    public async Task StartStreamAsync(string seriesId)

    {

        // add series to chart

        if (!DynamicSeriesCollection.ContainsKey(seriesId))

        {

            DynamicSeriesCollection.Add(seriesId, new ObservableCollection())


            var seriesCollection = new List()

            seriesCollection.Add(new ChartSeries

            {

                Name = seriesId,

                XName = nameof(MyData.Timestamp),

                YName = nameof(MyData.Value),

                DataSource = DynamicSeriesCollection[seriesId], // ObservableCollection per ChartSeries 

                Type = ChartSeriesType.Line

            })

            await Chart1.AddSeries(seriesCollection) // does not seem to listen for data changes in ObservableCollection

        }


        // call server to start streaming data

        StateHasChanged()

    }


    public class MyData

    {

        public string Id { get }

        public DateTime Timestamp { get set }

        public double Value { get set }

    }

}




Attachment: StreamingChart_c4f0092a.zip

9 Replies 1 reply marked as answer

DG Durga Gopalakrishnan Syncfusion Team August 26, 2020 03:12 PM UTC

Hi Mikanyg, 
 
We are validating your reported scenario. We will update the status within one business day(27th August, 2020). We appreciate your patience until then. 
 
Regards, 
Durga G 



DG Durga Gopalakrishnan Syncfusion Team August 27, 2020 02:59 PM UTC

Hi Mikanyg, 

We have validated your reported scenario and are confirming it as a bug and logged a defect report for this. This fix will be available in our upcoming weekly patch release which is scheduled to be rolled out on 8th September, 2020. We appreciate your patience until then. You can keep track of the bug from the feedback portal below.  
  
  
The provided feedback link is private, and you need to login to view this feedback. 
  
If you have any more specification/precise replication procedure or a scenario to be tested, you can add it as a comment in the portal. 

Regards, 
Durga G 



DG Durga Gopalakrishnan Syncfusion Team September 8, 2020 02:00 PM UTC

Hi Mikanyg, 
 
We are working on reported issue. We will include the fix in our upcoming weekly patch release which is scheduled to be rolled out on 15th September, 2020. We appreciate your patience until then. 
 
Regards, 
Durga G 



DG Durga Gopalakrishnan Syncfusion Team September 15, 2020 04:35 PM UTC

Hi Mikanyg, 
 
Sorry for inconvenience. We will include the fix in our upcoming weekly patch release. We appreciate your patience until then. 
 
Regards, 
Durga G 



DG Durga Gopalakrishnan Syncfusion Team September 25, 2020 06:29 AM UTC

Hi Mikanyg, 

We regret for inconvenience. We are working on reported issue and will include the fix in our upcoming weekly patch release which is scheduled to be rolled out on 7th October, 2020. We appreciate your patience until then. 

Regards, 
Durga G 



DG Durga Gopalakrishnan Syncfusion Team October 28, 2020 07:11 AM UTC

Hi Mikanyg, 
  
We will include fix for reported issue in our upcoming volume 4 main release which is expected to be rolled out at end of December, 2020. We appreciate your patience until then. 
  
Regards, 
Durga G 



RI Richard December 11, 2020 05:51 PM UTC

Hi,

I was having the same problem: I think you need to wrap the ChartSeries itself in an ObservableConnection like this:

ChartSeries series = new ChartSeries()
{
        Name = "chart series name",
        Type = ChartSeriesType.Line,
        DataSource = myObservableCollection,
         XName = "x axis name",
        YName = "y axis name",
        Animation = new ChartSeriesAnimation { Enable = false }
};
ObservableCollection<ChartSeries> observableChartSeries = new ObservableCollection<ChartSeries>();
observableChartSeries.Add(series);
await MySfChart.AddSeries(observableChartSeries);

I have this nearly working - it adds series to the chart and sets the x axis (in my case time and it gets updated so the chart scrolls) and y axis ranges.

The only thing it doesn't do is plot the actual points!

Did you manage to get it working?

Best regards,
Richard


DG Durga Gopalakrishnan Syncfusion Team December 14, 2020 12:14 PM UTC

Hi Richard,

We have ensured your reported scenario with attached code snippet. Please ensure whether the provided data points are within the specified minimum and maximum ranges. We have prepared sample and attached for your reference. 


If provided solution doesn't meet your requirement, please revert us.

Regards,
Durga G



DG Durga Gopalakrishnan Syncfusion Team December 18, 2020 03:50 PM UTC

Hi Mikanyg,

We are glad to announce that our Essential Studio 2020 Volume 4 release v18.4.0.30 is rolled out and is available for download under the following link.




We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance. 

Regards,
Durga G


Marked as answer
Loader.
Up arrow icon