[英]Binding LinearAxis Interval WPF Toolkit Chart
我有一个chartingToolKit
在我的XAML
文件,我想设置的间隔LinearAxis
我的动态而不是静态XAML
文件。 这就是我现在的做法:
<chartingToolkit:ColumnSeries.DependentRangeAxis>
<chartingToolkit:LinearAxis FontSize="15" Foreground="Black" Interval="1" Minimum="0" Orientation="Y" ShowGridLines="False" />
</chartingToolkit:ColumnSeries.DependentRangeAxis>
我试图通过绑定来做到这一点:
<chartingToolkit:ColumnSeries.DependentRangeAxis>
<chartingToolkit:LinearAxis FontSize="15" Foreground="Black" Interval="{Binding ChartingInterval}" Minimum="0" Orientation="Y" ShowGridLines="False" />
</chartingToolkit:ColumnSeries.DependentRangeAxis>
.cs 文件中对 ChartingInterval 属性的绑定引用,如下所示:
public int ChartingInterval
{
get
{
//Should contain more logic, obvious.
return 1;
}
}
但这似乎不能正常工作。 我怎样才能做到这一点?
非常感谢!
我认为这仅仅是因为您的 datacontext 没有设置在您拥有属性“ChartingInterval”的对象上。
您应该简单地将其设置如下:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:chartingToolkit="..."
Title="MainWindow" Height="350" Width="525"
DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}">
...
<chartingToolkit:ColumnSeries.DependentRangeAxis>
<chartingToolkit:LinearAxis FontSize="15" Foreground="Black" Interval="{Binding ChartingInterval}" Minimum="0" Orientation="Y" ShowGridLines="False" />
</chartingToolkit:ColumnSeries.DependentRangeAxis>
...
</Window>
您应该实现 INotifyPropertyChanged 以允许属性通知绑定其值已更改,因此绑定将更新目标值。
对不起我的英语不好
这是我在 C# 中为线系列动态重置图表的代码。 只需将LineSeries
替换为ColumnSeries
并消除您不需要的行。 还将DataContext
名称替换为您的名称,XAML windows.resource 中的样式是我的,因此您可以将其删除,等等。 也许这会帮助您开始 C# 代码。
//dynamically recreate the chart series1
private void AddSeries()
{
var series1 = new LineSeries();
series1.SetBinding(LineSeries.ItemsSourceProperty, new Binding());
series1.DataContext = Power;
series1.DependentValueBinding = new Binding("Value");
series1.IndependentValueBinding = new Binding("Key");
series1.Style = (Style)this.Resources["LineSeriesStyle1"];
//set initial values:
LinearAxis independentaxis = new LinearAxis();
independentaxis.Orientation = AxisOrientation.X;
independentaxis.ShowGridLines = true;
independentaxis.Maximum = 60;
independentaxis.Minimum = 0;
independentaxis.Title = "Time";
independentaxis.ShowGridLines = true;
series1.IndependentAxis = independentaxis;
//set initial values:
LinearAxis dependentaxis = new LinearAxis();
dependentaxis.Orientation = AxisOrientation.Y;
dependentaxis.ShowGridLines = true;
dependentaxis.Maximum = 600;
dependentaxis.Minimum = 0;
dependentaxis.Title = "Force(n)";
dependentaxis.ShowGridLines = true;
series1.DependentRangeAxis = dependentaxis;
chart1.Series.Add(series1);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.