Как добавить несколько графиков в коде wpf с помощью инструментария wpf - PullRequest
0 голосов
/ 23 сентября 2018

Я новичок в 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);


    }
}

, где я пытаюсь добавить обе диаграммы в сетку,Как мы можем добавить?

1 Ответ

0 голосов
/ 24 сентября 2018

Если вы определили Grid в своей разметке XAML, вы можете дать ему x:Name:

<Grid x:Name="theGrid" />

Затем вы можете добавить диаграммы к Grid 'ChildrenКоллекция программно:

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