Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit How to embed piechart in datagrid columns?
3 replies. Latest Post by amyo on November 9, 2009.
(0)
vjkumar
Member
0 points
2 Posts
11-07-2009 4:05 PM |
I know how to create a list and bind it to a datagrid to display data. I also know how to create pieseries list for a pie chart and bind it to display the piechart. Now I want to have the piechart in one of the columns of the datagrid. I have created the template column for the piechart. I am able to bind the data from the list to the datagrid but do not know how to access the piechart in the datagrid to populate it. I am not sure whether I should create the pieseries list which is embedded in the grid data list or should access the piecharts separately. Thanks. Some of the code public class Answers
I know how to create a list and bind it to a datagrid to display data.
I also know how to create pieseries list for a pie chart and bind it to display the piechart.
Now I want to have the piechart in one of the columns of the datagrid.
I have created the template column for the piechart.
I am able to bind the data from the list to the datagrid but do not know how to access the piechart in the datagrid to populate it.
I am not sure whether I should create the pieseries list which is embedded in the grid data list or should access the piecharts separately.
Thanks.
Some of the code
public
{
}
Answer_1 = i * 10,
Answer_2 = i * 20,
Answer_3 = i * 30,
Answer_4 = i * 40
});
AnswerGrid1.ItemsSource = source;
};
pieSliceanswers.ItemsSource = _answerpie;
amyo
Contributor
3630 points
495 Posts
11-08-2009 5:36 AM |
You can use DataGrid LoadingRow event like below:
private void AnswerGrid1_LoadingRow(object sender, DataGridRowEventArgs e) { var piechartanswers = AnswerGrid1.Columns [ 6 ].GetCellContent(e.Row) as Chart; if (piechartanswers != null) { PieSeries pieSliceanswers = piechartanswers.Series[0] as PieSeries; pieSliceanswers.ItemsSource = _answerpie; } }
11-08-2009 7:10 PM |
Thanks that works. Only correction I had to make was Column [5] instead of 6.
But now I want to populate the piechart with the values from the data in this grid row.
How do I get the values from the cell of the row being loaded. I tried a few ideas but not successful.
I want to get the values in the columns 1, 2,3 and 4 of the data row. which is being loaded.
11-09-2009 5:35 AM |
Try like below:
private void AnswerGrid1_LoadingRow(object sender, DataGridRowEventArgs e) { var answer= e.Row.DataContext as Answers; }