Hello , basically I want to refresh the x axe with new values coming.
Chart.xaml:
<UserControl
x:Class="----"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:tk="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<chartingToolkit:Chart Width="350" Height="250" Background="#BDBDBD" Name="AreaChart" Foreground="DarkRed"
LegendTitle="Ranges" Title="UKC" Margin="10" HorizontalAlignment="Left" >
<chartingToolkit:AreaSeries DependentValuePath="Value" Foreground="Yellow" IndependentValuePath="Key" ItemsSource="{Binding}"
IsSelectionEnabled="True">
</chartingToolkit:AreaSeries>
</chartingToolkit:Chart>
</Grid>
<UserControl>
Chart.cs:
public partial class Graph
{
static Timer timer;
List<KeyValuePair<int, int>> listofvalues = new List<KeyValuePair<int, int>>();
public Graph()
{
InitializeComponent();
LoadAreaChartData();
timer = new Timer(2200);
timer.Enabled = true;
timer.Elapsed += new ElapsedEventHandler(RefreshChart);
}
private void LoadAreaChartData()
{
listofvalues.Add( new KeyValuePair<int, int>(1, 90));
listofvalues.Add( new KeyValuePair<int, int>(5, 100));
listofvalues.Add( new KeyValuePair<int, int>(4, 110));
listofvalues.Add( new KeyValuePair<int, int>(8, 95));
listofvalues.Add(new KeyValuePair<int, int>(8, 100));
listofvalues.Add(new KeyValuePair<int, int>(12, 102));
((AreaSeries)AreaChart.Series[0]).ItemsSource = listofvalues;
}
private void RefreshChart(object sender, ElapsedEventArgs e){
this.Dispatcher.Invoke(new Action(delegate()
{
int time = DateTime.Now.Second;
listofvalues.RemoveAt(0);
listofvalues.Add(new KeyValuePair<int, int>(time, time + 30));
((AreaSeries)AreaChart.Series[0]).ItemsSource = listofvalues;
InitializeComponent();
}));
}
}
}
What I am missing?