AddSeries doesn't add series

Hi,

I'm trying to programmatically add a series to a chart.

the collection is an Observable collection because i want to add more values in real-time, however I can't get it to work with static test data only.

According to this page:
the chart object is only available from OnAfterRender(), so that's where I'm attempting to add the test series.

I will be adding more chart series later on (in event handlers raised from elsewhere) however they will always happen after this point in time.

Here's the razor page code:
@page "/arbitrage/lastprice"
 
<h2>Last Price Arbitrageh2>
<br />
<div id="ControlRegion">
    <SfChart @ref="LastPriceArbitrageChart">      
        <ChartPrimaryXAxis Title="Time"
                           ValueType="Syncfusion.Blazor.Charts.ValueType.DateTime"
                           IntervalType="IntervalType.Hours"
                           Minimum="DateTime.UtcNow.AddDays(-1)"
                           Maximum="DateTime.UtcNow.AddDays(1)"
                           RangePadding="ChartRangePadding.None">
        ChartPrimaryXAxis>
 
        <ChartPrimaryYAxis Title="Arbitrage %"
                           Minimum="0.5"
                           Maximum="2.0">
        ChartPrimaryYAxis>
 
        <ChartSeriesCollection>
        ChartSeriesCollection>
 
        <ChartTooltipSettings Enable="false">ChartTooltipSettings>
        <ChartCrosshairSettings Enable="false">ChartCrosshairSettings>
        <ChartZoomSettings EnableSelectionZooming="false">ChartZoomSettings>
    SfChart>
div>
 
<style>
    .ulstyle {
        margin0px;
        padding-left20px;
        displayinline-block;
    }
 
    .list {
        floatleft;
        line-height20px;
        margin10px;
        min-width200px;
    }
style>
 
@code{
 
    public ObservableCollection<Tuple<DateTimedecimal>> TestSeries =
    new ObservableCollection<Tuple<DateTimedecimal>>();
 
    public SfChart LastPriceArbitrageChart { getset; }
 
    protected override void OnAfterRender(bool firstRender)
    {
        if (firstRender)
        {
            TestSeries.Add(new Tuple<DateTimedecimal>(DateTime.UtcNow.AddHours(-5), (decimal)1.0));
            TestSeries.Add(new Tuple<DateTimedecimal>(DateTime.UtcNow.AddHours(-4), (decimal)1.2));
            TestSeries.Add(new Tuple<DateTimedecimal>(DateTime.UtcNow.AddHours(-3), (decimal)1.5));
            TestSeries.Add(new Tuple<DateTimedecimal>(DateTime.UtcNow.AddHours(-2), (decimal)1.2));
            TestSeries.Add(new Tuple<DateTimedecimal>(DateTime.UtcNow.AddHours(-1), (decimal)0.6));
            TestSeries.Add(new Tuple<DateTimedecimal>(DateTime.UtcNow.AddHours(0), (decimal)0.9));
            TestSeries.Add(new Tuple<DateTimedecimal>(DateTime.UtcNow.AddHours(1), (decimal)1.0));
            TestSeries.Add(new Tuple<DateTimedecimal>(DateTime.UtcNow.AddHours(2), (decimal)1.7));
            TestSeries.Add(new Tuple<DateTimedecimal>(DateTime.UtcNow.AddHours(3), (decimal)1.5));
            TestSeries.Add(new Tuple<DateTimedecimal>(DateTime.UtcNow.AddHours(4), (decimal)1.2));
            TestSeries.Add(new Tuple<DateTimedecimal>(DateTime.UtcNow.AddHours(5), (decimal)1.3));
 
            // create a fake datapoint so we can programmatically set the correct XName and YName from the Tuple
            var fakeDatapoint = new Tuple<DateTimedecimal>(DateTime.UtcNow, (decimal)1.0);
 
            // create a new chart series and connect it to the new observable collection
            ChartSeries testSeries = new ChartSeries()
            {
                Name = nameof(TestSeries),
                Type = ChartSeriesType.Line,
                DataSource = TestSeries,
                XName = nameof(fakeDatapoint.Item1),
                YName = nameof(fakeDatapoint.Item2),
                Animation = new ChartSeriesAnimation { Enable = false }
            };
 
            LastPriceArbitrageChart.AddSeries(testSeries);
        }
    }
}

Here's the result:

Am I doing something wrong, or is this a bug?

Best regards,
Richard

3 Replies 1 reply marked as answer

SM Srihari Muthukaruppan Syncfusion Team July 3, 2020 03:27 AM UTC

Hi Richard,  
  
We have analyzed your query. We were able to reproduce the issue in your version and we confirm this as a bug and logged a defect report. You can keep track of the bug from the feedback portal below.  
  
  
The fix will be available in our weekly patch release which is scheduled to be rolled out on or before July 24, 2020. 
  
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.  
  
Thanks,  
Srihari. 



SM Srihari Muthukaruppan Syncfusion Team July 24, 2020 12:16 PM UTC

Hi Richard,

Sorry for the inconvenience.

Our patch release is scheduled to be rolled out on July 28, 2020. We appreciate your patience until then.

Regards,
Srihari



SM Srihari Muthukaruppan Syncfusion Team July 29, 2020 03:42 AM UTC

Hi Richard,

While validating the reported scenario. From that, we suggest you to use the below method to overcome the reported scenario. Based on your requirement we have prepared a sample for your reference. Please find the sample, code snippet, and screenshot. 
 
  
  
Code Snippet: 
 @using Syncfusion.Blazor.Charts 
@using System.Collections.ObjectModel;
<SfChart @ref="LastPriceArbitrageChart">
   // add your additional code here
    <ChartSeriesCollection></ChartSeriesCollection>  
  // add your additional code here
</SfChart>

@code{
    public ObservableCollection<Tuple<DateTime, decimal>> TestSeries = new ObservableCollection<Tuple<DateTime, decimal>>();
            public SfChart LastPriceArbitrageChart { get; set; }
            List<string> EventType = new List<string>();
            protected override async Task OnAfterRenderAsync(bool firstRender)
            {
                await Task.Delay(1000);
                if (firstRender)
                {
                  // add your additional code here
                    ObservableCollection<ChartSeries> testSeries = new ObservableCollection<ChartSeries>();
                    testSeries.Add(new ChartSeries
                    {
                        Name = nameof(TestSeries),
                        Type = ChartSeriesType.Line,
                        DataSource = TestSeries,
                        XName = nameof(fakeDatapoint.Item1),
                        YName = nameof(fakeDatapoint.Item2),
                        Animation = new ChartSeriesAnimation { Enable = false }
                    });
                    this.LastPriceArbitrageChart.AddSeries(testSeries);
                }
            }
    }
 
  
Screenshot: 
 
  
Let us know if you have any concerns. 
  
Regards,  
Srihari M 


Marked as answer
Loader.
Up arrow icon