将对象列表绑定到Chart控件

时间:2018-09-22 09:31:37

标签: c# data-binding uwp syncfusion

我正在使用SyncFusion UWP库来构建内部带有图表的接口。我遵循了Getting Started的示例,但无法正常工作。以下代码包含我为适应应用程序需求所做的一些修改。

模型

<script>
$(document).ready(function(){
		$('#Submitall').click(function(){
			  var inputData=$('#ID_Entry-form').serialize();
			 // alert(inputData);
			  //return false;	
		$.ajax({
					method:'post',
					data:$('#ID_PFD-form').serialize(),
			     	url:'http://localhost:8090/TEST/Db_function/php_insert_TempTransac.php',
					//1-->url:'/Db_function/php_insert_TempTransac.php',
					//2-->url:'../Db_function/php_insert_TempTransac.php',
					//3-->url:'./Db_function/php_insert_TempTransac.php',
					
					
					
					success:function(data){
						
						console.log(data);
						//alert(data.trim());
					
					}
			  });			  
			});
		 });
</script>

ViewModel 我添加了notify属性更改

public class Voltage
{
    public DateTime Timestamp;
    public double Value;
}

XAML

public class VoltageViewModel : INotifyPropertyChanged
{
    public List<Voltage> Data { get; set; }

    public VoltageViewModel()
    {
        Data = new List<Voltage>()
        {
            new Voltage() { Timestamp = DateTime.Now.AddMinutes(-1), Value = 5.1 },
            new Voltage() { Timestamp = DateTime.Now.AddMinutes(-2), Value = 4.9 },
            new Voltage() { Timestamp = DateTime.Now.AddMinutes(-3), Value = 4.85 },
            new Voltage() { Timestamp = DateTime.Now.AddMinutes(-4), Value = 5.01 }
        };
    }

    public event PropertyChangedEventHandler PropertyChanged = delegate { };

    public void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        // Raise the PropertyChanged event, passing the name of the property whose value has changed.
        this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}

我认为SyncFusion没问题,我可以确认该图表绘制成功但没有数据。我自己的实现存在问题,但我无法解决问题。

1 个答案:

答案 0 :(得分:1)

只需在模型上而非视图模型上实现INotifyPropertyChanged。 并确保将TimestampValue声明为属性。

模型

public class Voltage : INotifyPropertyChanged
{
    public DateTime Timestamp { get; set; }
    public double Value { get; set; }


    public event PropertyChangedEventHandler PropertyChanged = delegate { };

    public void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        // Raise the PropertyChanged event, passing the name of the property whose value has changed.
        this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}

查看模型

public class VoltageViewModel
{
      public List<Voltage> Data { get; set; }

      public VoltageViewModel()
      {
          Data = new List<Voltage>()
          {
              new Voltage() { Timestamp = DateTime.Now.AddMinutes(-1), Value = 5.1 },
              new Voltage() { Timestamp = DateTime.Now.AddMinutes(-2), Value = 4.9 },
              new Voltage() { Timestamp = DateTime.Now.AddMinutes(-3), Value = 4.85 },
              new Voltage() { Timestamp = DateTime.Now.AddMinutes(-4), Value = 5.01 }
          };
      }

 }