C# 系列轴标题数目未知的XamDataChart
我正在使用Infragistics xamDataChart,并绘制未知数量的系列。我正在使用此处发布的解决方案,并且效果良好: 我的问题是如何在XAML中编辑生成的轴标题。我希望只生成一组x轴和y轴,因为我将构造我的数据,这样这些就足够了 我该怎么办C# 系列轴标题数目未知的XamDataChart,c#,xaml,infragistics,xamdatachart,C#,Xaml,Infragistics,Xamdatachart,我正在使用Infragistics xamDataChart,并绘制未知数量的系列。我正在使用此处发布的解决方案,并且效果良好: 我的问题是如何在XAML中编辑生成的轴标题。我希望只生成一组x轴和y轴,因为我将构造我的数据,这样这些就足够了 我该怎么办 谢谢 如果我没弄错,你想编辑axis的名称吗?也许太晚了,但这对我有帮助 您可以在方法更新riesProperties中设置axis的任何属性。例如,我的方法是这样的: private void UpdateSeriesProperties(Se
谢谢 如果我没弄错,你想编辑axis的名称吗?也许太晚了,但这对我有帮助 您可以在方法
更新riesProperties
中设置axis的任何属性。例如,我的方法是这样的:
private void UpdateSeriesProperties(Series series, SeriesType type, object seriesSource, bool shouldRenewAxes, bool clearOnly)
{
if (series != null)
{
switch (type)
{
case SeriesType.LineSeries:
try
{
HorizontalAnchoredCategorySeries category = series as HorizontalAnchoredCategorySeries;
category.ClearValue(HorizontalAnchoredCategorySeries.ValueMemberPathProperty);
category.ClearValue(HorizontalAnchoredCategorySeries.ItemsSourceProperty);
if (!clearOnly)
{
category.SetBinding(HorizontalAnchoredCategorySeries.ValueMemberPathProperty,
new Binding(YMemberPath) { Source = seriesSource });
category.SetBinding(HorizontalAnchoredCategorySeries.ItemsSourceProperty,
new Binding(ItemsSourcePath) { Source = seriesSource });
}
if (shouldRenewAxes)
{
if (category.XAxis != null)
_owner.Axes.Remove(category.XAxis);
if (category.YAxis != null)
_owner.Axes.Remove(category.YAxis);
if (!clearOnly)
{
CategoryDateTimeXAxis xAxis = new CategoryDateTimeXAxis();
xAxis.LabelSettings = new AxisLabelSettings();
xAxis.SetBinding(CategoryDateTimeXAxis.ItemsSourceProperty,
new Binding(ItemsSourcePath) { Source = seriesSource });
xAxis.SetBinding(CategoryDateTimeXAxis.DateTimeMemberPathProperty,
new Binding(XMemberPath) { Source = seriesSource });
xAxis.Label = "{" + seriesSource.GetType().GetProperty(XMemberPath).GetValue(seriesSource, null) + "}";
xAxis.StrokeThickness = 8;
xAxis.LabelSettings.Extent = 20;
xAxis.LabelSettings.Location = AxisLabelsLocation.OutsideBottom;
xAxis.LabelSettings.VerticalAlignment = System.Windows.VerticalAlignment.Center;
NumericYAxis yAxis = new NumericYAxis();
yAxis.LabelSettings = new AxisLabelSettings();
yAxis.StrokeThickness = 2;
yAxis.LabelSettings.Extent = 40;
yAxis.LabelSettings.Location = AxisLabelsLocation.OutsideLeft;
yAxis.MinimumValue = Convert.ToDouble(seriesSource
.GetType()
.GetProperty("MinMax")
.GetValue(seriesSource, null)
.ToString()
.Split(';')[0]);
yAxis.MaximumValue = Convert.ToDouble(seriesSource
.GetType()
.GetProperty("MinMax")
.GetValue(seriesSource, null)
.ToString()
.Split(';')[1]);
if (_owner.Axes.Count == 0)
{
yAxis.LabelSettings.Visibility = System.Windows.Visibility.Visible;
_owner.Axes.Add(xAxis);
_owner.Axes.Add(yAxis);
category.XAxis = xAxis;
category.YAxis = yAxis;
}
else
{
yAxis.LabelSettings.Visibility = System.Windows.Visibility.Hidden;
_owner.Axes.Add(yAxis);
category.XAxis = (Infragistics.Controls.Charts.CategoryAxisBase)_owner.Axes[0];
category.YAxis = yAxis;
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
break;
default:
break;
}
}
}
如您所见,我正在这里设置最小/最大值、标签、绑定等
您还可以设置图形系列的属性:
您可以在系列视图模型中添加Name
属性,如下所示:
private string name;
public string Name
{
get { return name; }
set { name = value; OnPropertyChagned("Name"); }
}
然后,您可以在方法CreateSeries
中的SeriesBinderInfo
中访问此属性:
series.Title = seriesSource.GetType().GetProperty("Name").GetValue(seriesSource, null);
您可以在其中设置系列
的任何属性,以在图形中反映该属性