【问题标题】:DynamicDataDisplay error AddLineGraph not in ChartplotterDynamicDataDisplay 错误 AddLineGraph 不在 Chartplotter 中
【发布时间】:2016-06-24 13:53:09
【问题描述】:

我一直在使用http://d3future.codeplex.com/提供的D3版本

它在股票图表上运行良好,但在 AddLineGraph 上出现错误。 以下代码来自其他网络帖子。

似乎某些版本的 DynamicDataDisplay.dll (v2/v3/v4) 可以使用该语句工作/编译。

任何帮助将不胜感激。

public partial class MainWindow : Window
{
    public ObservableDataSource<Point> source1 = null;
    public MainWindow()
    {
        InitializeComponent();
        //this.Loaded += MainWindow_Loaded;
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        source1 = new ObservableDataSource<Point>();
        //Set identity mapping of point
        source1.SetXYMapping(p => p);

        plotter3.AddLineGraph(source1, 4, "Data Row");

        //Fits the chart within ViewPort
        plotter3.Viewport.FitToView();

        // Start computation in 2nd thread
        Thread simThread = new Thread(new ThreadStart(Computation));
        simThread.IsBackground = true;
        simThread.Start();
    }
}

【问题讨论】:

  • 错误是 'ChartPlotter' 不包含 AddLineGraph 的定义,并且没有扩展方法 'AddLineGraph' 接受类型为'ChartPlotter'的第一个参数。

标签: c# wpf dynamic-data-display


【解决方案1】:

试试 AddLineChart。不知道为什么改了:

var x = Enumerable.Range(0, 9).Select(i => i * 100.0);
var y = new double[] { 10, 9, 7, 8, 5, 6, 4, 3, 2, 1 };
var source = DataSource.Create(x,y);
var line = plotter.AddLineChart(source)
    .WithStroke(Brushes.Red)
    .WithStrokeThickness(2)
    .WithDescription("x vs y");

【讨论】:

    【解决方案2】:

    这可能对你有帮助, 注意这里PointCollection 中的元素类型,Collectionenumerable 数据点的集合。

    var ds = new EnumerableDataSource<Point>(Collection);
    LineGraph line;
    ds.SetXMapping(x => x.X);
    ds.SetYMapping(y => y.Y);
    line = new LineGraph(ds);
    line.LinePen = new System.Windows.Media.Pen(System.Windows.Media.Brushes.Red, 2);
    //line.Description = new PenDescription("description");
    Graph.Children.Add(line);
    Graph.FitToView();
    

    【讨论】:

      【解决方案3】:

      感谢大家的有用回复。

      经过大量修改(是的,我是初学者),我发现向项目添加 5 个 cs 文件并使用 D3Future 源站点上的DynamicDataDisplay.dll(56kb)available 可以使代码按最初发布的方式运行。 这五个文件是: [1]Plotter2D [2]Plotter2DExtensions [3]Description [4]StandardDescription [5]PenDescription

      我现在不需要图例和描述,所以我注释掉了对它的引用,只是为了让代码使用AddLineGraph 方法编译和运行。

      我使用的是 Windows 10/Visual Studio Community Edition 2015。

      谢谢。

      【讨论】:

        【解决方案4】:

        我同意,为什么要更改此内容并特别注意不要更新所有源代码或文档。

        另一方面,正在采用标准化:

        <Window
        
        ...
        
        xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0"
        
        ...
        
        >
        
        <d3:ChartPlotter Name="plotter" Margin="0,5,0,0">
        <d3:LineGraph Name="lineGraph" Stroke="Red" StrokeThickness="1"/>
        </d3:ChartPlotter>
        
        </Window>
        

        在背后的代码中:

        public MainWindow()
        {
        
        InitializeComponent();
        
        plotter.Viewport.Domain = new Rect(-1, -1.2, 20, 2.4);
        plotter.Children.Add(new HorizontalScrollBar());
        plotter.AxisGrid.DrawHorizontalMinorTicks = false;
        plotter.AxisGrid.DrawVerticalMinorTicks = false;
        
        }
        
        
        
        
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
        
        lineGraph.DataSource = CreateSineDataSource(1.0);
        
        }   
        
        
        
        
        private IPointDataSource CreateSineDataSource(double phase)
        {
        
        const int N = 100;
        
        Point[] pts = new Point[N];
        
        for (int i = 0; i < N; i++)
        {
        double x = i / (N / 10.0) + phase;
        pts[i] = new Point(x, Math.Sin(x - phase));
        }
        
        var ds = new EnumerableDataSource<Point>(pts);
        ds.SetXYMapping(pt => pt);
        
        return ds;
        
        }
        

        文档中的 sn-p 确实显示了这种标准化,但经过整理和最小化以显示构建块线图。在这里找到:http://d3future.codeplex.com/SourceControl/latest#Main/src/DevSamples/LineTestSample/Window1.xaml.cs 版本:0.4

        注意DataSource的使用。

        希望这会有所帮助!

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-12-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多