我正在使用 Infragistics xamDataChart,并绘制未知数量的系列。我正在使用此处发布的解决方案,并且运行良好:XamDataChart with unknown number of series
我的问题是关于如何在 XAML 中编辑生成的轴标题。我希望只生成一组 x 和 y 轴,因为我将构建我的数据,这样就足够了。
我该怎么做?
谢谢!
我正在使用 Infragistics xamDataChart,并绘制未知数量的系列。我正在使用此处发布的解决方案,并且运行良好:XamDataChart with unknown number of series
我的问题是关于如何在 XAML 中编辑生成的轴标题。我希望只生成一组 x 和 y 轴,因为我将构建我的数据,这样就足够了。
我该怎么做?
谢谢!
所以如果我做对了,你想编辑轴的名称吗?也许为时已晚,但这对我有帮助。
您可以在方法中设置轴的任何属性UpdateSeriesProperties
。例如,这就是我的方法的样子:
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;
}
}
}
如您所见,我在这里设置最小/最大值、标签、绑定等。
您还可以设置 Graph 的系列的属性:您可以像这样添加Name
属性:SeriesViewModel
private string name;
public string Name
{
get { return name; }
set { name = value; OnPropertyChagned("Name"); }
}
SeriesBinderInfo
然后您可以在方法中访问此属性CreateSeries
:
series.Title = seriesSource.GetType().GetProperty("Name").GetValue(seriesSource, null);
您可以在其中设置任何属性以series
在图表中反映该属性。