Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to create a datagrid whose column should be bound to the piechart in such a manner that when I change the value of the column the piechart should get updated.

I want the datagrid should have two columns and should populate these fruit collection values.Also most importantly the datagrid should have only a single editable column i.e. SHARE and on changing the value under this column should automatically gets reflected in the piechart.For that the column SHARE must be binded with the piechart.

Please help me with complete code.

Below is my datagrid code.

XML
<DataGrid x:Name="dataGrid2"  Padding="3"  Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right"  ScrollViewer.HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" Width="301" Margin="0,10,10,10" Grid.ColumnSpan="2">
           <DataGrid.Resources>
               <Style TargetType="{x:Type DataGridColumnHeader}">
                   <Setter Property="Background" Value="Blue"/>
               </Style>
           </DataGrid.Resources>
       </DataGrid>



Also the piechart code.

XML
<DVC:Chart  HorizontalAlignment="Center" VerticalAlignment="Bottom" Canvas.Top="80" Canvas.Left="10" Name="mcChart"
           Background="White" Height="204" Width="754" Grid.Row="2" Grid.ColumnSpan="3" Margin="6,0,0,0">
            <DVC:Chart.Series>
                <DVC:PieSeries Title="Experience" 
                    ItemsSource="{StaticResource FruitCollection}"
                    IndependentValueBinding="{Binding  Path=Name}"
                    DependentValueBinding="{Binding Path=Share}">
                </DVC:PieSeries>
            </DVC:Chart.Series>
        </DVC:Chart>



C#
As you can see what I have tried that to create the pie chart and the piechart is taking its values from &#39;Share&#39; property.
The Dependent Value Binding is bonded to Share property and taking the value from fruitcollection.

class FruitCollection : System.Collections.ObjectModel.Collection&lt;Fruit&gt;
{
    public FruitCollection()
    {
        Add(new Fruit { Name =&quot;0-15&quot;, Share =&quot;1000000&quot;});
        Add(new Fruit { Name =&quot;15-30&quot;, Share = &quot;300000&quot; });
        Add(new Fruit { Name =&quot;30-45&quot;, Share = &quot;200000&quot; });
        Add(new Fruit { Name = &quot;45-60&quot;, Share = &quot;90000&quot; });
        
    }
        
}


What I have tried:

I searched in google and could find a piechart code which was bounded to a fruitcollection.I need to modify it as per the requirements mentioned above.
Please help!
Posted
Updated 24-Sep-16 11:37am
v2
Comments
[no name] 24-Sep-16 19:48pm    
You mean that you searched google for the exact same code you needed for your homework assignment and couldn't find it? Well, you might just have to try and be a programmer and write the code yourself.

1 solution

Hi,

You can use various ChartJS's these days for displaying your data in charts.
Try the following : FusionJS, CanvasJs , amCharts and many more.

Hopefully it will help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900