Data Binding to SfChart yields many rows of NaNs

SF version 19.4.0.38

I am using a MVVM design approach. In the model I have many wells and each well has associated production data. I use SfTreeGrid to show wells and, when the user selects one of the wells, the intent is to have SfChart update the production plot. There is a console area where I dump out text for debugging purposes or feedback to the user.

Note that SfCharts.Series[0].ItemsDataSource is initially empty (assigned but there is not data in the collection). The problem is that when the data in the SfCharts.Series[0].ItemsDataSource is changed (the reference is not changed, the data in the reference is changed), I can debug and examine the ItemsDataSource and it truly reflects the new data. In my usual example, it has 378 rows and all the data is correct (with no NaNs). Furthermore, SfCharts.Series[0].ActualXValues correctly reflect that the count is 378. However, all the values are NaN. The same problematic behavior is also observed with SfCharts.Series[0].YValues.

Note that when the well of interest is changed in the SfTreeGrid, and the data for SfCharts.Series[0].ItemsDataSource changes (not the reference, but the underlying data). that there is no event fired for LiquidChart_PropertyChanged.

Obviously, I am seeing no data on the chart.

On the main page, the relevant c# code is:

public sealed partial class MainPage : Page

{

private static ViewModel viewModel;

public MainPage()

{

this.InitializeComponent();

//Initialize the ViewModel

viewModel = new ViewModel();

//Set the datacontext for the page

//JPW - I don't have a good sense of what this actually is doing

this.DataContext = viewModel;

...

//Initialize WellListHistory treegrid

this.WellListHistory.ItemsSource = viewModel.HistoryWellList;

this.WellListHistory.ParentPropertyName = "EntityID";

this.WellListHistory.ChildPropertyName = "FlowsTo";

this.WellListHistory.SelfRelationRootValue = uint.MaxValue;

this.WellListHistory.AutoExpandMode = AutoExpandMode.RootNodesExpanded;


//Initialize LiquidChart SfChart

this.LiquidChart.Header = "All Wells";

NumericalAxis xaxis = new NumericalAxis();

NumericalAxis yaxis = new NumericalAxis();

xaxis.Header = "Operating Days";

yaxis.Header = "Rate OD (stb/d)";

this.LiquidChart.PrimaryAxis = xaxis;

this.LiquidChart.SecondaryAxis = yaxis;

ScatterSeries series = new ScatterSeries()

{

ItemsSource = viewModel.LiquidChartData,

XBindingPath = "X",

YBindingPath = "Y",

ListenPropertyChange = true,

Label = "All Wells",

ScatterHeight = 4,

ScatterWidth = 4

};

this.LiquidChart.Series.Add(series);

}

private void WellListHistory_SelectionChanged(object sender, Syncfusion.UI.Xaml.Grid.GridSelectionChangedEventArgs e)

{

TreeGridRowInfo w = (TreeGridRowInfo) e.AddedItems.ElementAt(0);

if (w != null)

{

this.LiquidChart.Header = viewModel.GetEntityName(w.RowData);

//Update viewModel. LiquidChartData based on the selected well.

//GetEntityID simply returns an ID for the well at the selected row

viewModel.FillLiquidChart(viewModel.GetEntityID(w.RowData));

//this.LiquidChart.Series.Clear();

//ScatterSeries series = new ScatterSeries()

//{

// ItemsSource = viewModel.LiquidChartData,

// XBindingPath = "X",

// YBindingPath = "Y",

// ListenPropertyChange = true,

// Label = "All Wells",

// ScatterHeight = 4,

// ScatterWidth = 4

//};

//this.LiquidChart.Series.Add(series);

}

AddConsoleText($"EntityID = {viewModel.GetEntityID(w.RowData)} EntityName = {viewModel.GetEntityName(w.RowData)} Rows of Production Data = {viewModel.LiquidChartData.Count()}");

}

private void LiquidChart_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)

{

AddConsoleText($"Property Changed {e.PropertyName}");

}

The viewModel.LiquidChartData simply returns a ObservableCollection object from my Model for a particular well. XY is a double x and double y struct.

Note that under WellListHistory_SelectionChanged I have commented out code where I experimented with clearing and repopulating the chart series. In that case, no data whatsoever was moved to ActualXValues and YValues (the counts were 0).


3 Replies

YP Yuvaraj Palanisamy Syncfusion Team February 21, 2022 04:53 PM UTC

Hi Jerry, 
 
We are validating the reported query with provided code snippet and we will update you with complete details by tomorrow 22nd February, 2022. 
 
Regards, 
Yuvaraj.


YP Yuvaraj Palanisamy Syncfusion Team February 22, 2022 01:33 PM UTC

Hi Jerry,

 
We request you to follow the ticket that you created under your account for further updates. 

Regards,
 
Yuvaraj.


JE Jerry February 22, 2022 09:13 PM UTC

For those that face a similar situation, here is the resolution I posted on the ticket. Thank you Syncfusion for being attentive. 

As I mentioned in the text, XY is a struct that contains double X and double Y. 

  public struct XY

  {

    public double X;

    public double Y;

  }

After a few days of looking at the examples in the documentation, I changed the struct to a class that contains double X and double Y as data members. That did not work either.

    public class XY

    {

        public double X;

        public double Y;

    }


However, when I changed the class to have double parameter specifications for X and Y, then it worked! The documentation was not clear about this requirement.

    public class XY

    {

        public double X { get; set; }

        public double Y { get; set; }

    }

Is this a bug or an intentional design requirement?

We are glad to know that you have resolved the issue. Also, we would like to let you know that, we have to use Properties in the data class instead of using Fields for binding the ItemsSource of the chart series. It is not a bug, it is an intentional requirement for design the ViewModel for chart series. For more details, please refer the below UG link.

https://help.syncfusion.com/uwp/charts/getting-started#initialize-view-model  


Thanks,

Manivannan E


Loader.
Up arrow icon