Quantcast
Channel: Modern UI (Metro) Charts for Windows 8, WPF, Silverlight
Viewing all articles
Browse latest Browse all 372

Created Unassigned: Binding Chart and DataGrid to same ObservableCollection [16844]

$
0
0
REPOSTING AS ISSUE (ACCIDENTALLY POSTED AS DISCUSSION):
I am trying to bind a DataGrid and a PieChart to the same ObservableCollection, however when I view the chart all it shows is a "0", the legend shows correctly (see image)

![Image](http://i.imgur.com/V2YJbCJ.png)

The DataGrid shows correctly, when I remove the ItemSource binding from the DataGrid the graph will show properly. Any idea what is causing this? Below is the relevant code:

```
<DataGrid ItemsSource="{Binding Path=Errors}" AutoGenerateColumns="True">
```

```
<Chart:PieChart.Series>
<Chart:ChartSeries
SeriesTitle="Populations"
DisplayMember="Category"
ValueMember="Number"
ItemsSource="{Binding Path=Errors}"/>
</Chart:PieChart.Series>
```

```
public class MainViewModel
{

public MainViewModel()
{
Errors = new ObservableCollection<TestClass>();

Errors.Add(new TestClass() { Category = "Globalization", Number = 75 });
Errors.Add(new TestClass() { Category = "Features", Number = 2 });
Errors.Add(new TestClass() { Category = "ContentTypes", Number = 12 });
Errors.Add(new TestClass() { Category = "Correctness", Number = 83 });
}

public ObservableCollection<TestClass> Errors
{
get;
set;
}
}

public class TestClass : INotifyPropertyChanged
{
private string _category = "";
public string Category
{
get
{
return _category;
}
set
{
_category = value;
if (PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs("Category"));
}
}
}

private double _number = 0;
public double Number
{
get
{
return _number;
}
set
{
_number = value;
if (PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs("Number"));
}
}

}

public event PropertyChangedEventHandler PropertyChanged;
}
```

My goal is that I want to be able to edit data in the DataGrid and that these changes will alter the graph.

Viewing all articles
Browse latest Browse all 372

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>