如何在WPF Toolkit折线图中交换轴?我有以下xaml:
<chartingToolkit:Chart Name="lineChart" Title="Line Series Demo" Margin="0,0,0,0">
<chartingToolkit:LineSeries DependentValuePath="Key" IndependentValuePath="Value" ItemsSource="{Binding}" IsSelectionEnabled="True" />
</chartingToolkit:Chart>
从属值始终显示为Y轴。我需要它们作为X轴。这是否可以使用WPF Toolkit图表?如果我不能用WPF Toolkit做到这一点,我可以使用其他免费的WPF图表库吗?我只需要的是折线图,它可以处理X轴上的多个时间序列和Y轴上的字符串。
答案 0 :(得分:0)
在尝试使用原始WPF工具包找到问题的答案失败后,我决定自己编辑Charting工具包源代码。以下是为了使其正常工作所做的更改:
(显示源代码更改,查看原始来源,在编辑前查看原始帖子)
更改LineSeries.cs:115至
if (axis == null)
{
axis = new CategoryAxis();
}
更改LineAreaBaseSeries.cs:243至
double x = ActualIndependentAxis.GetPlotAreaCoordinate(dataPoint.ActualIndependentValue).Value;
double y = this.InternalActualDependentAxis.GetPlotAreaCoordinate(dataPoint.ActualDependentValue).Value;
if (ValueHelper.CanGraph(x) && ValueHelper.CanGraph(y))
{
dataPoint.Visibility = Visibility.Visible;
double coordinateY = Math.Round(y - (dataPoint.ActualHeight / 2));
Canvas.SetTop(dataPoint, coordinateY);
double coordinateX = Math.Round(x - (dataPoint.ActualWidth / 2));
Canvas.SetLeft(dataPoint, coordinateX);
}
else
{
dataPoint.Visibility = Visibility.Collapsed;
}
更改LineAreaBaseSeries.cs:298到
Func<DataPoint, Point> createPoint =
dataPoint =>
new Point(
ActualIndependentAxis.GetPlotAreaCoordinate(dataPoint.ActualIndependentValue).Value,
this.InternalActualDependentAxis.GetPlotAreaCoordinate(dataPoint.ActualDependentValue).Value);
IEnumerable<Point> points = Enumerable.Empty<Point>();
if (ActualIndependentAxis is IRangeAxis)
{
points = DataPointsByIndependentValue.Select(createPoint);
}
else
{
points =
ActiveDataPoints
.Select(createPoint)
.OrderBy(point => point.X);
}
完成这些更改后,您可以使用依赖的字符串源。
干杯!