Update and refresh wpf chart

匿名 (未验证) 提交于 2019-12-03 10:10:24

问题:

I'm working with chart of wpf toolkit, and I can't view the inserted data of the chart... Here is the xaml part:

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

And the cs: Declaration

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

Module called when a user chose two dateTime and press a button

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();  } 

After this the chart has the right and not empty DataContext but doesn't show the values... anyone knows how can I fix it?

回答1:

Try to set name for chart series:

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

and after that, set DataContext for AreaSeries:

Example.DataContext = valueList; 


回答2:

Try change "Visibility" for Chart in xaml from

Visibility="Hidden" 

to

Visibility="Visible" 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!