如何处理在Independent和dependentValues中继续扩展的折线图

时间:2016-09-12 05:01:49

标签: uwp uwp-xaml

如何处理每10分钟不断扩展的IndependentdependentValuePath? 包含ScrollViewer的人会处理这种情况吗?

假设下面是使用中的图表:

<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>

1 个答案:

答案 0 :(得分:0)

  

如何处理每10分钟不断扩展的Independent和dependentValuePath。

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

  

包含ScrollViewer会处理这种情况吗?

WinRTXamlToolKit中的

LineChat可以自动排列轴,您不需要让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