1

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

我使用的是 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>

谢谢

4

2 回答 2

2

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.

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:

<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.

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).

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:

xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0"
于 2013-04-30T21:31:15.170 回答
0

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

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

于 2018-11-01T19:37:00.797 回答