【问题标题】:Update and refresh wpf chart更新和刷新 wpf 图表
【发布时间】:2012-09-25 08:54:14
【问题描述】:

我正在使用 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 但不显示值...有人知道我该如何解决吗?

【问题讨论】:

    标签: c# wpf charts refresh


    【解决方案1】:

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

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

    然后,为 AreaSeries 设置 DataContext:

    Example.DataContext = valueList;
    

    【讨论】:

    • @Rasa 我没有问这个问题,我回答了它
    • @DaniloVulović 这很尴尬。错误地我在评论中提到了你。顺便说一句,我纠正了我的错误
    • @MicheleCappannari 如果答案对你有用,那么你应该接受答案以供将来参考。
    • @DaniloVulović 打扰一下,这是我第一次在这里写信……所以现在它被接受了吗?
    • @MicheleCappannari 不,不是
    【解决方案2】:

    尝试从

    更改 xaml 中图表的“可见性”
    Visibility="Hidden"
    

    Visibility="Visible"
    

    【讨论】:

    • 我刚刚解决了这个问题!还是谢谢你:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多