GraphicsLayer selectionGraphicslayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer; selectionGraphicslayer.ClearGraphics();
<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>
<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>
dbroux;97173 wrote:
In your control (or your view model), you have to create two dependency properties (or 2 properties) of type IEnumerable<AttributeGroup>.
public class AttributeGroup
{
public static DependencyProperty PieGraphListProperty = DependencyProperty.Register(
"PieGraphList",
typeof(IEnumerable<object>),
typeof(AttributeGroup),
null);
public class PieGraphList
{
public string Key { get; set; }
public int Key2 { get; set; }
public int Sum { get; set; }
public int Count { get; set; }
public DateTime GISDATE { get; set; }
public int GISDOW { get; set; }
public int GISTIME { get; set; }
public int RESPONSETIME { get; set; }
public IEnumerable<Graphic> Graphics { get; set; } // only useful for graphics selection from sliver selection
}
public static DependencyProperty LineGraphListProperty = DependencyProperty.Register(
"LineGraphList",
typeof(IEnumerable<object>),
typeof(AttributeGroup),
null);
public class LineGraphList
{
public string Key { get; set; }
public int Key2 { get; set; }
public int Sum { get; set; }
public int Count { get; set; }
public DateTime GISDATE { get; set; }
public int GISDOW { get; set; }
public int GISTIME { get; set; }
public int RESPONSETIME { get; set; }
public IEnumerable<Graphic> Graphics { get; set; } // only useful for graphics selection from sliver selection
}
}You initialize the first one with the group by TYPECODE, the second one with the group by CALL (instead of initializing the datacontext).
//LINE CHART
DataContext = graphicsLayer.Graphics.GroupBy(graphic => (int)graphic.Attributes["CALL"],
(call, graphics) => new AttributeGroup.LineGraphList
{
Key2 = call,
// GISDATE = DateTime.ParseExact(gisdate.ToString(), "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture),
Count = graphics.Count(),
// Sum = graphics.Select(g => (int)g.Attributes["DOW"]).Sum(),
Graphics = graphics
}).ToArray();
//END LINE CHART
// 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.PieGraphList
{
Key = typecode,
Count = graphics.Count(),
Sum = graphics.Select(g => (int)g.Attributes["DOW"]).Sum(),
Graphics = graphics
}).ToArray();
//END PIE CHARTThen in XAML you bind the ItemsSource of yours charts to these properties (instead of ItemsSource="{Binding}").
Note : you don't need the new Key2 property, you can use the same Key property for both groups of graphics.
private void LineSeries_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var dataPointSeries = sender as DataPointSeries;
var attributeGroup = dataPointSeries.SelectedItem as AttributeGroup.LineGraphList;
if (attributeGroup == null)
return;
GraphicsLayer selectionGraphicslayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer;
foreach (Graphic item in selectionGraphicslayer.Graphics)
item.Selected = false;
foreach (var graphic in attributeGroup.Graphics)
{
graphic.Select();
}
}
public IEnumerable<AttributeGroup> Groups1
{
get { return (IEnumerable<AttributeGroup>)GetValue(Groups1Property); }
set { SetValue(Groups1Property, value); }
}
// Using a DependencyProperty as the backing store for Groups1. This enables animation, styling, binding, etc...
public static readonly DependencyProperty Groups1Property =
DependencyProperty.Register("Groups1", typeof(IEnumerable<AttributeGroup>), typeof(SpatialQuery), null);
public IEnumerable<AttributeGroup> Groups2
{
get { return (IEnumerable<AttributeGroup>)GetValue(Groups2Property); }
set { SetValue(Groups2Property, value); }
}
// Using a DependencyProperty as the backing store for Groups2. This enables animation, styling, binding, etc...
public static readonly DependencyProperty Groups2Property =
DependencyProperty.Register("Groups2", typeof(IEnumerable<AttributeGroup>), typeof(SpatialQuery), null);
// Group by sub region
Groups1 = graphicsLayer.Graphics.GroupBy(graphic => (string)graphic.Attributes["SUB_REGION"],
(key, graphics) => new AttributeGroup
{
Key = key,
Count = graphics.Count(),
Sum = graphics.Select(g => (int)g.Attributes["POP2000"]).Sum(),
Graphics = graphics
}).ToArray();
// Group by first letter of the state name
Groups2 = graphicsLayer.Graphics.GroupBy(graphic => ((string)graphic.Attributes["STATE_NAME"]).FirstOrDefault().ToString(),
(key, graphics) => new AttributeGroup
{
Key = key,
Count = graphics.Count(),
Sum = graphics.Select(g => (int)g.Attributes["POP2007"]).Sum(),
Graphics = graphics
}).OrderBy(group => group.Key).ToArray();
<UserControl x:Name="MyUserControl"
< <StackPanel x:Name="ChartDisplay" Visibility="Collapsed"> <Grid Width="400" Height="300" HorizontalAlignment="Left" VerticalAlignment="Top" > <chartingToolkit:Chart Title="Population 2000 by Region" BorderBrush="Transparent"> <chartingToolkit:PieSeries IsSelectionEnabled="True" SelectionChanged="ChartSeries_SelectionChanged" ItemsSource="{Binding Groups1, ElementName=MyUserControl}" IndependentValuePath="Key" DependentValuePath="Sum" AnimationSequence="FirstToLast"/> </chartingToolkit:Chart> </Grid> <Grid Width="400" Height="300" HorizontalAlignment="Left" VerticalAlignment="Top"> <chartingToolkit:Chart Title="Population 2007" BorderBrush="Transparent"> <chartingToolkit:ColumnSeries Title="State First Letter" IsSelectionEnabled="True" SelectionChanged="ChartSeries_SelectionChanged" ItemsSource="{Binding Groups2, ElementName=MyUserControl}" IndependentValuePath="Key" DependentValuePath="Sum" AnimationSequence="FirstToLast"/> </chartingToolkit:Chart> </Grid> </StackPanel>
Hello,
I would like to use this code but I don't know how to display in another datagrid all the information of MySelectionGraphicsLayer when I select.
Could you help me please ?
Thank you very much,
Fabien (fr)
:)Thank you very very much for both Nathalie and Dominique. It's great topic.
And i was wondered if i can show the chart at the same place of the selected polygon .
Another, if you can explain this object:
DataContext = graphicsLayer.Graphics.GroupBy(graphic => (string)graphic.Attributes["NAME"],
(subregion, graphics) => new AttributeGroup
{
Key = subregion,
Count = graphics.Count(),
Sum = graphics.Select(g => (int)g.Attributes["ELEVATION"]).Sum(),
Graphics = graphics
}).ToArray();
// Group by sub region
Groups1 = graphicsLayer.Graphics.GroupBy(graphic => (string)graphic.Attributes["SUB_REGION"],
(key, graphics) => new AttributeGroup
{
Key = key,
Count = graphics.Count(),
Sum = graphics.Select(g => (int)g.Attributes["POP2000"]).Sum(),
Graphics = graphics
}).ToArray();