Select to view content in your preferred language

Graphs and Charts

7018
36
03-31-2011 04:10 PM
NathalieNeagle
Regular Contributor
I have a simple police application that allows officers to spatial select and query some points (police calls).  I using esri FeatureDataGrid.  I wanted to create a few simple charts and graphs and send the queried data (that is in the featuredatagrid) into these grids and charts. 

Currently I'm trying to send the selected GraphicLayer
<esri:GraphicsLayer ID="MySelectionGraphicsLayer" />

here's a small snip of my code behind to select the graphiclayer
 GraphicsLayer selectionGraphicslayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer;
            selectionGraphicslayer.ClearGraphics();


I'm wondering if I'm binding it right

Here's my Pie Chart




 <Grid Style="{StaticResource WrapperStyle}">
            <chartingToolkit:Chart Title="AnimationSequence = FirstToLast" Palette="{StaticResource GrowPieDataPointPalette}" Style="{StaticResource ChartStyle}" MouseLeftButtonDown="OnMouseLeftButtonDown" Margin="1,4,-1,-4">
                <chartingToolkit:Chart.Series>
                    <chartingToolkit:PieSeries ItemsSource="{Binding ElementName=Map, Path=Layers[MySelectionGraphicsLayer].Graphics}" DependentValueBinding="{Binding Attributes[DISPDESC]}" AnimationSequence="FirstToLast"/>
                 </chartingToolkit:Chart.Series>
            </chartingToolkit:Chart>
        </Grid>




My table works and here's how I'm binding that:

 <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="15" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <TextBlock x:Name="DataDisplayTitle" Text="Search Results" FontSize="9" Grid.Row="0" FontWeight="Bold" FontFamily="Arial" Foreground="#FFFFFFFF" />



                            <esriWidgets:FeatureDataGrid Grid.Row="1" x:Name="QueryDetailsDataGrid" Height="170" 
                                      Map="{Binding ElementName=Map}" 
                                      GraphicsLayer="{Binding Layers[MySelectionGraphicsLayer], ElementName=Map}" />

                        </Grid>




Does it seem like I'm binding the Pie Graph correctly because now app is not completely firing and its not really working; it is only selecting or creating one graphic.  If I try to select 20 points only one gets selected and the featuredatagrid is not firing and showing up (ResultsDisplay.Visibility = Visibility.Visibility).  Everything was working before so I'm wondering/thinking it is something with my pie chart.



Thanks
Nat
0 Kudos
36 Replies
DominiqueBroux
Esri Frequent Contributor
So the question is : 'How to make the cherry bomb explode? 🙂

Unfortunately I can't figure out where your issue is.

Check that you hooked up the selection changed handler and set IsSelectinEnabled to true:

<chartingToolkit:PieSeries IsSelectionEnabled="True"SelectionChanged="PieSeries_SelectionChanged" 
                                   ItemsSource="{Binding}" 


Then try debugging step by step the 'PieSeries_SelectionChanged' code: 'attributeGroup.Graphics' should contain the graphics corresponding to your typecode.

Good luck.

BTW : to keep the colors from VS, paste the code after creating the
 tags.
0 Kudos
NathalieNeagle
Regular Contributor
Dominique,

Thanks again for all the help! I set a break point at:
 private void PieSeries_SelectionChanged(object sender, SelectionChangedEventArgs e)

right when I clicked on a slice of the pie it jumped to V.S. and I started stepping through the code.

Once it hits the for loop:
foreach (Graphic item in selectionGraphicslayer.Graphics)
                item.Selected = false;
I have to jump through the for loop X times for X amount of points/graphics...seems right.

Then it moves on into the next for loop

 {
                QueryDetailsDataGrid.SelectedItems.Add(graphic);
                graphic.Select();
            }


and then it finally fails at
QueryDetailsDataGrid.SelectedItems.Add(graphic);



Message: Unhandled
Here's the error message and I attached the screen shot: not to sure what to make of it. Any ideas?

