This project is read-only.

How to change column series after created once with itemsSource?

Oct 1, 2014 at 3:54 PM
Hey Guys,

I have a data structure that's hierarchical, like a tree. I start by showing the root in column series. And when clicking on one column the user will view a new column series with other data and possible not the same amount of columns. But can't get it right, the first Column displays but when you click on a column the app stops running.
This is part of the code:
                <Charting:ColumnSeries Title="KPI Data"
                                       IsSelectionEnabled="True"
                                       IndependentValuePath="Name"
                                       DependentValuePath="Amount"
                                       SelectionChanged="ColumnSeries_SelectionChanged">
                </Charting:ColumnSeries>
            </Charting:Chart>

Everything is ok until the point where itemssource is set, it won't update the columnseries with the new data.
    void Load(Node<Data> root)
    {
        LoadChartContents(new ObservableCollection<Data>(){root.Value});
    }

    private void LoadChartContents(ObservableCollection<Data> data)
    {
        (ColumnChart.Series[0] as ColumnSeries).ItemsSource = data;
    }

    private ObservableCollection<Data> FillList(Node<Data> node)
    {
        ObservableCollection<Data> children = new ObservableCollection<Data>();
        foreach (var child in node)
        {
            children.Add(child.Value);
        }
        return children;
    }

    private Node<Data> FindNode(Data data, Node<Data> root)
    {
        foreach (var node in root.All)
        {
            if (data.Name == node.Value.Name)
            {
                return node;
            }
        }
        return root;
    }

    private void ColumnSeries_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
            Data selectedBar = e.AddedItems[0] as Data;
            Node<Data> nextNode = FindNode(selectedBar, world);
            ObservableCollection<Data> nextList = FillList(nextNode);
            LoadChartContents(nextList);
    }
Regards