【问题标题】:WPF Dynamic Data Display Not Showing Line PlotWPF动态数据显示不显示线图
【发布时间】:2016-08-18 16:19:17
【问题描述】:

我编写了一个简单的应用程序,我想绘制它计算的一些数据。我在 Google 上遇到了Dynamic Data Display,它看起来正是我需要的那种东西,只是我无法让情节出现。

我有以下 XAML:

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

<d3:ChartPlotter Name="plotter" Background="Cornsilk" Grid.Row="3" Grid.Column="1">
        <d3:Header>
            <TextBlock HorizontalAlignment="Center" FontSize="20">Very simple chart</TextBlock>
        </d3:Header>
        <d3:HorizontalAxisTitle>This is horizontal axis</d3:HorizontalAxisTitle>
        <d3:VerticalAxisTitle>This is vertical axis</d3:VerticalAxisTitle>
        <d3:Footer>
            <TextBlock HorizontalAlignment="Center" FontSize="10" FontStyle="Italic">
                Footer example
            </TextBlock>
        </d3:Footer>
</d3:ChartPlotter>

这个 C# 链接到按钮的 onClick 事件:

        int[] xarr = { 2, 4, 6 };
        int[] yarr = { 1, 1, 1 };
        EnumerableDataSource<int> x = new EnumerableDataSource<int>(xarr);
        EnumerableDataSource<int> y = new EnumerableDataSource<int>(yarr);
        CompositeDataSource toplot = new CompositeDataSource(x, y);
        plotter.AddLineGraph(toplot);

当我单击按钮时,绘图右上角会出现一个注释,上面写着LineGraph,但看不到任何线条。如有任何帮助,我将不胜感激。

更新:

我在调试控制台中注意到以下错误消息:

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=VerticalContentAlignment; DataItem=null; target element is 'MenuItem' (Name=''); target property is 'VerticalContentAlignment' (type 'VerticalAlignment')

【问题讨论】:

  • 这有点难以帮助,因为它只是一些 3'rd 方库而不是 WPF 框架的一部分,他们有一些示例可供下载,你为什么不复制粘贴 LineGraph 示例并构建最重要的是
  • 我很欣赏这很棘手,我只是希望也许有人对那个库有一些经验,它在 Google 上的排名很高,我确信绘制数据是一项常见的任务。我会采纳您的意见,并尝试从一个示例中回过头来。

标签: c# wpf plot


【解决方案1】:

使用 ObservableDataSource 而不是 CompositeDataSource。只要您添加值,就会引发 DataChanged 事件,并且图表应该会自行更新。

如果您必须向 XAML 添加水平/垂直轴,我不确定。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-02
    • 2012-08-24
    • 1970-01-01
    • 1970-01-01
    • 2015-06-28
    • 1970-01-01
    相关资源
    最近更新 更多