【问题标题】:how to add multiple charts in behind code in wpf using wpf toolkit如何使用 wpf 工具包在 wpf 中的代码后面添加多个图表
【发布时间】:2018-09-23 15:04:07
【问题描述】:

我是 WPF 新手,我想知道如何使用 WPF 数据可视化工具包从后面的代码中添加图表。

public void LoadChart()
    {
        List<KeyValuePair<string, int>> valueList = new List<KeyValuePair<string, int>>();
        valueList.Add(new KeyValuePair<string, int>("FreeSpace", 60));
        valueList.Add(new KeyValuePair<string, int>("UsedSpace", 20));

        List<KeyValuePair<string, int>> list = new List<KeyValuePair<string, int>>();
        valueList.Add(new KeyValuePair<string, int>("x", 40));
        valueList.Add(new KeyValuePair<string, int>("y", 400));
        PieSeries pie = new PieSeries();


        pie.Title = "Disk Memory";
        pie.ItemsSource = valueList;
        pie.IndependentValuePath = "Key";
        pie.DependentValuePath = "Value";
        chart.Series.Add(pie);

        Chart x = new Chart();

        PieSeries series = new PieSeries();
        series.Title = "Disk Memory";
        series.ItemsSource = list;
        series.IndependentValuePath = "Key";
        series.DependentValuePath = "Value";
        x.Series.Add(series);


    }
}

我正在尝试将两个图表都添加到网格中。怎么添加?

【问题讨论】:

    标签: c# wpf charts wpftoolkit


    【解决方案1】:

    如果您在 XAML 标记中定义了 Grid,则可以给它一个 x:Name

    <Grid x:Name="theGrid" />
    

    然后您可以通过编程将图表添加到GridChildren 集合中:

    theGrid.RowDefinitions.Add(new RowDefinition()); //add a row the Grid
    theGrid.RowDefinitions.Add(new RowDefinition());
    theGrid.Children.Add(chart);
    Grid.SetRow(1, x); //add "x" to the second row
    theGrid.Children.Add(x);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多