问题
How to handle the Independent
and dependentValuePath
that keep expanding in every 10 minutes?
Will including ScrollViewer
handle this scenario?
Suppose, below is the chart in use:
<Charting:LineSeries Title="station1" Margin="0" FontSize="16" FontWeight="SemiBold" IndependentValuePath="Q_interval" DependentValuePath="Q_size" IsSelectionEnabled="True">
<Charting:LineSeries Title="Terminal 1" Margin="10" FontSize="16" Foreground="Blue" FontWeight="SemiBold" Foreground="Purple" BorderBrush="Red" IndependentValuePath="Q_interval" DependentValuePath="Q_size" IsSelectionEnabled="True">
<Charting:LineSeries.DataPointStyle>
<Style TargetType="Charting:LineDataPoint">
<Setter Property="Width" Value="20" />
<Setter Property="Height" Value="20" />
<Setter Property="Background" Value="Blue"/>
<Setter Property="FontWeight" Value="SemiBold"/>
</Style>
</Charting:LineSeries.DataPointStyle>
</Charting:LineSeries>
</Charting:Chart>
回答1:
how to handle the Independent and dependentValuePath that keep expanding in every 10 minutes.
You can use a DispatherTimer to control the independent
and dependent
value every 10 minutes.
Is including ScrollViewer will handle this scenario?
LineChat
in WinRTXamlToolKit can arrange the axis automatically, you don't need to let a ScrollViewer handle it.
Here is the completed demo about expanding the independent
and dependent
every 2 seconds.
XAML Code
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<charting:Chart
x:Name="LineChart"
Title="Line Chart"
Margin="70,0"
Foreground="Red"
FontSize="10">
<charting:LineSeries
x:Name="line1"
Title="Population in 2005"
DependentValueBinding="{Binding Value}"
IndependentValueBinding="{Binding Name}"
IsSelectionEnabled="True" />
</charting:Chart>
Code behind,
public sealed partial class NewChart : Page
{
private Random _random = new Random();
private EventThrottler _updateThrottler = new EventThrottler();
private readonly DispatcherTimer _timer;
private int total = 1;
public NewChart()
{
this.InitializeComponent();
_timer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(2)
};
_timer.Tick += AddlineChat;
_timer.Start();
}
private void AddlineChat(object sender, object e)
{
total += 1;
_updateThrottler.Run(
async () =>
{
var sw = new Stopwatch();
sw.Start();
this.UpdateCharts(total);
sw.Stop();
await Task.Delay(sw.Elapsed);
});
}
private void RunIfSelected(UIElement element, Action action)
{
action.Invoke();
}
private void UpdateCharts(int n)
{
var items1 = new List<NameValueItem>();
var items2 = new List<NameValueItem>();
var items3 = new List<NameValueItem>();
for (int i = 0; i < n; i++)
{
items1.Add(new NameValueItem { Name = "Name" + i, Value = _random.Next(10, 100) });
}
this.RunIfSelected(this.LineChart, () => ((LineSeries)this.LineChart.Series[0]).ItemsSource = items1);
}
}
public class NameValueItem
{
public string Name { get; set; }
public int Value { get; set; }
}
Shared my demo to GitHub, please see here.
来源:https://stackoverflow.com/questions/39443609/how-to-handle-line-chart-that-keep-expanding-in-both-independent-and-dependentva