2

我试图通过 wpf 应用程序中的 c# 代码动态添加图表花冠。但出现运行时错误,例如“调用目标已引发异常”。

Manwindow.xaml.cs

public partial class Window1 : Window
{

    public ObservableCollection<SeriesPoint> SeriesPoint2 { get; set; }
    //  public   ObservableCollection<BarFullStackedSeries2D> barstacked { get; set; }

    public BarFullStackedSeries2D barstacked;
    //   public SeriesPoint SeriesPoints;

    public Window1()
    {
        // InitializeComponent();
        //SeriesPoints=new SeriesPoint();
        SeriesPoint2 = new ObservableCollection<SeriesPoint>();
        SeriesPoint2.Add(new SeriesPoint("ty", 1));
        barstacked = new BarFullStackedSeries2D();
        foreach (SeriesPoint sr in SeriesPoint2)

            barstacked.Points.Add(sr);

        test.Series.Add(barstacked);



    }
}

人窗口.xaml

<Window x:Class="FullStackedBar2DChart.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts" Title="Window1" Height="350" Width="620">
    <Grid>
        <dxc:ChartControl Name="chartControl1">
            <dxc:ChartControl.Diagram>
                <dxc:XYDiagram2D Name="test">
                    <!--<dxc:XYDiagram2D.Series>

                        <dxc:BarFullStackedSeries2D DisplayName="Second Series">
                            <dxc:BarFullStackedSeries2D.Points>
                                <dxc:SeriesPoint Argument="A" Value="4" />
                                <dxc:SeriesPoint Argument="B" Value="3" />
                                <dxc:SeriesPoint Argument="C" Value="2" />
                                <dxc:SeriesPoint Argument="D" Value="1" />
                            </dxc:BarFullStackedSeries2D.Points>

                        </dxc:BarFullStackedSeries2D>
                    </dxc:XYDiagram2D.Series>-->
                </dxc:XYDiagram2D>
            </dxc:ChartControl.Diagram>
            <dxc:ChartControl.Legend>
                <dxc:Legend />
            </dxc:ChartControl.Legend>
        </dxc:ChartControl>
    </Grid>
</Window>
4

0 回答 0