c# - 更新并刷新 wpf 图表

标签 c# wpf charts refresh

我正在使用wpf工具包的图表,但无法查看图表插入的数据...这是xaml部分:

<chartingToolkit:Chart  Height="352" HorizontalAlignment="Left" Name="profilo_cale_chart" Title="Profili cale" VerticalAlignment="Bottom" Width="655" FontSize="16" Margin="252,0,0,55" Visibility="Hidden"> 
   <chartingToolkit:AreaSeries DependentValuePath="Value" IndependentValuePath="Key" IsSelectionEnabled="True" ItemsSource="{Binding}" Foreground="#FF242424" Background="LightSteelBlue" />
</chartingToolkit:Chart>

还有CS: 声明

public partial class MainWindow : Window
{ ...  
    List<KeyValuePair<DateTime, double>> valueList = new List<KeyValuePair<DateTime, double>>(); 
...

当用户选择两个日期时间并按下按钮时调用的模块

private void refresh_charts(DateTime dtStart, DateTime dtEnd)
{
    valueList.Clear();
    using (ModelFoosContainer mc1 = new ModelFoosContainer())
    {
        var res_mea = (from mea in mc1.MeasureSet where (mea.datetime>= dtStart && mea.datetime <= dtEnd) orderby mea.datetime descending select mea).Take(1000);
        foreach (Measure mea1 in res_mea){
            valueList.Add(new KeyValuePair<DateTime,double>(mea1.datetime, Convert.ToDouble(mea1.depth)));
        }
    }


    profilo_cale_chart.DataContext = valueList;
    //I've tried with this two but doesn't work..
    //profilo_cale_chart.Refresh();
    //this.UpdateLayout();

}

在此之后,图表具有正确且非空的 DataContext,但不显示值...有人知道我该如何修复它吗?

最佳答案

尝试为图表系列设置名称:

<chartingToolkit:AreaSeries Name="Example" DependentValuePath="Value" IndependentValuePath="Key" IsSelectionEnabled="True" ItemsSource="{Binding}" Foreground="#FF242424" Background="LightSteelBlue" />

然后,为 AreaSeries 设置 DataContext:

Example.DataContext = valueList;

关于c# - 更新并刷新 wpf 图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12725264/

相关文章:

javascript - 有 id 和 name 的 json 字符串?使用 c 锐利

c# - 为什么 BackgroundWorker_RunWorkerCompleted 不更新 GUI?

ios - 你如何通过代码选择/突出图表的一部分? (图表- PieChartView)

c# - 使用 CultureInfo 格式化 C# 图表轴

java - 如何使用 JFreeChart 绘制曲面?

c# - 如果 c# 中的条件,则在 Inline 中获取错误

c# - 从 JSON 中排除域模型对象的属性

c# - 阻止并发集合,例如 ConcurrentBag 或 BlockingCollection

c# - 如何在 XAML 中使用 C# 自定义子类?

c# - 尝试运行第二个实例时激活隐藏的 wpf 应用程序