2016-09-12 29 views
0

如何处理每10分钟不断扩展的IndependentdependentValuePath? 将包括ScrollViewer处理这种情况?如何处理在独立和dependentValues中保持扩展的折线图

假设,下面是使用图表:

<Charting:LineSeries Title="station1" Margin="0" FontSize="16" FontWeight="SemiBold" IndependentValuePath="Q_interval" DependentValuePath="Q_size" IsSelectionEnabled="True"> 

    <Charting:LineSeries Title="Terminal 1" Margin="10" FontSize="16" Foreground="Blue" FontWeight="SemiBold" Foreground="Purple" BorderBrush="Red" IndependentValuePath="Q_interval" DependentValuePath="Q_size" IsSelectionEnabled="True"> 
    <Charting:LineSeries.DataPointStyle> 
     <Style TargetType="Charting:LineDataPoint"> 
     <Setter Property="Width" Value="20" /> 
     <Setter Property="Height" Value="20" /> 
     <Setter Property="Background" Value="Blue"/> 
     <Setter Property="FontWeight" Value="SemiBold"/> 
     </Style> 
    </Charting:LineSeries.DataPointStyle> 
    </Charting:LineSeries> 
</Charting:Chart> 

回答

0

如何处理独立和dependentValuePath是守在每10分钟扩大。

可以使用DispatherTimer控制independentdependent值每隔10分钟。

是否包含ScrollViewer将处理这种情况?

LineChat在WinRTXamlToolKit中可以自动排列轴,您不需要让ScrollViewer处理它。

下面是关于每2秒扩展independentdependent的完整演示。

XAML代码

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
    <charting:Chart 
     x:Name="LineChart" 
     Title="Line Chart" 
     Margin="70,0" 
     Foreground="Red" 
     FontSize="10"> 
     <charting:LineSeries 
      x:Name="line1" 
      Title="Population in 2005" 
      DependentValueBinding="{Binding Value}" 
      IndependentValueBinding="{Binding Name}" 
      IsSelectionEnabled="True" /> 
    </charting:Chart> 

后面的代码,

public sealed partial class NewChart : Page 
{ 
    private Random _random = new Random(); 
    private EventThrottler _updateThrottler = new EventThrottler(); 
    private readonly DispatcherTimer _timer; 
    private int total = 1; 
    public NewChart() 
    { 
     this.InitializeComponent(); 
     _timer = new DispatcherTimer 
     { 
      Interval = TimeSpan.FromSeconds(2) 
     }; 
     _timer.Tick += AddlineChat; 
     _timer.Start(); 
    } 

    private void AddlineChat(object sender, object e) 
    { 
     total += 1; 
     _updateThrottler.Run(
      async() => 
      { 
       var sw = new Stopwatch(); 
       sw.Start(); 
       this.UpdateCharts(total); 
       sw.Stop(); 
       await Task.Delay(sw.Elapsed); 
      }); 
    } 

    private void RunIfSelected(UIElement element, Action action) 
    { 
     action.Invoke(); 
    } 
    private void UpdateCharts(int n) 
    { 
     var items1 = new List<NameValueItem>(); 
     var items2 = new List<NameValueItem>(); 
     var items3 = new List<NameValueItem>(); 
     for (int i = 0; i < n; i++) 
     { 
      items1.Add(new NameValueItem { Name = "Name" + i, Value = _random.Next(10, 100) }); 
     } 
     this.RunIfSelected(this.LineChart,() => ((LineSeries)this.LineChart.Series[0]).ItemsSource = items1); 
    } 
} 

public class NameValueItem 
{ 
    public string Name { get; set; } 
    public int Value { get; set; } 
} 

共享我的演示到GitHub上,请参阅here

+0

已下载该应用。当我使用vs2015 Community ver打开它时,我遇到了一些运行该应用程序的问题,因为它是空的。我可以看到文件夹中的文件,但VS2015说它不可用。所以,我创建了一个项目来使用你的文件。但是我需要下载哪一个? WinRTXamlToolkit.UWP或任何版本都可以使用?或者为您的应用程序使用WinRTXamlToolkite.Control.DataVisualization.Windows。 – MilkBottle

+0

[WinRT XAML Toolkit for Windows 10](https://www.nuget.org/packages/winrtxamltoolkit)和[WinRTXamlToolkit.Controls.DataVisualization](https://www.nuget.org/packages/winrtxamltoolkit.Controls。 DataVisualization)是必需的。 –

+0

我的项目需要14393 SDK。尝试一下,如果仍然无法运行,请告诉我您正在使用的SDK版本。 –