我正在使用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>>();
...
当用户选择两个dateTime并按下按钮时调用的模块
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但不显示值...任何人都知道如何解决它?
答案 0 :(得分:1)
尝试为图表系列设置名称:
<chartingToolkit:AreaSeries Name="Example" DependentValuePath="Value" IndependentValuePath="Key" IsSelectionEnabled="True" ItemsSource="{Binding}" Foreground="#FF242424" Background="LightSteelBlue" />
之后,为AreaSeries设置DataContext:
Example.DataContext = valueList;
答案 1 :(得分:1)
尝试从
更改xaml中图表的“可见性”Visibility="Hidden"
到
Visibility="Visible"