【发布时间】:2012-12-19 23:39:15
【问题描述】:
在搜索 WPF 的开放图表库时,我找到了 DynamicDataDisplay 库。
但是我找不到一种方法(可能是由于文档不完善)根据值格式化它们包含图像的轴标签。
为什么我需要这个?
我目前正在编写一个跟踪游戏 (GW2) 市场价格的工具。
这些价格显示为黄金、白银和铜,我根据铜值获取价格,我希望垂直轴显示价格。
所以希望有人知道一种方法来模板化 D3 的轴标签。
【问题讨论】:
在搜索 WPF 的开放图表库时,我找到了 DynamicDataDisplay 库。
但是我找不到一种方法(可能是由于文档不完善)根据值格式化它们包含图像的轴标签。
为什么我需要这个?
我目前正在编写一个跟踪游戏 (GW2) 市场价格的工具。
这些价格显示为黄金、白银和铜,我根据铜值获取价格,我希望垂直轴显示价格。
所以希望有人知道一种方法来模板化 D3 的轴标签。
【问题讨论】:
感谢 Mikhail Brinchuk 为我指明了正确的方向。 这是我想出的解决方案:
<Window x:Class="ChartTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0"
xmlns:chart="clr-namespace:ChartTest.Chart"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<chart:MoneyLabelProvider x:Key="MoneyLabelProvider"></chart:MoneyLabelProvider>
</Window.Resources>
<Grid>
<d3:ChartPlotter x:Name="Plotter">
<d3:ChartPlotter.VerticalAxis>
<d3:VerticalIntegerAxis x:Name="Axis" LabelProvider="{StaticResource MoneyLabelProvider}">
</d3:VerticalIntegerAxis>
</d3:ChartPlotter.VerticalAxis>
<d3:ChartPlotter.HorizontalAxis>
<d3:HorizontalDateTimeAxis x:Name="DateTimeAxis">
</d3:HorizontalDateTimeAxis>
</d3:ChartPlotter.HorizontalAxis>
</d3:ChartPlotter>
</Grid>
public class MoneyLabelProvider : GenericLabelProvider<int>
{
public override System.Windows.UIElement[] CreateLabels(Microsoft.Research.DynamicDataDisplay.Charts.ITicksInfo<int> ticksInfo)
{
var customElements = new UIElement[ticksInfo.Ticks.Length];
for (int i = 0; i < customElements.Length; i++)
{
var mv = new MoneyView(); // View provides the money style format
var money = new Money(0, 0, ticksInfo.Ticks[i]); // Data class provides the calculation
mv.DataContext = money; // Bind the data to the view
customElements[i] = mv;
}
return customElements;
}
}
【讨论】:
Axis 包含一个 LabelProvider 属性。您可以创建自定义标签提供程序,并在重写方法 CreateLabels 中创建您需要的所有控件。
【讨论】: