【问题标题】:WPF DynamicDataDisplay templating axis labels with icon images based on valueWPF DynamicDataDisplay 模板轴标签与基于值的图标图像
【发布时间】:2012-12-19 23:39:15
【问题描述】:

在搜索 WPF 的开放图表库时,我找到了 DynamicDataDisplay 库。

但是我找不到一种方法(可能是由于文档不完善)根据值格式化它们包含图像的轴标签。

为什么我需要这个?

我目前正在编写一个跟踪游戏 (GW2) 市场价格的工具。

这些价​​格显示为黄金、白银和铜,我根据铜值获取价格,我希望垂直轴显示价格。

所以希望有人知道一种方法来模板化 D3 的轴标签。

【问题讨论】:

    标签: c# wpf xaml


    【解决方案1】:

    感谢 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;
        }
    }
    

    【讨论】:

    【解决方案2】:

    Axis 包含一个 LabelProvider 属性。您可以创建自定义标签提供程序,并在重写方法 CreateLabels 中创建您需要的所有控件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-28
      • 1970-01-01
      • 2012-03-11
      • 1970-01-01
      • 2020-04-13
      • 2017-08-12
      • 1970-01-01
      • 2014-06-14
      相关资源
      最近更新 更多