Error in Silverlight Application
Code: 4004
Category: ManagedRuntimeError
Message: System.ArgumentException: The item is not contained in the ItemsSource.
Parameter name: dataItem
at System.Windows.Controls.DataGridSelectedItemsCollection.Add(Object dataItem)
at TabbedRibbon.MainPage.PieSeries_SelectionChanged(Object sender, SelectionChangedEventArgs e)
at System.Windows.Controls.DataVisualization.Charting.DataPointSeries.OnSelectedItemPropertyChanged(Object oldValue, Object newValue)
at System.Windows.Controls.DataVisualization.Charting.DataPointSeries.OnSelectedItemPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at System.Windows.Controls.DataVisualization.Charting.DataPointSeries.set_SelectedItem(Object value)
at System.Windows.Controls.DataVisualization.Charting.DataPointSeries.Select(DataPoint dataPoint)
at System.Windows.Controls.DataVisualization.Charting.DataPointSeries.OnDataPointIsSelectedChanged(Object sender, RoutedPropertyChangedEventArgs`1 e)
at System.Windows.Controls.DataVisualization.Charting.DataPoint.OnIsSelectedPropertyChanged(Boolean oldValue, Boolean newValue)
at System.Windows.Controls.DataVisualization.Charting.DataPoint.OnIsSelectedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at System.Windows.Controls.DataVisualization.Charting.DataPoint.set_IsSelected(Boolean value)
at System.Windows.Controls.DataVisualization.Charting.DataPoint.OnMouseLeftButtonDown(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonDown(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)

Line: 54
Char: 13
Code: 0
URI: http://localhost:49827/Web/


no explosion
Nathalie
0 Kudos
DominiqueBroux
Esri Frequent Contributor
When and How is set the ItemsSource of your QueryDetailsDataGrid?

In the initial sample, it was done in QueryTask_ExecuteComplete:
        private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {
            FeatureSet featureSet = args.FeatureSet;
            QueryDetailsDataGrid.ItemsSource = featureSet.Features;



By security, we can check that the graphic exists in the grid before selecting it:
foreach (var graphic in attributeGroup.Graphics)
{
    if (QueryDetailsDataGrid.ItemsSource != null && QueryDetailsDataGrid.ItemsSource.Cast<Graphic>().Contains(graphic))
        QueryDetailsDataGrid.SelectedItems.Add(graphic);
    graphic.Select();
}
That should avoid the crash but the rows will probably not get selected if there is an issue with the initialization of ItemsSource.
0 Kudos
DavidAshton
Frequent Contributor
Great post learning alot
0 Kudos
NathalieNeagle
Regular Contributor
O.K. I think I am close and hopefully I will stop bothering you soon.

When and How is set the ItemsSource of your QueryDetailsDataGrid?

In the initial sample, it was done in QueryTask_ExecuteComplete:
        private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {
            FeatureSet featureSet = args.FeatureSet;
            QueryDetailsDataGrid.ItemsSource = featureSet.Features;




In the original example http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SpatialQueryI don't see the line
QueryDetailsDataGrid.ItemsSource = featureSet.Features;

AND I don't have the QueryDetailsDataGrid.ItemsSource = featureSet.Features;
line in my code.

And if I add it to my code it breaks my spatial selection...unless I add it to the end. Then it works but my table is filled with feature geometry attributes like (Geometry, Symbol, Attributes, MapTip, TimeExtent, Selected, etc. ) instead of the attributes of the feature but it does seem like the chart is working --- kind of -- when I click on a slice of pie it selects the graphic and rows but when I click on another slice it doesn't deselect the original graphic/row...The Selected field is checked boxes and once they are checked they stayed check.


Here's my private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)

I guess I just noticed the example is using a DataGrid and I'm using a FeatureDataGrid so i'm not sure if that makes a difference.

Should I just add that one line of code somewhere? Thanks Again!

        private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {
            FeatureSet featureSet = args.FeatureSet;
           

            if (featureSet == null || featureSet.Features.Count < 1)
            {
                MessageBox.Show("No features retured from query");
                return;
            }

            GraphicsLayer graphicsLayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer;

           

            if (featureSet != null && featureSet.Features.Count > 0)

            // ResultsDisplay.Visibility = Visibility.Visible;
            {
                foreach (Graphic feature in featureSet.Features)
                {

                    switch (featureSet.GeometryType.ToString())
                    {
                        case "Polygon":
                            feature.Symbol = LayoutRoot.Resources["ResultsFillSymbol"] as FillSymbol;
                            break;
                        case "Polyline":
                            feature.Symbol = LayoutRoot.Resources["CustomGrowLineSymbol"] as LineSymbol;
                            break;
                        case "Point":
                            feature.Symbol = LayoutRoot.Resources["ResultsMarkerSymbol"] as SimpleMarkerSymbol;
                            break;
                    }

                    graphicsLayer.Graphics.Insert(0, feature);
                    
                }
                //ResultsDisplay.Visibility = Visibility.Visible;
                ResultsDisplay.IsExpanded = true;

                
            }

            MyDrawSurface.IsEnabled = false;


            




            // PIE CHART -  create an enumeration of AttributeGroup from the graphics in your layer

            DataContext = graphicsLayer.Graphics.GroupBy(graphic => (string)graphic.Attributes["TYPECODE"],
                            (typecode, graphics) => new AttributeGroup
                            {
                                Key = typecode,
                                Count = graphics.Count(),
                                Sum = graphics.Select(g => (int)g.Attributes["DOW"]).Sum(),
                                Graphics = graphics
                            }).ToArray();

            //END PIE CHART



        }
0 Kudos
MuhammadWaqar_ul_islam
Occasional Contributor
Dear NathalieNeagle & Dominique,
I need final Code in ( Xaml and  C#) for pie chart while using Interactive sample of Spatil Query 
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SpatialQuery
& my request to ESRI PERSON to add Reports and Pie chart in Interactive Sample
thanks to both of You
0 Kudos
DominiqueBroux
Esri Frequent Contributor
In the original example http://help.arcgis.com/en/webapi/sil...m#SpatialQueryI don't see the line
QueryDetailsDataGrid.ItemsSource = featureSet.Features;


You are right, it's done by a binding in MyDrawSurface_DrawComplete. I don't remember why I changed that in my version but anyway that should not change anything.


I guess I just noticed the example is using a DataGrid and I'm using a FeatureDataGrid so i'm not sure if that makes a difference.


That's likely the point. The selection of a FeatureDataGrid is automatically synchronized with the graphic selection. So you can simply remove these lines:
   if (QueryDetailsDataGrid.ItemsSource != null && QueryDetailsDataGrid.ItemsSource.Cast<Graphic>().Contains(graphic))
        QueryDetailsDataGrid.SelectedItems.Add(graphic);

That being said, I don't understand, how this code could have compiled if QueryDetailsDataGrid was a FeatureDataGrid:confused:
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I need final Code in ( Xaml and C#) for pie chart while using Interactive sample of Spatil Query


I've attached the modified files to this thread.With these modifications, you get a Pie chart of the population by region.
0 Kudos
NathalieNeagle
Regular Contributor
Dominique,

Thanks!


That's likely the point. The selection of a FeatureDataGrid is automatically synchronized with the graphic selection. So you can simply remove these lines:
Code:

   if (QueryDetailsDataGrid.ItemsSource != null && QueryDetailsDataGrid.ItemsSource.Cast<Graphic>().Contains(graphic))
        QueryDetailsDataGrid.SelectedItems.Add(graphic);

That being said, I don't understand, how this code could have compiled if QueryDetailsDataGrid was a FeatureDataGrid



Based off of your response I took out this code:

  QueryDetailsDataGrid.SelectedItem = null;

            foreach (var graphic in attributeGroup.Graphics)
            {
                QueryDetailsDataGrid.SelectedItems.Add(graphic);
                graphic.Select();
            }

           


And replaced it with this code:
 foreach (var graphic in attributeGroup.Graphics)
            {
                graphic.Select();
            }


Now the graphics/cad police points seem to be interacting with the Pie Chart nicely; I have a cherry on the pie;)

It doesn't seem to be selecting my featuregrid rows only when I hoover over the graphic point or click on the graphic point does the table row get selected.

I guess I'm wondering what this line is doing

item.Selected =true;

I changed it to False and it didn't really seem like it effect anything.

Thanks
Nat.
0 Kudos
SteveVidal
Emerging Contributor
NathalieNeagle
I have a simple police application that allows officers to spatial select and query some points (police calls).


Hi Nathalie,

I apologise in advance for highjacking this thread, but I work on a police application (for Queensland Police in Australia), and I was thrilled when I read that you do too.

If that's ok with you I would like to get in touch and share some technical info. I know that posting a request like this on the esri forum is a bit clumsy but that was the best way I could think of! My email address is: Vidal.SteveA@police.qld.gov.au

Cheers,
Steve
0 Kudos