【问题标题】:How do I update my chart to make it display recently added points如何更新我的图表以使其显示最近添加的点
【发布时间】:2017-04-18 19:47:55
【问题描述】:

我想在我的折线图中添加点,但它在视觉上没有改变。我第一次单击该按钮时,它会添加两个点。其他所有点击什么都不做,为什么不呢?

C#代码:

   List<KeyValuePair<string, int>> valueList = new List<KeyValuePair<string, int>>();
    private void Button_Click_3(object sender, System.Windows.RoutedEventArgs e)
    {

        valueList.Add(new KeyValuePair<string, int>(DateTime.Now.ToString("T"), 130));
        System.Threading.Thread.Sleep(1000);
        valueList.Add(new KeyValuePair<string, int>(DateTime.Now.ToString("T"), 140));

       lineSeries1.ItemsSource = valueList;


    }

XAML:

<chartingToolkit:Chart Canvas.Top="80" Canvas.Left="10" Name="mcChart" Width="400" Height="250" Background="LightSteelBlue">
    <chartingToolkit:Chart.Series>
            <chartingToolkit:LineSeries x:Name="lineSeries1" Title="Test" IndependentValueBinding="{Binding Path=Key}" DependentValueBinding="{Binding Path=Value}">
            </chartingToolkit:LineSeries>
    </chartingToolkit:Chart.Series>
</chartingToolkit:Chart>

这是结果的图片: 如上所述,第二次单击同一个按钮不会执行任何操作。

【问题讨论】:

    标签: wpf charts wpftoolkit


    【解决方案1】:

    使用 ObservableCollection 而不是 List。

    ObservableCollection<KeyValuePair<string, int>> valueList = 
        new ObservableCollection<KeyValuePair<string, int>>();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-07
      • 2023-01-24
      • 2023-02-14
      • 1970-01-01
      相关资源
      最近更新 更多