带有图例复选框的动态数据显示图表 (WPF)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16305792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 08:42:47  来源:igfitidea点击:

Dynamic Data Display Chart with legend checkbox (WPF)

wpflegenddynamic-data-display

提问by guilhermecgs

I am trying to recreate the example called "Line Graph legend" under Miscellanous in the following link, http://research.microsoft.com/en-us/um/cambridge/projects/ddd/d3isdk/

我正在尝试在以下链接中的“杂项”下重新创建名为“线图图例”的示例,http://research.microsoft.com/en-us/um/cambridge/projects/ddd/d3isdk/

I am using WPF not silverligth, and was having problems getting the references for the following XAML portion.

我使用的是 WPF 而不是 silverligth,并且在获取以下 XAML 部分的引用时遇到问题。

 <d3:Chart.LegendContent>
    <d3:LegendItemsPanel>
        <d3:LegendItemsPanel.Resources>
            <DataTemplate x:Key="Microsoft.Research.DynamicDataDisplay.LineGraph">
                <StackPanel Orientation="Horizontal">
                    <CheckBox IsChecked="{Binding Path=Visibility, Converter={StaticResource VisibilityToCheckedConverter}, Mode=TwoWay}"/>
                    <Line Width="15" Height="15" X1="0" Y1="0" X2="15" Y2="15" Stroke="{Binding Path=Stroke}" StrokeThickness="2"/>
                    <TextBlock Margin="5,0,0,0" Text="{Binding Path=Description}"/>
                </StackPanel>
            </DataTemplate>
        </d3:LegendItemsPanel.Resources>
    </d3:LegendItemsPanel>
</d3:Chart.LegendContent>

Thanks

谢谢

回答by Ross Llewallyn

I suffered the same confusion when starting with D3. From what I understand, it was first developed for WPF, then used as a springboard for building the same functionality in Silverlight. So the examples you see online have some differences and some additional capabilities that you won't see in the WPF version.

从 D3 开始时,我也遇到了同样的困惑。据我了解,它最初是为 WPF 开发的,然后用作在 Silverlight 中构建相同功能的跳板。因此,您在网上看到的示例存在一些差异和一些您在 WPF 版本中看不到的附加功能。

For one, the class "Chart" does not exist in the WPF version. You'll more likely be using "ChartPlotter" for your graphs. Same with "Legend" and "LineLegendItem" instead of "LegendContent" and "LegendItemsPanel". This might be where you're trying to go:

一方面,WPF 版本中不存在“Chart”类。您更有可能在图表中使用“ChartPlotter”。与“Legend”和“LineLegendItem”相同,而不是“LegendContent”和“LegendItemsPanel”。这可能是您要去的地方:

<d3:ChartPlotter>
    <d3:Legend>
        <d3:LineLegendItem>
            <d3:LineLegendItem.Resources>
                <DataTemplate StackPanel with checkbox>
            </d3:LineLegendItem.Resources>
        </d3:LineLegendItem>
    </d3:Legend>
</d3:ChartPlotter>

I haven't used these classes personally, so I have no first-hand knowledge that this matches the Silverlight example, but I hope it's enough to get you off the ground and experimenting.

我没有亲自使用过这些类,所以我没有第一手资料表明这与 Silverlight 示例相匹配,但我希望这足以让您开始进行实验。

I highly recommend looking at the examples from the download on the official D3 page. I found out recently that you can view the code behind their samples, which is annoyingly not included in the download, online here. (Stable>v0.3.1>src>Samples, find the sample you'd like to examine).

我强烈建议您查看官方 D3 页面上下载的示例。我最近发现您可以在此处在线查看其示例背后的代码,但令人讨厌的是,下载中并未包含这些代码。(Stable>v0.3.1>src>Samples,找到你想检查的样本)。

I don't see any there that have your exact example of having a checkbox in the legend, but your method seems like it should work once you start accessing the right classes.

我没有看到任何有您在图例中具有复选框的确切示例,但是一旦您开始访问正确的类,您的方法似乎应该可以工作。

Also, I assume you're using the following line, and not the Silverlight one, to reference the library:

另外,我假设您使用以下行而不是 Silverlight 来引用库:

xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0"

回答by Johanna Witt

You'll want to use the example here: https://github.com/Microsoft/InteractiveDataDisplay.WPF/tree/master/samples/LineGraphSample

您需要在此处使用示例:https: //github.com/Microsoft/InteractiveDataDisplay.WPF/tree/master/samples/LineGraphSample

Interactive Data Display is the continuation (one of them anyhow) of D3. Some of the C# might be different though.

交互式数据显示是 D3 的延续(无论如何都是其中之一)。但是,某些 C# 可能会有所不同。